dsi_panel.c 108 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/delay.h>
  6. #include <linux/slab.h>
  7. #include <linux/gpio.h>
  8. #include <linux/of_gpio.h>
  9. #include <linux/pwm.h>
  10. #include <video/mipi_display.h>
  11. #include "dsi_panel.h"
  12. #include "dsi_ctrl_hw.h"
  13. #include "dsi_parser.h"
  14. #include "sde_dsc_helper.h"
  15. #include "sde_vdc_helper.h"
  16. /**
  17. * topology is currently defined by a set of following 3 values:
  18. * 1. num of layer mixers
  19. * 2. num of compression encoders
  20. * 3. num of interfaces
  21. */
  22. #define TOPOLOGY_SET_LEN 3
  23. #define MAX_TOPOLOGY 5
  24. #define DSI_PANEL_DEFAULT_LABEL "Default dsi panel"
  25. #define DEFAULT_PANEL_JITTER_NUMERATOR 2
  26. #define DEFAULT_PANEL_JITTER_DENOMINATOR 1
  27. #define DEFAULT_PANEL_JITTER_ARRAY_SIZE 2
  28. #define MAX_PANEL_JITTER 10
  29. #define DEFAULT_PANEL_PREFILL_LINES 25
  30. #define MIN_PREFILL_LINES 35
  31. static void dsi_dce_prepare_pps_header(char *buf, u32 pps_delay_ms)
  32. {
  33. char *bp;
  34. bp = buf;
  35. /* First 7 bytes are cmd header */
  36. *bp++ = 0x0A;
  37. *bp++ = 1;
  38. *bp++ = 0;
  39. *bp++ = 0;
  40. *bp++ = pps_delay_ms;
  41. *bp++ = 0;
  42. *bp++ = 128;
  43. }
  44. static int dsi_dsc_create_pps_buf_cmd(struct msm_display_dsc_info *dsc,
  45. char *buf, int pps_id, u32 size)
  46. {
  47. dsi_dce_prepare_pps_header(buf, dsc->pps_delay_ms);
  48. buf += DSI_CMD_PPS_HDR_SIZE;
  49. return sde_dsc_create_pps_buf_cmd(dsc, buf, pps_id,
  50. size);
  51. }
  52. static int dsi_vdc_create_pps_buf_cmd(struct msm_display_vdc_info *vdc,
  53. char *buf, int pps_id, u32 size)
  54. {
  55. dsi_dce_prepare_pps_header(buf, vdc->pps_delay_ms);
  56. buf += DSI_CMD_PPS_HDR_SIZE;
  57. return sde_vdc_create_pps_buf_cmd(vdc, buf, pps_id,
  58. size);
  59. }
  60. static int dsi_panel_vreg_get(struct dsi_panel *panel)
  61. {
  62. int rc = 0;
  63. int i;
  64. struct regulator *vreg = NULL;
  65. for (i = 0; i < panel->power_info.count; i++) {
  66. vreg = devm_regulator_get(panel->parent,
  67. panel->power_info.vregs[i].vreg_name);
  68. rc = PTR_RET(vreg);
  69. if (rc) {
  70. DSI_ERR("failed to get %s regulator\n",
  71. panel->power_info.vregs[i].vreg_name);
  72. goto error_put;
  73. }
  74. panel->power_info.vregs[i].vreg = vreg;
  75. }
  76. return rc;
  77. error_put:
  78. for (i = i - 1; i >= 0; i--) {
  79. devm_regulator_put(panel->power_info.vregs[i].vreg);
  80. panel->power_info.vregs[i].vreg = NULL;
  81. }
  82. return rc;
  83. }
  84. static int dsi_panel_vreg_put(struct dsi_panel *panel)
  85. {
  86. int rc = 0;
  87. int i;
  88. for (i = panel->power_info.count - 1; i >= 0; i--)
  89. devm_regulator_put(panel->power_info.vregs[i].vreg);
  90. return rc;
  91. }
  92. static int dsi_panel_gpio_request(struct dsi_panel *panel)
  93. {
  94. int rc = 0;
  95. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  96. if (gpio_is_valid(r_config->reset_gpio)) {
  97. rc = gpio_request(r_config->reset_gpio, "reset_gpio");
  98. if (rc) {
  99. DSI_ERR("request for reset_gpio failed, rc=%d\n", rc);
  100. goto error;
  101. }
  102. }
  103. if (gpio_is_valid(r_config->disp_en_gpio)) {
  104. rc = gpio_request(r_config->disp_en_gpio, "disp_en_gpio");
  105. if (rc) {
  106. DSI_ERR("request for disp_en_gpio failed, rc=%d\n", rc);
  107. goto error_release_reset;
  108. }
  109. }
  110. if (gpio_is_valid(panel->bl_config.en_gpio)) {
  111. rc = gpio_request(panel->bl_config.en_gpio, "bklt_en_gpio");
  112. if (rc) {
  113. DSI_ERR("request for bklt_en_gpio failed, rc=%d\n", rc);
  114. goto error_release_disp_en;
  115. }
  116. }
  117. if (gpio_is_valid(r_config->lcd_mode_sel_gpio)) {
  118. rc = gpio_request(r_config->lcd_mode_sel_gpio, "mode_gpio");
  119. if (rc) {
  120. DSI_ERR("request for mode_gpio failed, rc=%d\n", rc);
  121. goto error_release_mode_sel;
  122. }
  123. }
  124. if (gpio_is_valid(panel->panel_test_gpio)) {
  125. rc = gpio_request(panel->panel_test_gpio, "panel_test_gpio");
  126. if (rc) {
  127. DSI_WARN("request for panel_test_gpio failed, rc=%d\n",
  128. rc);
  129. panel->panel_test_gpio = -1;
  130. rc = 0;
  131. }
  132. }
  133. goto error;
  134. error_release_mode_sel:
  135. if (gpio_is_valid(panel->bl_config.en_gpio))
  136. gpio_free(panel->bl_config.en_gpio);
  137. error_release_disp_en:
  138. if (gpio_is_valid(r_config->disp_en_gpio))
  139. gpio_free(r_config->disp_en_gpio);
  140. error_release_reset:
  141. if (gpio_is_valid(r_config->reset_gpio))
  142. gpio_free(r_config->reset_gpio);
  143. error:
  144. return rc;
  145. }
  146. static int dsi_panel_gpio_release(struct dsi_panel *panel)
  147. {
  148. int rc = 0;
  149. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  150. if (gpio_is_valid(r_config->reset_gpio))
  151. gpio_free(r_config->reset_gpio);
  152. if (gpio_is_valid(r_config->disp_en_gpio))
  153. gpio_free(r_config->disp_en_gpio);
  154. if (gpio_is_valid(panel->bl_config.en_gpio))
  155. gpio_free(panel->bl_config.en_gpio);
  156. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  157. gpio_free(panel->reset_config.lcd_mode_sel_gpio);
  158. if (gpio_is_valid(panel->panel_test_gpio))
  159. gpio_free(panel->panel_test_gpio);
  160. return rc;
  161. }
  162. int dsi_panel_trigger_esd_attack(struct dsi_panel *panel)
  163. {
  164. struct dsi_panel_reset_config *r_config;
  165. if (!panel) {
  166. DSI_ERR("Invalid panel param\n");
  167. return -EINVAL;
  168. }
  169. r_config = &panel->reset_config;
  170. if (!r_config) {
  171. DSI_ERR("Invalid panel reset configuration\n");
  172. return -EINVAL;
  173. }
  174. if (gpio_is_valid(r_config->reset_gpio)) {
  175. gpio_set_value(r_config->reset_gpio, 0);
  176. DSI_INFO("GPIO pulled low to simulate ESD\n");
  177. return 0;
  178. }
  179. DSI_ERR("failed to pull down gpio\n");
  180. return -EINVAL;
  181. }
  182. static int dsi_panel_reset(struct dsi_panel *panel)
  183. {
  184. int rc = 0;
  185. struct dsi_panel_reset_config *r_config = &panel->reset_config;
  186. int i;
  187. if (gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  188. rc = gpio_direction_output(panel->reset_config.disp_en_gpio, 1);
  189. if (rc) {
  190. DSI_ERR("unable to set dir for disp gpio rc=%d\n", rc);
  191. goto exit;
  192. }
  193. }
  194. if (r_config->count) {
  195. rc = gpio_direction_output(r_config->reset_gpio,
  196. r_config->sequence[0].level);
  197. if (rc) {
  198. DSI_ERR("unable to set dir for rst gpio rc=%d\n", rc);
  199. goto exit;
  200. }
  201. }
  202. for (i = 0; i < r_config->count; i++) {
  203. gpio_set_value(r_config->reset_gpio,
  204. r_config->sequence[i].level);
  205. if (r_config->sequence[i].sleep_ms)
  206. usleep_range(r_config->sequence[i].sleep_ms * 1000,
  207. (r_config->sequence[i].sleep_ms * 1000) + 100);
  208. }
  209. if (gpio_is_valid(panel->bl_config.en_gpio)) {
  210. rc = gpio_direction_output(panel->bl_config.en_gpio, 1);
  211. if (rc)
  212. DSI_ERR("unable to set dir for bklt gpio rc=%d\n", rc);
  213. }
  214. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio)) {
  215. bool out = true;
  216. if ((panel->reset_config.mode_sel_state == MODE_SEL_DUAL_PORT)
  217. || (panel->reset_config.mode_sel_state
  218. == MODE_GPIO_LOW))
  219. out = false;
  220. else if ((panel->reset_config.mode_sel_state
  221. == MODE_SEL_SINGLE_PORT) ||
  222. (panel->reset_config.mode_sel_state
  223. == MODE_GPIO_HIGH))
  224. out = true;
  225. rc = gpio_direction_output(
  226. panel->reset_config.lcd_mode_sel_gpio, out);
  227. if (rc)
  228. DSI_ERR("unable to set dir for mode gpio rc=%d\n", rc);
  229. }
  230. if (gpio_is_valid(panel->panel_test_gpio)) {
  231. rc = gpio_direction_input(panel->panel_test_gpio);
  232. if (rc)
  233. DSI_WARN("unable to set dir for panel test gpio rc=%d\n",
  234. rc);
  235. }
  236. exit:
  237. return rc;
  238. }
  239. static int dsi_panel_set_pinctrl_state(struct dsi_panel *panel, bool enable)
  240. {
  241. int rc = 0;
  242. struct pinctrl_state *state;
  243. if (panel->host_config.ext_bridge_mode)
  244. return 0;
  245. if (enable)
  246. state = panel->pinctrl.active;
  247. else
  248. state = panel->pinctrl.suspend;
  249. rc = pinctrl_select_state(panel->pinctrl.pinctrl, state);
  250. if (rc)
  251. DSI_ERR("[%s] failed to set pin state, rc=%d\n",
  252. panel->name, rc);
  253. return rc;
  254. }
  255. static int dsi_panel_power_on(struct dsi_panel *panel)
  256. {
  257. int rc = 0;
  258. rc = dsi_pwr_enable_regulator(&panel->power_info, true);
  259. if (rc) {
  260. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  261. panel->name, rc);
  262. goto exit;
  263. }
  264. rc = dsi_panel_set_pinctrl_state(panel, true);
  265. if (rc) {
  266. DSI_ERR("[%s] failed to set pinctrl, rc=%d\n", panel->name, rc);
  267. goto error_disable_vregs;
  268. }
  269. rc = dsi_panel_reset(panel);
  270. if (rc) {
  271. DSI_ERR("[%s] failed to reset panel, rc=%d\n", panel->name, rc);
  272. goto error_disable_gpio;
  273. }
  274. goto exit;
  275. error_disable_gpio:
  276. if (gpio_is_valid(panel->reset_config.disp_en_gpio))
  277. gpio_set_value(panel->reset_config.disp_en_gpio, 0);
  278. if (gpio_is_valid(panel->bl_config.en_gpio))
  279. gpio_set_value(panel->bl_config.en_gpio, 0);
  280. (void)dsi_panel_set_pinctrl_state(panel, false);
  281. error_disable_vregs:
  282. (void)dsi_pwr_enable_regulator(&panel->power_info, false);
  283. exit:
  284. return rc;
  285. }
  286. static int dsi_panel_power_off(struct dsi_panel *panel)
  287. {
  288. int rc = 0;
  289. if (gpio_is_valid(panel->reset_config.disp_en_gpio))
  290. gpio_set_value(panel->reset_config.disp_en_gpio, 0);
  291. if (gpio_is_valid(panel->reset_config.reset_gpio))
  292. gpio_set_value(panel->reset_config.reset_gpio, 0);
  293. if (gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  294. gpio_set_value(panel->reset_config.lcd_mode_sel_gpio, 0);
  295. if (gpio_is_valid(panel->panel_test_gpio)) {
  296. rc = gpio_direction_input(panel->panel_test_gpio);
  297. if (rc)
  298. DSI_WARN("set dir for panel test gpio failed rc=%d\n",
  299. rc);
  300. }
  301. rc = dsi_panel_set_pinctrl_state(panel, false);
  302. if (rc) {
  303. DSI_ERR("[%s] failed set pinctrl state, rc=%d\n", panel->name,
  304. rc);
  305. }
  306. rc = dsi_pwr_enable_regulator(&panel->power_info, false);
  307. if (rc)
  308. DSI_ERR("[%s] failed to enable vregs, rc=%d\n",
  309. panel->name, rc);
  310. return rc;
  311. }
  312. static int dsi_panel_tx_cmd_set(struct dsi_panel *panel,
  313. enum dsi_cmd_set_type type)
  314. {
  315. int rc = 0, i = 0;
  316. ssize_t len;
  317. struct dsi_cmd_desc *cmds;
  318. u32 count;
  319. enum dsi_cmd_set_state state;
  320. struct dsi_display_mode *mode;
  321. const struct mipi_dsi_host_ops *ops = panel->host->ops;
  322. if (!panel || !panel->cur_mode)
  323. return -EINVAL;
  324. mode = panel->cur_mode;
  325. cmds = mode->priv_info->cmd_sets[type].cmds;
  326. count = mode->priv_info->cmd_sets[type].count;
  327. state = mode->priv_info->cmd_sets[type].state;
  328. if (count == 0) {
  329. DSI_DEBUG("[%s] No commands to be sent for state(%d)\n",
  330. panel->name, type);
  331. goto error;
  332. }
  333. for (i = 0; i < count; i++) {
  334. if (state == DSI_CMD_SET_STATE_LP)
  335. cmds->msg.flags |= MIPI_DSI_MSG_USE_LPM;
  336. if (cmds->last_command)
  337. cmds->msg.flags |= MIPI_DSI_MSG_LASTCOMMAND;
  338. len = ops->transfer(panel->host, &cmds->msg);
  339. if (len < 0) {
  340. rc = len;
  341. DSI_ERR("failed to set cmds(%d), rc=%d\n", type, rc);
  342. goto error;
  343. }
  344. if (cmds->post_wait_ms)
  345. usleep_range(cmds->post_wait_ms*1000,
  346. ((cmds->post_wait_ms*1000)+10));
  347. cmds++;
  348. }
  349. error:
  350. return rc;
  351. }
  352. static int dsi_panel_pinctrl_deinit(struct dsi_panel *panel)
  353. {
  354. int rc = 0;
  355. if (panel->host_config.ext_bridge_mode)
  356. return 0;
  357. devm_pinctrl_put(panel->pinctrl.pinctrl);
  358. return rc;
  359. }
  360. static int dsi_panel_pinctrl_init(struct dsi_panel *panel)
  361. {
  362. int rc = 0;
  363. if (panel->host_config.ext_bridge_mode)
  364. return 0;
  365. /* TODO: pinctrl is defined in dsi dt node */
  366. panel->pinctrl.pinctrl = devm_pinctrl_get(panel->parent);
  367. if (IS_ERR_OR_NULL(panel->pinctrl.pinctrl)) {
  368. rc = PTR_ERR(panel->pinctrl.pinctrl);
  369. DSI_ERR("failed to get pinctrl, rc=%d\n", rc);
  370. goto error;
  371. }
  372. panel->pinctrl.active = pinctrl_lookup_state(panel->pinctrl.pinctrl,
  373. "panel_active");
  374. if (IS_ERR_OR_NULL(panel->pinctrl.active)) {
  375. rc = PTR_ERR(panel->pinctrl.active);
  376. DSI_ERR("failed to get pinctrl active state, rc=%d\n", rc);
  377. goto error;
  378. }
  379. panel->pinctrl.suspend =
  380. pinctrl_lookup_state(panel->pinctrl.pinctrl, "panel_suspend");
  381. if (IS_ERR_OR_NULL(panel->pinctrl.suspend)) {
  382. rc = PTR_ERR(panel->pinctrl.suspend);
  383. DSI_ERR("failed to get pinctrl suspend state, rc=%d\n", rc);
  384. goto error;
  385. }
  386. error:
  387. return rc;
  388. }
  389. static int dsi_panel_wled_register(struct dsi_panel *panel,
  390. struct dsi_backlight_config *bl)
  391. {
  392. struct backlight_device *bd;
  393. bd = backlight_device_get_by_type(BACKLIGHT_RAW);
  394. if (!bd) {
  395. DSI_ERR("[%s] fail raw backlight register\n", panel->name);
  396. return -EPROBE_DEFER;
  397. }
  398. bl->raw_bd = bd;
  399. return 0;
  400. }
  401. static int dsi_panel_update_backlight(struct dsi_panel *panel,
  402. u32 bl_lvl)
  403. {
  404. int rc = 0;
  405. struct mipi_dsi_device *dsi;
  406. if (!panel || (bl_lvl > 0xffff)) {
  407. DSI_ERR("invalid params\n");
  408. return -EINVAL;
  409. }
  410. dsi = &panel->mipi_device;
  411. rc = mipi_dsi_dcs_set_display_brightness(dsi, bl_lvl);
  412. if (rc < 0)
  413. DSI_ERR("failed to update dcs backlight:%d\n", bl_lvl);
  414. return rc;
  415. }
  416. static int dsi_panel_update_pwm_backlight(struct dsi_panel *panel,
  417. u32 bl_lvl)
  418. {
  419. int rc = 0;
  420. u32 duty = 0;
  421. u32 period_ns = 0;
  422. struct dsi_backlight_config *bl;
  423. if (!panel) {
  424. DSI_ERR("Invalid Params\n");
  425. return -EINVAL;
  426. }
  427. bl = &panel->bl_config;
  428. if (!bl->pwm_bl) {
  429. DSI_ERR("pwm device not found\n");
  430. return -EINVAL;
  431. }
  432. period_ns = bl->pwm_period_usecs * NSEC_PER_USEC;
  433. duty = bl_lvl * period_ns;
  434. duty /= bl->bl_max_level;
  435. rc = pwm_config(bl->pwm_bl, duty, period_ns);
  436. if (rc) {
  437. DSI_ERR("[%s] failed to change pwm config, rc=\n", panel->name,
  438. rc);
  439. goto error;
  440. }
  441. if (bl_lvl == 0 && bl->pwm_enabled) {
  442. pwm_disable(bl->pwm_bl);
  443. bl->pwm_enabled = false;
  444. return 0;
  445. }
  446. if (!bl->pwm_enabled) {
  447. rc = pwm_enable(bl->pwm_bl);
  448. if (rc) {
  449. DSI_ERR("[%s] failed to enable pwm, rc=\n", panel->name,
  450. rc);
  451. goto error;
  452. }
  453. bl->pwm_enabled = true;
  454. }
  455. error:
  456. return rc;
  457. }
  458. int dsi_panel_set_backlight(struct dsi_panel *panel, u32 bl_lvl)
  459. {
  460. int rc = 0;
  461. struct dsi_backlight_config *bl = &panel->bl_config;
  462. if (panel->host_config.ext_bridge_mode)
  463. return 0;
  464. DSI_DEBUG("backlight type:%d lvl:%d\n", bl->type, bl_lvl);
  465. switch (bl->type) {
  466. case DSI_BACKLIGHT_WLED:
  467. rc = backlight_device_set_brightness(bl->raw_bd, bl_lvl);
  468. break;
  469. case DSI_BACKLIGHT_DCS:
  470. rc = dsi_panel_update_backlight(panel, bl_lvl);
  471. break;
  472. case DSI_BACKLIGHT_EXTERNAL:
  473. break;
  474. case DSI_BACKLIGHT_PWM:
  475. rc = dsi_panel_update_pwm_backlight(panel, bl_lvl);
  476. break;
  477. default:
  478. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  479. rc = -ENOTSUPP;
  480. }
  481. return rc;
  482. }
  483. static u32 dsi_panel_get_brightness(struct dsi_backlight_config *bl)
  484. {
  485. u32 cur_bl_level;
  486. struct backlight_device *bd = bl->raw_bd;
  487. /* default the brightness level to 50% */
  488. cur_bl_level = bl->bl_max_level >> 1;
  489. switch (bl->type) {
  490. case DSI_BACKLIGHT_WLED:
  491. /* Try to query the backlight level from the backlight device */
  492. if (bd->ops && bd->ops->get_brightness)
  493. cur_bl_level = bd->ops->get_brightness(bd);
  494. break;
  495. case DSI_BACKLIGHT_DCS:
  496. case DSI_BACKLIGHT_EXTERNAL:
  497. case DSI_BACKLIGHT_PWM:
  498. default:
  499. /*
  500. * Ideally, we should read the backlight level from the
  501. * panel. For now, just set it default value.
  502. */
  503. break;
  504. }
  505. DSI_DEBUG("cur_bl_level=%d\n", cur_bl_level);
  506. return cur_bl_level;
  507. }
  508. void dsi_panel_bl_handoff(struct dsi_panel *panel)
  509. {
  510. struct dsi_backlight_config *bl = &panel->bl_config;
  511. bl->bl_level = dsi_panel_get_brightness(bl);
  512. }
  513. static int dsi_panel_pwm_register(struct dsi_panel *panel)
  514. {
  515. int rc = 0;
  516. struct dsi_backlight_config *bl = &panel->bl_config;
  517. bl->pwm_bl = devm_of_pwm_get(panel->parent, panel->panel_of_node, NULL);
  518. if (IS_ERR_OR_NULL(bl->pwm_bl)) {
  519. rc = PTR_ERR(bl->pwm_bl);
  520. DSI_ERR("[%s] failed to request pwm, rc=%d\n", panel->name,
  521. rc);
  522. return rc;
  523. }
  524. return 0;
  525. }
  526. static int dsi_panel_bl_register(struct dsi_panel *panel)
  527. {
  528. int rc = 0;
  529. struct dsi_backlight_config *bl = &panel->bl_config;
  530. if (panel->host_config.ext_bridge_mode)
  531. return 0;
  532. switch (bl->type) {
  533. case DSI_BACKLIGHT_WLED:
  534. rc = dsi_panel_wled_register(panel, bl);
  535. break;
  536. case DSI_BACKLIGHT_DCS:
  537. break;
  538. case DSI_BACKLIGHT_EXTERNAL:
  539. break;
  540. case DSI_BACKLIGHT_PWM:
  541. rc = dsi_panel_pwm_register(panel);
  542. break;
  543. default:
  544. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  545. rc = -ENOTSUPP;
  546. goto error;
  547. }
  548. error:
  549. return rc;
  550. }
  551. static void dsi_panel_pwm_unregister(struct dsi_panel *panel)
  552. {
  553. struct dsi_backlight_config *bl = &panel->bl_config;
  554. devm_pwm_put(panel->parent, bl->pwm_bl);
  555. }
  556. static int dsi_panel_bl_unregister(struct dsi_panel *panel)
  557. {
  558. int rc = 0;
  559. struct dsi_backlight_config *bl = &panel->bl_config;
  560. if (panel->host_config.ext_bridge_mode)
  561. return 0;
  562. switch (bl->type) {
  563. case DSI_BACKLIGHT_WLED:
  564. break;
  565. case DSI_BACKLIGHT_DCS:
  566. break;
  567. case DSI_BACKLIGHT_EXTERNAL:
  568. break;
  569. case DSI_BACKLIGHT_PWM:
  570. dsi_panel_pwm_unregister(panel);
  571. break;
  572. default:
  573. DSI_ERR("Backlight type(%d) not supported\n", bl->type);
  574. rc = -ENOTSUPP;
  575. goto error;
  576. }
  577. error:
  578. return rc;
  579. }
  580. static int dsi_panel_parse_timing(struct dsi_mode_info *mode,
  581. struct dsi_parser_utils *utils)
  582. {
  583. int rc = 0;
  584. u64 tmp64 = 0;
  585. struct dsi_display_mode *display_mode;
  586. struct dsi_display_mode_priv_info *priv_info;
  587. display_mode = container_of(mode, struct dsi_display_mode, timing);
  588. priv_info = display_mode->priv_info;
  589. rc = utils->read_u64(utils->data,
  590. "qcom,mdss-dsi-panel-clockrate", &tmp64);
  591. if (rc == -EOVERFLOW) {
  592. tmp64 = 0;
  593. rc = utils->read_u32(utils->data,
  594. "qcom,mdss-dsi-panel-clockrate", (u32 *)&tmp64);
  595. }
  596. mode->clk_rate_hz = !rc ? tmp64 : 0;
  597. display_mode->priv_info->clk_rate_hz = mode->clk_rate_hz;
  598. mode->pclk_scale.numer = 1;
  599. mode->pclk_scale.denom = 1;
  600. display_mode->priv_info->pclk_scale = mode->pclk_scale;
  601. rc = utils->read_u32(utils->data, "qcom,mdss-mdp-transfer-time-us",
  602. &mode->mdp_transfer_time_us);
  603. if (!rc)
  604. display_mode->priv_info->mdp_transfer_time_us =
  605. mode->mdp_transfer_time_us;
  606. else
  607. display_mode->priv_info->mdp_transfer_time_us = 0;
  608. rc = utils->read_u32(utils->data,
  609. "qcom,mdss-dsi-panel-framerate",
  610. &mode->refresh_rate);
  611. if (rc) {
  612. DSI_ERR("failed to read qcom,mdss-dsi-panel-framerate, rc=%d\n",
  613. rc);
  614. goto error;
  615. }
  616. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-width",
  617. &mode->h_active);
  618. if (rc) {
  619. DSI_ERR("failed to read qcom,mdss-dsi-panel-width, rc=%d\n",
  620. rc);
  621. goto error;
  622. }
  623. rc = utils->read_u32(utils->data,
  624. "qcom,mdss-dsi-h-front-porch",
  625. &mode->h_front_porch);
  626. if (rc) {
  627. DSI_ERR("failed to read qcom,mdss-dsi-h-front-porch, rc=%d\n",
  628. rc);
  629. goto error;
  630. }
  631. rc = utils->read_u32(utils->data,
  632. "qcom,mdss-dsi-h-back-porch",
  633. &mode->h_back_porch);
  634. if (rc) {
  635. DSI_ERR("failed to read qcom,mdss-dsi-h-back-porch, rc=%d\n",
  636. rc);
  637. goto error;
  638. }
  639. rc = utils->read_u32(utils->data,
  640. "qcom,mdss-dsi-h-pulse-width",
  641. &mode->h_sync_width);
  642. if (rc) {
  643. DSI_ERR("failed to read qcom,mdss-dsi-h-pulse-width, rc=%d\n",
  644. rc);
  645. goto error;
  646. }
  647. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-h-sync-skew",
  648. &mode->h_skew);
  649. if (rc)
  650. DSI_ERR("qcom,mdss-dsi-h-sync-skew is not defined, rc=%d\n",
  651. rc);
  652. DSI_DEBUG("panel horz active:%d front_portch:%d back_porch:%d sync_skew:%d\n",
  653. mode->h_active, mode->h_front_porch, mode->h_back_porch,
  654. mode->h_sync_width);
  655. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-height",
  656. &mode->v_active);
  657. if (rc) {
  658. DSI_ERR("failed to read qcom,mdss-dsi-panel-height, rc=%d\n",
  659. rc);
  660. goto error;
  661. }
  662. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-back-porch",
  663. &mode->v_back_porch);
  664. if (rc) {
  665. DSI_ERR("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n",
  666. rc);
  667. goto error;
  668. }
  669. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-front-porch",
  670. &mode->v_front_porch);
  671. if (rc) {
  672. DSI_ERR("failed to read qcom,mdss-dsi-v-back-porch, rc=%d\n",
  673. rc);
  674. goto error;
  675. }
  676. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-v-pulse-width",
  677. &mode->v_sync_width);
  678. if (rc) {
  679. DSI_ERR("failed to read qcom,mdss-dsi-v-pulse-width, rc=%d\n",
  680. rc);
  681. goto error;
  682. }
  683. DSI_DEBUG("panel vert active:%d front_portch:%d back_porch:%d pulse_width:%d\n",
  684. mode->v_active, mode->v_front_porch, mode->v_back_porch,
  685. mode->v_sync_width);
  686. error:
  687. return rc;
  688. }
  689. static int dsi_panel_parse_pixel_format(struct dsi_host_common_cfg *host,
  690. struct dsi_parser_utils *utils,
  691. const char *name)
  692. {
  693. int rc = 0;
  694. u32 bpp = 0;
  695. enum dsi_pixel_format fmt;
  696. const char *packing;
  697. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bpp", &bpp);
  698. if (rc) {
  699. DSI_ERR("[%s] failed to read qcom,mdss-dsi-bpp, rc=%d\n",
  700. name, rc);
  701. return rc;
  702. }
  703. host->bpp = bpp;
  704. switch (bpp) {
  705. case 3:
  706. fmt = DSI_PIXEL_FORMAT_RGB111;
  707. break;
  708. case 8:
  709. fmt = DSI_PIXEL_FORMAT_RGB332;
  710. break;
  711. case 12:
  712. fmt = DSI_PIXEL_FORMAT_RGB444;
  713. break;
  714. case 16:
  715. fmt = DSI_PIXEL_FORMAT_RGB565;
  716. break;
  717. case 18:
  718. fmt = DSI_PIXEL_FORMAT_RGB666;
  719. break;
  720. case 24:
  721. default:
  722. fmt = DSI_PIXEL_FORMAT_RGB888;
  723. break;
  724. }
  725. if (fmt == DSI_PIXEL_FORMAT_RGB666) {
  726. packing = utils->get_property(utils->data,
  727. "qcom,mdss-dsi-pixel-packing",
  728. NULL);
  729. if (packing && !strcmp(packing, "loose"))
  730. fmt = DSI_PIXEL_FORMAT_RGB666_LOOSE;
  731. }
  732. host->dst_format = fmt;
  733. return rc;
  734. }
  735. static int dsi_panel_parse_lane_states(struct dsi_host_common_cfg *host,
  736. struct dsi_parser_utils *utils,
  737. const char *name)
  738. {
  739. int rc = 0;
  740. bool lane_enabled;
  741. u32 num_of_lanes = 0;
  742. lane_enabled = utils->read_bool(utils->data,
  743. "qcom,mdss-dsi-lane-0-state");
  744. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_0 : 0);
  745. lane_enabled = utils->read_bool(utils->data,
  746. "qcom,mdss-dsi-lane-1-state");
  747. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_1 : 0);
  748. lane_enabled = utils->read_bool(utils->data,
  749. "qcom,mdss-dsi-lane-2-state");
  750. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_2 : 0);
  751. lane_enabled = utils->read_bool(utils->data,
  752. "qcom,mdss-dsi-lane-3-state");
  753. host->data_lanes |= (lane_enabled ? DSI_DATA_LANE_3 : 0);
  754. if (host->data_lanes & DSI_DATA_LANE_0)
  755. num_of_lanes++;
  756. if (host->data_lanes & DSI_DATA_LANE_1)
  757. num_of_lanes++;
  758. if (host->data_lanes & DSI_DATA_LANE_2)
  759. num_of_lanes++;
  760. if (host->data_lanes & DSI_DATA_LANE_3)
  761. num_of_lanes++;
  762. host->num_data_lanes = num_of_lanes;
  763. if (host->data_lanes == 0) {
  764. DSI_ERR("[%s] No data lanes are enabled, rc=%d\n", name, rc);
  765. rc = -EINVAL;
  766. }
  767. return rc;
  768. }
  769. static int dsi_panel_parse_color_swap(struct dsi_host_common_cfg *host,
  770. struct dsi_parser_utils *utils,
  771. const char *name)
  772. {
  773. int rc = 0;
  774. const char *swap_mode;
  775. swap_mode = utils->get_property(utils->data,
  776. "qcom,mdss-dsi-color-order", NULL);
  777. if (swap_mode) {
  778. if (!strcmp(swap_mode, "rgb_swap_rgb")) {
  779. host->swap_mode = DSI_COLOR_SWAP_RGB;
  780. } else if (!strcmp(swap_mode, "rgb_swap_rbg")) {
  781. host->swap_mode = DSI_COLOR_SWAP_RBG;
  782. } else if (!strcmp(swap_mode, "rgb_swap_brg")) {
  783. host->swap_mode = DSI_COLOR_SWAP_BRG;
  784. } else if (!strcmp(swap_mode, "rgb_swap_grb")) {
  785. host->swap_mode = DSI_COLOR_SWAP_GRB;
  786. } else if (!strcmp(swap_mode, "rgb_swap_gbr")) {
  787. host->swap_mode = DSI_COLOR_SWAP_GBR;
  788. } else {
  789. DSI_ERR("[%s] Unrecognized color order-%s\n",
  790. name, swap_mode);
  791. rc = -EINVAL;
  792. }
  793. } else {
  794. DSI_DEBUG("[%s] Falling back to default color order\n", name);
  795. host->swap_mode = DSI_COLOR_SWAP_RGB;
  796. }
  797. /* bit swap on color channel is not defined in dt */
  798. host->bit_swap_red = false;
  799. host->bit_swap_green = false;
  800. host->bit_swap_blue = false;
  801. return rc;
  802. }
  803. static int dsi_panel_parse_triggers(struct dsi_host_common_cfg *host,
  804. struct dsi_parser_utils *utils,
  805. const char *name)
  806. {
  807. const char *trig;
  808. int rc = 0;
  809. trig = utils->get_property(utils->data,
  810. "qcom,mdss-dsi-mdp-trigger", NULL);
  811. if (trig) {
  812. if (!strcmp(trig, "none")) {
  813. host->mdp_cmd_trigger = DSI_TRIGGER_NONE;
  814. } else if (!strcmp(trig, "trigger_te")) {
  815. host->mdp_cmd_trigger = DSI_TRIGGER_TE;
  816. } else if (!strcmp(trig, "trigger_sw")) {
  817. host->mdp_cmd_trigger = DSI_TRIGGER_SW;
  818. } else if (!strcmp(trig, "trigger_sw_te")) {
  819. host->mdp_cmd_trigger = DSI_TRIGGER_SW_TE;
  820. } else {
  821. DSI_ERR("[%s] Unrecognized mdp trigger type (%s)\n",
  822. name, trig);
  823. rc = -EINVAL;
  824. }
  825. } else {
  826. DSI_DEBUG("[%s] Falling back to default MDP trigger\n",
  827. name);
  828. host->mdp_cmd_trigger = DSI_TRIGGER_SW;
  829. }
  830. trig = utils->get_property(utils->data,
  831. "qcom,mdss-dsi-dma-trigger", NULL);
  832. if (trig) {
  833. if (!strcmp(trig, "none")) {
  834. host->dma_cmd_trigger = DSI_TRIGGER_NONE;
  835. } else if (!strcmp(trig, "trigger_te")) {
  836. host->dma_cmd_trigger = DSI_TRIGGER_TE;
  837. } else if (!strcmp(trig, "trigger_sw")) {
  838. host->dma_cmd_trigger = DSI_TRIGGER_SW;
  839. } else if (!strcmp(trig, "trigger_sw_seof")) {
  840. host->dma_cmd_trigger = DSI_TRIGGER_SW_SEOF;
  841. } else if (!strcmp(trig, "trigger_sw_te")) {
  842. host->dma_cmd_trigger = DSI_TRIGGER_SW_TE;
  843. } else {
  844. DSI_ERR("[%s] Unrecognized mdp trigger type (%s)\n",
  845. name, trig);
  846. rc = -EINVAL;
  847. }
  848. } else {
  849. DSI_DEBUG("[%s] Falling back to default MDP trigger\n", name);
  850. host->dma_cmd_trigger = DSI_TRIGGER_SW;
  851. }
  852. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-te-pin-select",
  853. &host->te_mode);
  854. if (rc) {
  855. DSI_WARN("[%s] fallback to default te-pin-select\n", name);
  856. host->te_mode = 1;
  857. rc = 0;
  858. }
  859. return rc;
  860. }
  861. static int dsi_panel_parse_misc_host_config(struct dsi_host_common_cfg *host,
  862. struct dsi_parser_utils *utils,
  863. const char *name)
  864. {
  865. u32 val = 0;
  866. int rc = 0;
  867. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-t-clk-post", &val);
  868. if (!rc) {
  869. host->t_clk_post = val;
  870. DSI_DEBUG("[%s] t_clk_post = %d\n", name, val);
  871. }
  872. val = 0;
  873. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-t-clk-pre", &val);
  874. if (!rc) {
  875. host->t_clk_pre = val;
  876. DSI_DEBUG("[%s] t_clk_pre = %d\n", name, val);
  877. }
  878. host->ignore_rx_eot = utils->read_bool(utils->data,
  879. "qcom,mdss-dsi-rx-eot-ignore");
  880. host->append_tx_eot = utils->read_bool(utils->data,
  881. "qcom,mdss-dsi-tx-eot-append");
  882. host->ext_bridge_mode = utils->read_bool(utils->data,
  883. "qcom,mdss-dsi-ext-bridge-mode");
  884. host->force_hs_clk_lane = utils->read_bool(utils->data,
  885. "qcom,mdss-dsi-force-clock-lane-hs");
  886. return 0;
  887. }
  888. static void dsi_panel_parse_split_link_config(struct dsi_host_common_cfg *host,
  889. struct dsi_parser_utils *utils,
  890. const char *name)
  891. {
  892. int rc = 0;
  893. u32 val = 0;
  894. bool supported = false;
  895. struct dsi_split_link_config *split_link = &host->split_link;
  896. supported = utils->read_bool(utils->data, "qcom,split-link-enabled");
  897. if (!supported) {
  898. DSI_DEBUG("[%s] Split link is not supported\n", name);
  899. split_link->split_link_enabled = false;
  900. return;
  901. }
  902. rc = utils->read_u32(utils->data, "qcom,sublinks-count", &val);
  903. if (rc || val < 1) {
  904. DSI_DEBUG("[%s] Using default sublinks count\n", name);
  905. split_link->num_sublinks = 2;
  906. } else {
  907. split_link->num_sublinks = val;
  908. }
  909. rc = utils->read_u32(utils->data, "qcom,lanes-per-sublink", &val);
  910. if (rc || val < 1) {
  911. DSI_DEBUG("[%s] Using default lanes per sublink\n", name);
  912. split_link->lanes_per_sublink = 2;
  913. } else {
  914. split_link->lanes_per_sublink = val;
  915. }
  916. DSI_DEBUG("[%s] Split link is supported %d-%d\n", name,
  917. split_link->num_sublinks, split_link->lanes_per_sublink);
  918. split_link->split_link_enabled = true;
  919. }
  920. static int dsi_panel_parse_host_config(struct dsi_panel *panel)
  921. {
  922. int rc = 0;
  923. struct dsi_parser_utils *utils = &panel->utils;
  924. rc = dsi_panel_parse_pixel_format(&panel->host_config, utils,
  925. panel->name);
  926. if (rc) {
  927. DSI_ERR("[%s] failed to get pixel format, rc=%d\n",
  928. panel->name, rc);
  929. goto error;
  930. }
  931. rc = dsi_panel_parse_lane_states(&panel->host_config, utils,
  932. panel->name);
  933. if (rc) {
  934. DSI_ERR("[%s] failed to parse lane states, rc=%d\n",
  935. panel->name, rc);
  936. goto error;
  937. }
  938. rc = dsi_panel_parse_color_swap(&panel->host_config, utils,
  939. panel->name);
  940. if (rc) {
  941. DSI_ERR("[%s] failed to parse color swap config, rc=%d\n",
  942. panel->name, rc);
  943. goto error;
  944. }
  945. rc = dsi_panel_parse_triggers(&panel->host_config, utils,
  946. panel->name);
  947. if (rc) {
  948. DSI_ERR("[%s] failed to parse triggers, rc=%d\n",
  949. panel->name, rc);
  950. goto error;
  951. }
  952. rc = dsi_panel_parse_misc_host_config(&panel->host_config, utils,
  953. panel->name);
  954. if (rc) {
  955. DSI_ERR("[%s] failed to parse misc host config, rc=%d\n",
  956. panel->name, rc);
  957. goto error;
  958. }
  959. dsi_panel_parse_split_link_config(&panel->host_config, utils,
  960. panel->name);
  961. error:
  962. return rc;
  963. }
  964. static int dsi_panel_parse_qsync_caps(struct dsi_panel *panel,
  965. struct device_node *of_node)
  966. {
  967. int rc = 0;
  968. u32 val = 0;
  969. rc = of_property_read_u32(of_node,
  970. "qcom,mdss-dsi-qsync-min-refresh-rate",
  971. &val);
  972. if (rc)
  973. DSI_DEBUG("[%s] qsync min fps not defined rc:%d\n",
  974. panel->name, rc);
  975. panel->qsync_min_fps = val;
  976. return rc;
  977. }
  978. static int dsi_panel_parse_dyn_clk_caps(struct dsi_panel *panel)
  979. {
  980. int rc = 0;
  981. bool supported = false;
  982. struct dsi_dyn_clk_caps *dyn_clk_caps = &panel->dyn_clk_caps;
  983. struct dsi_parser_utils *utils = &panel->utils;
  984. const char *name = panel->name;
  985. const char *type;
  986. supported = utils->read_bool(utils->data, "qcom,dsi-dyn-clk-enable");
  987. if (!supported) {
  988. dyn_clk_caps->dyn_clk_support = false;
  989. return rc;
  990. }
  991. dyn_clk_caps->bit_clk_list_len = utils->count_u32_elems(utils->data,
  992. "qcom,dsi-dyn-clk-list");
  993. if (dyn_clk_caps->bit_clk_list_len < 1) {
  994. DSI_ERR("[%s] failed to get supported bit clk list\n", name);
  995. return -EINVAL;
  996. }
  997. dyn_clk_caps->bit_clk_list = kcalloc(dyn_clk_caps->bit_clk_list_len,
  998. sizeof(u32), GFP_KERNEL);
  999. if (!dyn_clk_caps->bit_clk_list)
  1000. return -ENOMEM;
  1001. rc = utils->read_u32_array(utils->data, "qcom,dsi-dyn-clk-list",
  1002. dyn_clk_caps->bit_clk_list,
  1003. dyn_clk_caps->bit_clk_list_len);
  1004. if (rc) {
  1005. DSI_ERR("[%s] failed to parse supported bit clk list\n", name);
  1006. return -EINVAL;
  1007. }
  1008. dyn_clk_caps->dyn_clk_support = true;
  1009. type = utils->get_property(utils->data,
  1010. "qcom,dsi-dyn-clk-type", NULL);
  1011. if (!type) {
  1012. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_LEGACY;
  1013. dyn_clk_caps->maintain_const_fps = false;
  1014. return 0;
  1015. }
  1016. if (!strcmp(type, "constant-fps-adjust-hfp")) {
  1017. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_HFP;
  1018. dyn_clk_caps->maintain_const_fps = true;
  1019. } else if (!strcmp(type, "constant-fps-adjust-vfp")) {
  1020. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_CONST_FPS_ADJUST_VFP;
  1021. dyn_clk_caps->maintain_const_fps = true;
  1022. } else {
  1023. dyn_clk_caps->type = DSI_DYN_CLK_TYPE_LEGACY;
  1024. dyn_clk_caps->maintain_const_fps = false;
  1025. }
  1026. DSI_DEBUG("Dynamic clock type is [%s]\n", type);
  1027. return 0;
  1028. }
  1029. static int dsi_panel_parse_dfps_caps(struct dsi_panel *panel)
  1030. {
  1031. int rc = 0;
  1032. bool supported = false;
  1033. struct dsi_dfps_capabilities *dfps_caps = &panel->dfps_caps;
  1034. struct dsi_parser_utils *utils = &panel->utils;
  1035. const char *name = panel->name;
  1036. const char *type;
  1037. u32 i;
  1038. supported = utils->read_bool(utils->data,
  1039. "qcom,mdss-dsi-pan-enable-dynamic-fps");
  1040. if (!supported) {
  1041. DSI_DEBUG("[%s] DFPS is not supported\n", name);
  1042. dfps_caps->dfps_support = false;
  1043. return rc;
  1044. }
  1045. type = utils->get_property(utils->data,
  1046. "qcom,mdss-dsi-pan-fps-update", NULL);
  1047. if (!type) {
  1048. DSI_ERR("[%s] dfps type not defined\n", name);
  1049. rc = -EINVAL;
  1050. goto error;
  1051. } else if (!strcmp(type, "dfps_suspend_resume_mode")) {
  1052. dfps_caps->type = DSI_DFPS_SUSPEND_RESUME;
  1053. } else if (!strcmp(type, "dfps_immediate_clk_mode")) {
  1054. dfps_caps->type = DSI_DFPS_IMMEDIATE_CLK;
  1055. } else if (!strcmp(type, "dfps_immediate_porch_mode_hfp")) {
  1056. dfps_caps->type = DSI_DFPS_IMMEDIATE_HFP;
  1057. } else if (!strcmp(type, "dfps_immediate_porch_mode_vfp")) {
  1058. dfps_caps->type = DSI_DFPS_IMMEDIATE_VFP;
  1059. } else {
  1060. DSI_ERR("[%s] dfps type is not recognized\n", name);
  1061. rc = -EINVAL;
  1062. goto error;
  1063. }
  1064. dfps_caps->dfps_list_len = utils->count_u32_elems(utils->data,
  1065. "qcom,dsi-supported-dfps-list");
  1066. if (dfps_caps->dfps_list_len < 1) {
  1067. DSI_ERR("[%s] dfps refresh list not present\n", name);
  1068. rc = -EINVAL;
  1069. goto error;
  1070. }
  1071. dfps_caps->dfps_list = kcalloc(dfps_caps->dfps_list_len, sizeof(u32),
  1072. GFP_KERNEL);
  1073. if (!dfps_caps->dfps_list) {
  1074. rc = -ENOMEM;
  1075. goto error;
  1076. }
  1077. rc = utils->read_u32_array(utils->data,
  1078. "qcom,dsi-supported-dfps-list",
  1079. dfps_caps->dfps_list,
  1080. dfps_caps->dfps_list_len);
  1081. if (rc) {
  1082. DSI_ERR("[%s] dfps refresh rate list parse failed\n", name);
  1083. rc = -EINVAL;
  1084. goto error;
  1085. }
  1086. dfps_caps->dfps_support = true;
  1087. /* calculate max and min fps */
  1088. dfps_caps->max_refresh_rate = dfps_caps->dfps_list[0];
  1089. dfps_caps->min_refresh_rate = dfps_caps->dfps_list[0];
  1090. for (i = 1; i < dfps_caps->dfps_list_len; i++) {
  1091. if (dfps_caps->dfps_list[i] < dfps_caps->min_refresh_rate)
  1092. dfps_caps->min_refresh_rate = dfps_caps->dfps_list[i];
  1093. else if (dfps_caps->dfps_list[i] > dfps_caps->max_refresh_rate)
  1094. dfps_caps->max_refresh_rate = dfps_caps->dfps_list[i];
  1095. }
  1096. error:
  1097. return rc;
  1098. }
  1099. static int dsi_panel_parse_video_host_config(struct dsi_video_engine_cfg *cfg,
  1100. struct dsi_parser_utils *utils,
  1101. const char *name)
  1102. {
  1103. int rc = 0;
  1104. const char *traffic_mode;
  1105. u32 vc_id = 0;
  1106. u32 val = 0;
  1107. u32 line_no = 0;
  1108. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-h-sync-pulse", &val);
  1109. if (rc) {
  1110. DSI_DEBUG("[%s] fallback to default h-sync-pulse\n", name);
  1111. cfg->pulse_mode_hsa_he = false;
  1112. } else if (val == 1) {
  1113. cfg->pulse_mode_hsa_he = true;
  1114. } else if (val == 0) {
  1115. cfg->pulse_mode_hsa_he = false;
  1116. } else {
  1117. DSI_ERR("[%s] Unrecognized value for mdss-dsi-h-sync-pulse\n",
  1118. name);
  1119. rc = -EINVAL;
  1120. goto error;
  1121. }
  1122. cfg->hfp_lp11_en = utils->read_bool(utils->data,
  1123. "qcom,mdss-dsi-hfp-power-mode");
  1124. cfg->hbp_lp11_en = utils->read_bool(utils->data,
  1125. "qcom,mdss-dsi-hbp-power-mode");
  1126. cfg->hsa_lp11_en = utils->read_bool(utils->data,
  1127. "qcom,mdss-dsi-hsa-power-mode");
  1128. cfg->last_line_interleave_en = utils->read_bool(utils->data,
  1129. "qcom,mdss-dsi-last-line-interleave");
  1130. cfg->eof_bllp_lp11_en = utils->read_bool(utils->data,
  1131. "qcom,mdss-dsi-bllp-eof-power-mode");
  1132. cfg->bllp_lp11_en = utils->read_bool(utils->data,
  1133. "qcom,mdss-dsi-bllp-power-mode");
  1134. cfg->force_clk_lane_hs = of_property_read_bool(utils->data,
  1135. "qcom,mdss-dsi-force-clock-lane-hs");
  1136. traffic_mode = utils->get_property(utils->data,
  1137. "qcom,mdss-dsi-traffic-mode",
  1138. NULL);
  1139. if (!traffic_mode) {
  1140. DSI_DEBUG("[%s] Falling back to default traffic mode\n", name);
  1141. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  1142. } else if (!strcmp(traffic_mode, "non_burst_sync_pulse")) {
  1143. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_PULSES;
  1144. } else if (!strcmp(traffic_mode, "non_burst_sync_event")) {
  1145. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_SYNC_START_EVENTS;
  1146. } else if (!strcmp(traffic_mode, "burst_mode")) {
  1147. cfg->traffic_mode = DSI_VIDEO_TRAFFIC_BURST_MODE;
  1148. } else {
  1149. DSI_ERR("[%s] Unrecognized traffic mode-%s\n", name,
  1150. traffic_mode);
  1151. rc = -EINVAL;
  1152. goto error;
  1153. }
  1154. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-virtual-channel-id",
  1155. &vc_id);
  1156. if (rc) {
  1157. DSI_DEBUG("[%s] Fallback to default vc id\n", name);
  1158. cfg->vc_id = 0;
  1159. } else {
  1160. cfg->vc_id = vc_id;
  1161. }
  1162. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-dma-schedule-line",
  1163. &line_no);
  1164. if (rc) {
  1165. DSI_DEBUG("[%s] set default dma scheduling line no\n", name);
  1166. cfg->dma_sched_line = 0x1;
  1167. /* do not fail since we have default value */
  1168. rc = 0;
  1169. } else {
  1170. cfg->dma_sched_line = line_no;
  1171. }
  1172. error:
  1173. return rc;
  1174. }
  1175. static int dsi_panel_parse_cmd_host_config(struct dsi_cmd_engine_cfg *cfg,
  1176. struct dsi_parser_utils *utils,
  1177. const char *name)
  1178. {
  1179. u32 val = 0;
  1180. int rc = 0;
  1181. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-wr-mem-start", &val);
  1182. if (rc) {
  1183. DSI_DEBUG("[%s] Fallback to default wr-mem-start\n", name);
  1184. cfg->wr_mem_start = 0x2C;
  1185. } else {
  1186. cfg->wr_mem_start = val;
  1187. }
  1188. val = 0;
  1189. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-wr-mem-continue",
  1190. &val);
  1191. if (rc) {
  1192. DSI_DEBUG("[%s] Fallback to default wr-mem-continue\n", name);
  1193. cfg->wr_mem_continue = 0x3C;
  1194. } else {
  1195. cfg->wr_mem_continue = val;
  1196. }
  1197. /* TODO: fix following */
  1198. cfg->max_cmd_packets_interleave = 0;
  1199. val = 0;
  1200. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-te-dcs-command",
  1201. &val);
  1202. if (rc) {
  1203. DSI_DEBUG("[%s] fallback to default te-dcs-cmd\n", name);
  1204. cfg->insert_dcs_command = true;
  1205. } else if (val == 1) {
  1206. cfg->insert_dcs_command = true;
  1207. } else if (val == 0) {
  1208. cfg->insert_dcs_command = false;
  1209. } else {
  1210. DSI_ERR("[%s] Unrecognized value for mdss-dsi-te-dcs-command\n",
  1211. name);
  1212. rc = -EINVAL;
  1213. goto error;
  1214. }
  1215. error:
  1216. return rc;
  1217. }
  1218. static int dsi_panel_parse_panel_mode(struct dsi_panel *panel)
  1219. {
  1220. int rc = 0;
  1221. struct dsi_parser_utils *utils = &panel->utils;
  1222. bool panel_mode_switch_enabled;
  1223. enum dsi_op_mode panel_mode;
  1224. const char *mode;
  1225. mode = utils->get_property(utils->data,
  1226. "qcom,mdss-dsi-panel-type", NULL);
  1227. if (!mode) {
  1228. DSI_DEBUG("[%s] Fallback to default panel mode\n", panel->name);
  1229. panel_mode = DSI_OP_VIDEO_MODE;
  1230. } else if (!strcmp(mode, "dsi_video_mode")) {
  1231. panel_mode = DSI_OP_VIDEO_MODE;
  1232. } else if (!strcmp(mode, "dsi_cmd_mode")) {
  1233. panel_mode = DSI_OP_CMD_MODE;
  1234. } else {
  1235. DSI_ERR("[%s] Unrecognized panel type-%s\n", panel->name, mode);
  1236. rc = -EINVAL;
  1237. goto error;
  1238. }
  1239. panel_mode_switch_enabled = utils->read_bool(utils->data,
  1240. "qcom,mdss-dsi-panel-mode-switch");
  1241. DSI_DEBUG("%s: panel operating mode switch feature %s\n", __func__,
  1242. (panel_mode_switch_enabled ? "enabled" : "disabled"));
  1243. if (panel_mode == DSI_OP_VIDEO_MODE || panel_mode_switch_enabled) {
  1244. rc = dsi_panel_parse_video_host_config(&panel->video_config,
  1245. utils,
  1246. panel->name);
  1247. if (rc) {
  1248. DSI_ERR("[%s] Failed to parse video host cfg, rc=%d\n",
  1249. panel->name, rc);
  1250. goto error;
  1251. }
  1252. }
  1253. if (panel_mode == DSI_OP_CMD_MODE || panel_mode_switch_enabled) {
  1254. rc = dsi_panel_parse_cmd_host_config(&panel->cmd_config,
  1255. utils,
  1256. panel->name);
  1257. if (rc) {
  1258. DSI_ERR("[%s] Failed to parse cmd host config, rc=%d\n",
  1259. panel->name, rc);
  1260. goto error;
  1261. }
  1262. }
  1263. panel->poms_align_vsync = utils->read_bool(utils->data,
  1264. "qcom,poms-align-panel-vsync");
  1265. panel->panel_mode = panel_mode;
  1266. panel->panel_mode_switch_enabled = panel_mode_switch_enabled;
  1267. error:
  1268. return rc;
  1269. }
  1270. static int dsi_panel_parse_phy_props(struct dsi_panel *panel)
  1271. {
  1272. int rc = 0;
  1273. u32 val = 0;
  1274. const char *str;
  1275. struct dsi_panel_phy_props *props = &panel->phy_props;
  1276. struct dsi_parser_utils *utils = &panel->utils;
  1277. const char *name = panel->name;
  1278. rc = utils->read_u32(utils->data,
  1279. "qcom,mdss-pan-physical-width-dimension", &val);
  1280. if (rc) {
  1281. DSI_DEBUG("[%s] Physical panel width is not defined\n", name);
  1282. props->panel_width_mm = 0;
  1283. rc = 0;
  1284. } else {
  1285. props->panel_width_mm = val;
  1286. }
  1287. rc = utils->read_u32(utils->data,
  1288. "qcom,mdss-pan-physical-height-dimension",
  1289. &val);
  1290. if (rc) {
  1291. DSI_DEBUG("[%s] Physical panel height is not defined\n", name);
  1292. props->panel_height_mm = 0;
  1293. rc = 0;
  1294. } else {
  1295. props->panel_height_mm = val;
  1296. }
  1297. str = utils->get_property(utils->data,
  1298. "qcom,mdss-dsi-panel-orientation", NULL);
  1299. if (!str) {
  1300. props->rotation = DSI_PANEL_ROTATE_NONE;
  1301. } else if (!strcmp(str, "180")) {
  1302. props->rotation = DSI_PANEL_ROTATE_HV_FLIP;
  1303. } else if (!strcmp(str, "hflip")) {
  1304. props->rotation = DSI_PANEL_ROTATE_H_FLIP;
  1305. } else if (!strcmp(str, "vflip")) {
  1306. props->rotation = DSI_PANEL_ROTATE_V_FLIP;
  1307. } else {
  1308. DSI_ERR("[%s] Unrecognized panel rotation-%s\n", name, str);
  1309. rc = -EINVAL;
  1310. goto error;
  1311. }
  1312. error:
  1313. return rc;
  1314. }
  1315. const char *cmd_set_prop_map[DSI_CMD_SET_MAX] = {
  1316. "qcom,mdss-dsi-pre-on-command",
  1317. "qcom,mdss-dsi-on-command",
  1318. "qcom,mdss-dsi-post-panel-on-command",
  1319. "qcom,mdss-dsi-pre-off-command",
  1320. "qcom,mdss-dsi-off-command",
  1321. "qcom,mdss-dsi-post-off-command",
  1322. "qcom,mdss-dsi-pre-res-switch",
  1323. "qcom,mdss-dsi-res-switch",
  1324. "qcom,mdss-dsi-post-res-switch",
  1325. "qcom,cmd-to-video-mode-switch-commands",
  1326. "qcom,cmd-to-video-mode-post-switch-commands",
  1327. "qcom,video-to-cmd-mode-switch-commands",
  1328. "qcom,video-to-cmd-mode-post-switch-commands",
  1329. "qcom,mdss-dsi-panel-status-command",
  1330. "qcom,mdss-dsi-lp1-command",
  1331. "qcom,mdss-dsi-lp2-command",
  1332. "qcom,mdss-dsi-nolp-command",
  1333. "PPS not parsed from DTSI, generated dynamically",
  1334. "ROI not parsed from DTSI, generated dynamically",
  1335. "qcom,mdss-dsi-timing-switch-command",
  1336. "qcom,mdss-dsi-post-mode-switch-on-command",
  1337. "qcom,mdss-dsi-qsync-on-commands",
  1338. "qcom,mdss-dsi-qsync-off-commands",
  1339. };
  1340. const char *cmd_set_state_map[DSI_CMD_SET_MAX] = {
  1341. "qcom,mdss-dsi-pre-on-command-state",
  1342. "qcom,mdss-dsi-on-command-state",
  1343. "qcom,mdss-dsi-post-on-command-state",
  1344. "qcom,mdss-dsi-pre-off-command-state",
  1345. "qcom,mdss-dsi-off-command-state",
  1346. "qcom,mdss-dsi-post-off-command-state",
  1347. "qcom,mdss-dsi-pre-res-switch-state",
  1348. "qcom,mdss-dsi-res-switch-state",
  1349. "qcom,mdss-dsi-post-res-switch-state",
  1350. "qcom,cmd-to-video-mode-switch-commands-state",
  1351. "qcom,cmd-to-video-mode-post-switch-commands-state",
  1352. "qcom,video-to-cmd-mode-switch-commands-state",
  1353. "qcom,video-to-cmd-mode-post-switch-commands-state",
  1354. "qcom,mdss-dsi-panel-status-command-state",
  1355. "qcom,mdss-dsi-lp1-command-state",
  1356. "qcom,mdss-dsi-lp2-command-state",
  1357. "qcom,mdss-dsi-nolp-command-state",
  1358. "PPS not parsed from DTSI, generated dynamically",
  1359. "ROI not parsed from DTSI, generated dynamically",
  1360. "qcom,mdss-dsi-timing-switch-command-state",
  1361. "qcom,mdss-dsi-post-mode-switch-on-command-state",
  1362. "qcom,mdss-dsi-qsync-on-commands-state",
  1363. "qcom,mdss-dsi-qsync-off-commands-state",
  1364. };
  1365. static int dsi_panel_get_cmd_pkt_count(const char *data, u32 length, u32 *cnt)
  1366. {
  1367. const u32 cmd_set_min_size = 7;
  1368. u32 count = 0;
  1369. u32 packet_length;
  1370. u32 tmp;
  1371. while (length >= cmd_set_min_size) {
  1372. packet_length = cmd_set_min_size;
  1373. tmp = ((data[5] << 8) | (data[6]));
  1374. packet_length += tmp;
  1375. if (packet_length > length) {
  1376. DSI_ERR("format error\n");
  1377. return -EINVAL;
  1378. }
  1379. length -= packet_length;
  1380. data += packet_length;
  1381. count++;
  1382. }
  1383. *cnt = count;
  1384. return 0;
  1385. }
  1386. static int dsi_panel_create_cmd_packets(const char *data,
  1387. u32 length,
  1388. u32 count,
  1389. struct dsi_cmd_desc *cmd)
  1390. {
  1391. int rc = 0;
  1392. int i, j;
  1393. u8 *payload;
  1394. for (i = 0; i < count; i++) {
  1395. u32 size;
  1396. cmd[i].msg.type = data[0];
  1397. cmd[i].last_command = (data[1] == 1);
  1398. cmd[i].msg.channel = data[2];
  1399. cmd[i].msg.flags |= (data[3] == 1 ? MIPI_DSI_MSG_REQ_ACK : 0);
  1400. cmd[i].msg.ctrl = 0;
  1401. cmd[i].post_wait_ms = cmd[i].msg.wait_ms = data[4];
  1402. cmd[i].msg.tx_len = ((data[5] << 8) | (data[6]));
  1403. size = cmd[i].msg.tx_len * sizeof(u8);
  1404. payload = kzalloc(size, GFP_KERNEL);
  1405. if (!payload) {
  1406. rc = -ENOMEM;
  1407. goto error_free_payloads;
  1408. }
  1409. for (j = 0; j < cmd[i].msg.tx_len; j++)
  1410. payload[j] = data[7 + j];
  1411. cmd[i].msg.tx_buf = payload;
  1412. data += (7 + cmd[i].msg.tx_len);
  1413. }
  1414. return rc;
  1415. error_free_payloads:
  1416. for (i = i - 1; i >= 0; i--) {
  1417. cmd--;
  1418. kfree(cmd->msg.tx_buf);
  1419. }
  1420. return rc;
  1421. }
  1422. static void dsi_panel_destroy_cmd_packets(struct dsi_panel_cmd_set *set)
  1423. {
  1424. u32 i = 0;
  1425. struct dsi_cmd_desc *cmd;
  1426. for (i = 0; i < set->count; i++) {
  1427. cmd = &set->cmds[i];
  1428. kfree(cmd->msg.tx_buf);
  1429. }
  1430. }
  1431. static void dsi_panel_dealloc_cmd_packets(struct dsi_panel_cmd_set *set)
  1432. {
  1433. kfree(set->cmds);
  1434. }
  1435. static int dsi_panel_alloc_cmd_packets(struct dsi_panel_cmd_set *cmd,
  1436. u32 packet_count)
  1437. {
  1438. u32 size;
  1439. size = packet_count * sizeof(*cmd->cmds);
  1440. cmd->cmds = kzalloc(size, GFP_KERNEL);
  1441. if (!cmd->cmds)
  1442. return -ENOMEM;
  1443. cmd->count = packet_count;
  1444. return 0;
  1445. }
  1446. static int dsi_panel_parse_cmd_sets_sub(struct dsi_panel_cmd_set *cmd,
  1447. enum dsi_cmd_set_type type,
  1448. struct dsi_parser_utils *utils)
  1449. {
  1450. int rc = 0;
  1451. u32 length = 0;
  1452. const char *data;
  1453. const char *state;
  1454. u32 packet_count = 0;
  1455. data = utils->get_property(utils->data, cmd_set_prop_map[type],
  1456. &length);
  1457. if (!data) {
  1458. DSI_DEBUG("%s commands not defined\n", cmd_set_prop_map[type]);
  1459. rc = -ENOTSUPP;
  1460. goto error;
  1461. }
  1462. DSI_DEBUG("type=%d, name=%s, length=%d\n", type,
  1463. cmd_set_prop_map[type], length);
  1464. print_hex_dump_debug("", DUMP_PREFIX_NONE,
  1465. 8, 1, data, length, false);
  1466. rc = dsi_panel_get_cmd_pkt_count(data, length, &packet_count);
  1467. if (rc) {
  1468. DSI_ERR("commands failed, rc=%d\n", rc);
  1469. goto error;
  1470. }
  1471. DSI_DEBUG("[%s] packet-count=%d, %d\n", cmd_set_prop_map[type],
  1472. packet_count, length);
  1473. rc = dsi_panel_alloc_cmd_packets(cmd, packet_count);
  1474. if (rc) {
  1475. DSI_ERR("failed to allocate cmd packets, rc=%d\n", rc);
  1476. goto error;
  1477. }
  1478. rc = dsi_panel_create_cmd_packets(data, length, packet_count,
  1479. cmd->cmds);
  1480. if (rc) {
  1481. DSI_ERR("failed to create cmd packets, rc=%d\n", rc);
  1482. goto error_free_mem;
  1483. }
  1484. state = utils->get_property(utils->data, cmd_set_state_map[type], NULL);
  1485. if (!state || !strcmp(state, "dsi_lp_mode")) {
  1486. cmd->state = DSI_CMD_SET_STATE_LP;
  1487. } else if (!strcmp(state, "dsi_hs_mode")) {
  1488. cmd->state = DSI_CMD_SET_STATE_HS;
  1489. } else {
  1490. DSI_ERR("[%s] command state unrecognized-%s\n",
  1491. cmd_set_state_map[type], state);
  1492. goto error_free_mem;
  1493. }
  1494. return rc;
  1495. error_free_mem:
  1496. kfree(cmd->cmds);
  1497. cmd->cmds = NULL;
  1498. error:
  1499. return rc;
  1500. }
  1501. static int dsi_panel_parse_cmd_sets(
  1502. struct dsi_display_mode_priv_info *priv_info,
  1503. struct dsi_parser_utils *utils)
  1504. {
  1505. int rc = 0;
  1506. struct dsi_panel_cmd_set *set;
  1507. u32 i;
  1508. if (!priv_info) {
  1509. DSI_ERR("invalid mode priv info\n");
  1510. return -EINVAL;
  1511. }
  1512. for (i = DSI_CMD_SET_PRE_ON; i < DSI_CMD_SET_MAX; i++) {
  1513. set = &priv_info->cmd_sets[i];
  1514. set->type = i;
  1515. set->count = 0;
  1516. if (i == DSI_CMD_SET_PPS) {
  1517. rc = dsi_panel_alloc_cmd_packets(set, 1);
  1518. if (rc)
  1519. DSI_ERR("failed to allocate cmd set %d, rc = %d\n",
  1520. i, rc);
  1521. set->state = DSI_CMD_SET_STATE_LP;
  1522. } else {
  1523. rc = dsi_panel_parse_cmd_sets_sub(set, i, utils);
  1524. if (rc)
  1525. DSI_DEBUG("failed to parse set %d\n", i);
  1526. }
  1527. }
  1528. rc = 0;
  1529. return rc;
  1530. }
  1531. static int dsi_panel_parse_reset_sequence(struct dsi_panel *panel)
  1532. {
  1533. int rc = 0;
  1534. int i;
  1535. u32 length = 0;
  1536. u32 count = 0;
  1537. u32 size = 0;
  1538. u32 *arr_32 = NULL;
  1539. const u32 *arr;
  1540. struct dsi_parser_utils *utils = &panel->utils;
  1541. struct dsi_reset_seq *seq;
  1542. if (panel->host_config.ext_bridge_mode)
  1543. return 0;
  1544. arr = utils->get_property(utils->data,
  1545. "qcom,mdss-dsi-reset-sequence", &length);
  1546. if (!arr) {
  1547. DSI_ERR("[%s] dsi-reset-sequence not found\n", panel->name);
  1548. rc = -EINVAL;
  1549. goto error;
  1550. }
  1551. if (length & 0x1) {
  1552. DSI_ERR("[%s] syntax error for dsi-reset-sequence\n",
  1553. panel->name);
  1554. rc = -EINVAL;
  1555. goto error;
  1556. }
  1557. DSI_DEBUG("RESET SEQ LENGTH = %d\n", length);
  1558. length = length / sizeof(u32);
  1559. size = length * sizeof(u32);
  1560. arr_32 = kzalloc(size, GFP_KERNEL);
  1561. if (!arr_32) {
  1562. rc = -ENOMEM;
  1563. goto error;
  1564. }
  1565. rc = utils->read_u32_array(utils->data, "qcom,mdss-dsi-reset-sequence",
  1566. arr_32, length);
  1567. if (rc) {
  1568. DSI_ERR("[%s] cannot read dso-reset-seqience\n", panel->name);
  1569. goto error_free_arr_32;
  1570. }
  1571. count = length / 2;
  1572. size = count * sizeof(*seq);
  1573. seq = kzalloc(size, GFP_KERNEL);
  1574. if (!seq) {
  1575. rc = -ENOMEM;
  1576. goto error_free_arr_32;
  1577. }
  1578. panel->reset_config.sequence = seq;
  1579. panel->reset_config.count = count;
  1580. for (i = 0; i < length; i += 2) {
  1581. seq->level = arr_32[i];
  1582. seq->sleep_ms = arr_32[i + 1];
  1583. seq++;
  1584. }
  1585. error_free_arr_32:
  1586. kfree(arr_32);
  1587. error:
  1588. return rc;
  1589. }
  1590. static int dsi_panel_parse_misc_features(struct dsi_panel *panel)
  1591. {
  1592. struct dsi_parser_utils *utils = &panel->utils;
  1593. const char *string;
  1594. int i, rc = 0;
  1595. panel->ulps_feature_enabled =
  1596. utils->read_bool(utils->data, "qcom,ulps-enabled");
  1597. DSI_DEBUG("%s: ulps feature %s\n", __func__,
  1598. (panel->ulps_feature_enabled ? "enabled" : "disabled"));
  1599. panel->ulps_suspend_enabled =
  1600. utils->read_bool(utils->data, "qcom,suspend-ulps-enabled");
  1601. DSI_DEBUG("%s: ulps during suspend feature %s\n", __func__,
  1602. (panel->ulps_suspend_enabled ? "enabled" : "disabled"));
  1603. panel->te_using_watchdog_timer = utils->read_bool(utils->data,
  1604. "qcom,mdss-dsi-te-using-wd");
  1605. panel->sync_broadcast_en = utils->read_bool(utils->data,
  1606. "qcom,cmd-sync-wait-broadcast");
  1607. panel->lp11_init = utils->read_bool(utils->data,
  1608. "qcom,mdss-dsi-lp11-init");
  1609. panel->spr_info.enable = false;
  1610. panel->spr_info.pack_type = MSM_DISPLAY_SPR_TYPE_MAX;
  1611. rc = utils->read_string(utils->data, "qcom,spr-pack-type", &string);
  1612. if (!rc) {
  1613. // find match for pack-type string
  1614. for (i = 0; i < MSM_DISPLAY_SPR_TYPE_MAX; i++) {
  1615. if (msm_spr_pack_type_str[i] &&
  1616. (!strcmp(string, msm_spr_pack_type_str[i]))) {
  1617. panel->spr_info.enable = true;
  1618. panel->spr_info.pack_type = i;
  1619. break;
  1620. }
  1621. }
  1622. }
  1623. pr_debug("%s source side spr packing, pack-type %s\n",
  1624. panel->spr_info.enable ? "enable" : "disable",
  1625. panel->spr_info.enable ?
  1626. msm_spr_pack_type_str[panel->spr_info.pack_type] : "none");
  1627. return 0;
  1628. }
  1629. static int dsi_panel_parse_jitter_config(
  1630. struct dsi_display_mode *mode,
  1631. struct dsi_parser_utils *utils)
  1632. {
  1633. int rc;
  1634. struct dsi_display_mode_priv_info *priv_info;
  1635. u32 jitter[DEFAULT_PANEL_JITTER_ARRAY_SIZE] = {0, 0};
  1636. u64 jitter_val = 0;
  1637. priv_info = mode->priv_info;
  1638. rc = utils->read_u32_array(utils->data, "qcom,mdss-dsi-panel-jitter",
  1639. jitter, DEFAULT_PANEL_JITTER_ARRAY_SIZE);
  1640. if (rc) {
  1641. DSI_DEBUG("panel jitter not defined rc=%d\n", rc);
  1642. } else {
  1643. jitter_val = jitter[0];
  1644. jitter_val = div_u64(jitter_val, jitter[1]);
  1645. }
  1646. if (rc || !jitter_val || (jitter_val > MAX_PANEL_JITTER)) {
  1647. priv_info->panel_jitter_numer = DEFAULT_PANEL_JITTER_NUMERATOR;
  1648. priv_info->panel_jitter_denom =
  1649. DEFAULT_PANEL_JITTER_DENOMINATOR;
  1650. } else {
  1651. priv_info->panel_jitter_numer = jitter[0];
  1652. priv_info->panel_jitter_denom = jitter[1];
  1653. }
  1654. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-panel-prefill-lines",
  1655. &priv_info->panel_prefill_lines);
  1656. if (rc) {
  1657. DSI_DEBUG("panel prefill lines are not defined rc=%d\n", rc);
  1658. priv_info->panel_prefill_lines = mode->timing.v_back_porch +
  1659. mode->timing.v_sync_width + mode->timing.v_front_porch;
  1660. } else if (priv_info->panel_prefill_lines >=
  1661. DSI_V_TOTAL(&mode->timing)) {
  1662. DSI_DEBUG("invalid prefill lines config=%d setting to:%d\n",
  1663. priv_info->panel_prefill_lines, DEFAULT_PANEL_PREFILL_LINES);
  1664. priv_info->panel_prefill_lines = DEFAULT_PANEL_PREFILL_LINES;
  1665. }
  1666. return 0;
  1667. }
  1668. static int dsi_panel_parse_power_cfg(struct dsi_panel *panel)
  1669. {
  1670. int rc = 0;
  1671. char *supply_name;
  1672. if (panel->host_config.ext_bridge_mode)
  1673. return 0;
  1674. if (!strcmp(panel->type, "primary"))
  1675. supply_name = "qcom,panel-supply-entries";
  1676. else
  1677. supply_name = "qcom,panel-sec-supply-entries";
  1678. rc = dsi_pwr_of_get_vreg_data(&panel->utils,
  1679. &panel->power_info, supply_name);
  1680. if (rc) {
  1681. DSI_ERR("[%s] failed to parse vregs\n", panel->name);
  1682. goto error;
  1683. }
  1684. error:
  1685. return rc;
  1686. }
  1687. static int dsi_panel_parse_gpios(struct dsi_panel *panel)
  1688. {
  1689. int rc = 0;
  1690. const char *data;
  1691. struct dsi_parser_utils *utils = &panel->utils;
  1692. char *reset_gpio_name, *mode_set_gpio_name;
  1693. if (!strcmp(panel->type, "primary")) {
  1694. reset_gpio_name = "qcom,platform-reset-gpio";
  1695. mode_set_gpio_name = "qcom,panel-mode-gpio";
  1696. } else {
  1697. reset_gpio_name = "qcom,platform-sec-reset-gpio";
  1698. mode_set_gpio_name = "qcom,panel-sec-mode-gpio";
  1699. }
  1700. panel->reset_config.reset_gpio = utils->get_named_gpio(utils->data,
  1701. reset_gpio_name, 0);
  1702. if (!gpio_is_valid(panel->reset_config.reset_gpio) &&
  1703. !panel->host_config.ext_bridge_mode) {
  1704. rc = panel->reset_config.reset_gpio;
  1705. DSI_ERR("[%s] failed get reset gpio, rc=%d\n", panel->name, rc);
  1706. goto error;
  1707. }
  1708. panel->reset_config.disp_en_gpio = utils->get_named_gpio(utils->data,
  1709. "qcom,5v-boost-gpio",
  1710. 0);
  1711. if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  1712. DSI_DEBUG("[%s] 5v-boot-gpio is not set, rc=%d\n",
  1713. panel->name, rc);
  1714. panel->reset_config.disp_en_gpio =
  1715. utils->get_named_gpio(utils->data,
  1716. "qcom,platform-en-gpio", 0);
  1717. if (!gpio_is_valid(panel->reset_config.disp_en_gpio)) {
  1718. DSI_DEBUG("[%s] platform-en-gpio is not set, rc=%d\n",
  1719. panel->name, rc);
  1720. }
  1721. }
  1722. panel->reset_config.lcd_mode_sel_gpio = utils->get_named_gpio(
  1723. utils->data, mode_set_gpio_name, 0);
  1724. if (!gpio_is_valid(panel->reset_config.lcd_mode_sel_gpio))
  1725. DSI_DEBUG("mode gpio not specified\n");
  1726. DSI_DEBUG("mode gpio=%d\n", panel->reset_config.lcd_mode_sel_gpio);
  1727. data = utils->get_property(utils->data,
  1728. "qcom,mdss-dsi-mode-sel-gpio-state", NULL);
  1729. if (data) {
  1730. if (!strcmp(data, "single_port"))
  1731. panel->reset_config.mode_sel_state =
  1732. MODE_SEL_SINGLE_PORT;
  1733. else if (!strcmp(data, "dual_port"))
  1734. panel->reset_config.mode_sel_state =
  1735. MODE_SEL_DUAL_PORT;
  1736. else if (!strcmp(data, "high"))
  1737. panel->reset_config.mode_sel_state =
  1738. MODE_GPIO_HIGH;
  1739. else if (!strcmp(data, "low"))
  1740. panel->reset_config.mode_sel_state =
  1741. MODE_GPIO_LOW;
  1742. } else {
  1743. /* Set default mode as SPLIT mode */
  1744. panel->reset_config.mode_sel_state = MODE_SEL_DUAL_PORT;
  1745. }
  1746. /* TODO: release memory */
  1747. rc = dsi_panel_parse_reset_sequence(panel);
  1748. if (rc) {
  1749. DSI_ERR("[%s] failed to parse reset sequence, rc=%d\n",
  1750. panel->name, rc);
  1751. goto error;
  1752. }
  1753. panel->panel_test_gpio = utils->get_named_gpio(utils->data,
  1754. "qcom,mdss-dsi-panel-test-pin",
  1755. 0);
  1756. if (!gpio_is_valid(panel->panel_test_gpio))
  1757. DSI_DEBUG("%s:%d panel test gpio not specified\n", __func__,
  1758. __LINE__);
  1759. error:
  1760. return rc;
  1761. }
  1762. static int dsi_panel_parse_bl_pwm_config(struct dsi_panel *panel)
  1763. {
  1764. int rc = 0;
  1765. u32 val;
  1766. struct dsi_backlight_config *config = &panel->bl_config;
  1767. struct dsi_parser_utils *utils = &panel->utils;
  1768. rc = utils->read_u32(utils->data, "qcom,bl-pmic-pwm-period-usecs",
  1769. &val);
  1770. if (rc) {
  1771. DSI_ERR("bl-pmic-pwm-period-usecs is not defined, rc=%d\n", rc);
  1772. goto error;
  1773. }
  1774. config->pwm_period_usecs = val;
  1775. error:
  1776. return rc;
  1777. }
  1778. static int dsi_panel_parse_bl_config(struct dsi_panel *panel)
  1779. {
  1780. int rc = 0;
  1781. u32 val = 0;
  1782. const char *bl_type;
  1783. const char *data;
  1784. struct dsi_parser_utils *utils = &panel->utils;
  1785. char *bl_name;
  1786. if (!strcmp(panel->type, "primary"))
  1787. bl_name = "qcom,mdss-dsi-bl-pmic-control-type";
  1788. else
  1789. bl_name = "qcom,mdss-dsi-sec-bl-pmic-control-type";
  1790. bl_type = utils->get_property(utils->data, bl_name, NULL);
  1791. if (!bl_type) {
  1792. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  1793. } else if (!strcmp(bl_type, "bl_ctrl_pwm")) {
  1794. panel->bl_config.type = DSI_BACKLIGHT_PWM;
  1795. } else if (!strcmp(bl_type, "bl_ctrl_wled")) {
  1796. panel->bl_config.type = DSI_BACKLIGHT_WLED;
  1797. } else if (!strcmp(bl_type, "bl_ctrl_dcs")) {
  1798. panel->bl_config.type = DSI_BACKLIGHT_DCS;
  1799. } else if (!strcmp(bl_type, "bl_ctrl_external")) {
  1800. panel->bl_config.type = DSI_BACKLIGHT_EXTERNAL;
  1801. } else {
  1802. DSI_DEBUG("[%s] bl-pmic-control-type unknown-%s\n",
  1803. panel->name, bl_type);
  1804. panel->bl_config.type = DSI_BACKLIGHT_UNKNOWN;
  1805. }
  1806. data = utils->get_property(utils->data, "qcom,bl-update-flag", NULL);
  1807. if (!data) {
  1808. panel->bl_config.bl_update = BL_UPDATE_NONE;
  1809. } else if (!strcmp(data, "delay_until_first_frame")) {
  1810. panel->bl_config.bl_update = BL_UPDATE_DELAY_UNTIL_FIRST_FRAME;
  1811. } else {
  1812. DSI_DEBUG("[%s] No valid bl-update-flag: %s\n",
  1813. panel->name, data);
  1814. panel->bl_config.bl_update = BL_UPDATE_NONE;
  1815. }
  1816. panel->bl_config.bl_scale = MAX_BL_SCALE_LEVEL;
  1817. panel->bl_config.bl_scale_sv = MAX_SV_BL_SCALE_LEVEL;
  1818. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bl-min-level", &val);
  1819. if (rc) {
  1820. DSI_DEBUG("[%s] bl-min-level unspecified, defaulting to zero\n",
  1821. panel->name);
  1822. panel->bl_config.bl_min_level = 0;
  1823. } else {
  1824. panel->bl_config.bl_min_level = val;
  1825. }
  1826. rc = utils->read_u32(utils->data, "qcom,mdss-dsi-bl-max-level", &val);
  1827. if (rc) {
  1828. DSI_DEBUG("[%s] bl-max-level unspecified, defaulting to max level\n",
  1829. panel->name);
  1830. panel->bl_config.bl_max_level = MAX_BL_LEVEL;
  1831. } else {
  1832. panel->bl_config.bl_max_level = val;
  1833. }
  1834. rc = utils->read_u32(utils->data, "qcom,mdss-brightness-max-level",
  1835. &val);
  1836. if (rc) {
  1837. DSI_DEBUG("[%s] brigheness-max-level unspecified, defaulting to 255\n",
  1838. panel->name);
  1839. panel->bl_config.brightness_max_level = 255;
  1840. } else {
  1841. panel->bl_config.brightness_max_level = val;
  1842. }
  1843. if (panel->bl_config.type == DSI_BACKLIGHT_PWM) {
  1844. rc = dsi_panel_parse_bl_pwm_config(panel);
  1845. if (rc) {
  1846. DSI_ERR("[%s] failed to parse pwm config, rc=%d\n",
  1847. panel->name, rc);
  1848. goto error;
  1849. }
  1850. }
  1851. panel->bl_config.en_gpio = utils->get_named_gpio(utils->data,
  1852. "qcom,platform-bklight-en-gpio",
  1853. 0);
  1854. if (!gpio_is_valid(panel->bl_config.en_gpio)) {
  1855. if (panel->bl_config.en_gpio == -EPROBE_DEFER) {
  1856. DSI_DEBUG("[%s] failed to get bklt gpio, rc=%d\n",
  1857. panel->name, rc);
  1858. rc = -EPROBE_DEFER;
  1859. goto error;
  1860. } else {
  1861. DSI_DEBUG("[%s] failed to get bklt gpio, rc=%d\n",
  1862. panel->name, rc);
  1863. rc = 0;
  1864. goto error;
  1865. }
  1866. }
  1867. error:
  1868. return rc;
  1869. }
  1870. static int dsi_panel_parse_phy_timing(struct dsi_display_mode *mode,
  1871. struct dsi_parser_utils *utils)
  1872. {
  1873. const char *data;
  1874. u32 len, i;
  1875. int rc = 0;
  1876. struct dsi_display_mode_priv_info *priv_info;
  1877. u64 pixel_clk_khz;
  1878. if (!mode || !mode->priv_info)
  1879. return -EINVAL;
  1880. priv_info = mode->priv_info;
  1881. data = utils->get_property(utils->data,
  1882. "qcom,mdss-dsi-panel-phy-timings", &len);
  1883. if (!data) {
  1884. DSI_DEBUG("Unable to read Phy timing settings\n");
  1885. } else {
  1886. priv_info->phy_timing_val =
  1887. kzalloc((sizeof(u32) * len), GFP_KERNEL);
  1888. if (!priv_info->phy_timing_val)
  1889. return -EINVAL;
  1890. for (i = 0; i < len; i++)
  1891. priv_info->phy_timing_val[i] = data[i];
  1892. priv_info->phy_timing_len = len;
  1893. }
  1894. if (mode->panel_mode == DSI_OP_VIDEO_MODE) {
  1895. /*
  1896. * For command mode we update the pclk as part of
  1897. * function dsi_panel_calc_dsi_transfer_time( )
  1898. * as we set it based on dsi clock or mdp transfer time.
  1899. */
  1900. pixel_clk_khz = (dsi_h_total_dce(&mode->timing) *
  1901. DSI_V_TOTAL(&mode->timing) *
  1902. mode->timing.refresh_rate);
  1903. do_div(pixel_clk_khz, 1000);
  1904. mode->pixel_clk_khz = pixel_clk_khz;
  1905. }
  1906. return rc;
  1907. }
  1908. static int dsi_panel_parse_dsc_params(struct dsi_display_mode *mode,
  1909. struct dsi_parser_utils *utils)
  1910. {
  1911. u32 data;
  1912. int rc = -EINVAL;
  1913. int intf_width;
  1914. const char *compression;
  1915. struct dsi_display_mode_priv_info *priv_info;
  1916. if (!mode || !mode->priv_info)
  1917. return -EINVAL;
  1918. priv_info = mode->priv_info;
  1919. priv_info->dsc_enabled = false;
  1920. compression = utils->get_property(utils->data,
  1921. "qcom,compression-mode", NULL);
  1922. if (compression && !strcmp(compression, "dsc"))
  1923. priv_info->dsc_enabled = true;
  1924. if (!priv_info->dsc_enabled) {
  1925. DSI_DEBUG("dsc compression is not enabled for the mode\n");
  1926. return 0;
  1927. }
  1928. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-version", &data);
  1929. if (rc) {
  1930. priv_info->dsc.config.dsc_version_major = 0x1;
  1931. priv_info->dsc.config.dsc_version_minor = 0x1;
  1932. rc = 0;
  1933. } else {
  1934. /* BITS[0..3] provides minor version and BITS[4..7] provide
  1935. * major version information
  1936. */
  1937. priv_info->dsc.config.dsc_version_major = (data >> 4) & 0x0F;
  1938. priv_info->dsc.config.dsc_version_minor = data & 0x0F;
  1939. if ((priv_info->dsc.config.dsc_version_major != 0x1) &&
  1940. ((priv_info->dsc.config.dsc_version_minor
  1941. != 0x1) ||
  1942. (priv_info->dsc.config.dsc_version_minor
  1943. != 0x2))) {
  1944. DSI_ERR("%s:unsupported major:%d minor:%d version\n",
  1945. __func__,
  1946. priv_info->dsc.config.dsc_version_major,
  1947. priv_info->dsc.config.dsc_version_minor
  1948. );
  1949. rc = -EINVAL;
  1950. goto error;
  1951. }
  1952. }
  1953. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-scr-version", &data);
  1954. if (rc) {
  1955. priv_info->dsc.scr_rev = 0x0;
  1956. rc = 0;
  1957. } else {
  1958. priv_info->dsc.scr_rev = data & 0xff;
  1959. /* only one scr rev supported */
  1960. if (priv_info->dsc.scr_rev > 0x1) {
  1961. DSI_ERR("%s: DSC scr version:%d not supported\n",
  1962. __func__, priv_info->dsc.scr_rev);
  1963. rc = -EINVAL;
  1964. goto error;
  1965. }
  1966. }
  1967. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-height", &data);
  1968. if (rc) {
  1969. DSI_ERR("failed to parse qcom,mdss-dsc-slice-height\n");
  1970. goto error;
  1971. }
  1972. priv_info->dsc.config.slice_height = data;
  1973. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-width", &data);
  1974. if (rc) {
  1975. DSI_ERR("failed to parse qcom,mdss-dsc-slice-width\n");
  1976. goto error;
  1977. }
  1978. priv_info->dsc.config.slice_width = data;
  1979. intf_width = mode->timing.h_active;
  1980. if (intf_width % priv_info->dsc.config.slice_width) {
  1981. DSI_ERR("invalid slice width for the intf width:%d slice width:%d\n",
  1982. intf_width, priv_info->dsc.config.slice_width);
  1983. rc = -EINVAL;
  1984. goto error;
  1985. }
  1986. priv_info->dsc.config.pic_width = mode->timing.h_active;
  1987. priv_info->dsc.config.pic_height = mode->timing.v_active;
  1988. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-slice-per-pkt", &data);
  1989. if (rc) {
  1990. DSI_ERR("failed to parse qcom,mdss-dsc-slice-per-pkt\n");
  1991. goto error;
  1992. } else if (!data || (data > 2)) {
  1993. DSI_ERR("invalid dsc slice-per-pkt:%d\n", data);
  1994. goto error;
  1995. }
  1996. priv_info->dsc.slice_per_pkt = data;
  1997. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-bit-per-component",
  1998. &data);
  1999. if (rc) {
  2000. DSI_ERR("failed to parse qcom,mdss-dsc-bit-per-component\n");
  2001. goto error;
  2002. }
  2003. priv_info->dsc.config.bits_per_component = data;
  2004. rc = utils->read_u32(utils->data, "qcom,mdss-pps-delay-ms", &data);
  2005. if (rc) {
  2006. DSI_DEBUG("pps-delay-ms not specified, defaulting to 0\n");
  2007. data = 0;
  2008. }
  2009. priv_info->dsc.pps_delay_ms = data;
  2010. rc = utils->read_u32(utils->data, "qcom,mdss-dsc-bit-per-pixel",
  2011. &data);
  2012. if (rc) {
  2013. DSI_ERR("failed to parse qcom,mdss-dsc-bit-per-pixel\n");
  2014. goto error;
  2015. }
  2016. priv_info->dsc.config.bits_per_pixel = data << 4;
  2017. rc = utils->read_u32(utils->data, "qcom,src-chroma-format",
  2018. &data);
  2019. if (rc) {
  2020. DSI_DEBUG("failed to parse qcom,src-chroma-format\n");
  2021. rc = 0;
  2022. data = MSM_CHROMA_444;
  2023. }
  2024. priv_info->dsc.chroma_format = data;
  2025. rc = utils->read_u32(utils->data, "qcom,src-color-space",
  2026. &data);
  2027. if (rc) {
  2028. DSI_DEBUG("failed to parse qcom,src-color-space\n");
  2029. rc = 0;
  2030. data = MSM_RGB;
  2031. }
  2032. priv_info->dsc.source_color_space = data;
  2033. priv_info->dsc.config.block_pred_enable = utils->read_bool(utils->data,
  2034. "qcom,mdss-dsc-block-prediction-enable");
  2035. priv_info->dsc.config.slice_count = DIV_ROUND_UP(intf_width,
  2036. priv_info->dsc.config.slice_width);
  2037. rc = sde_dsc_populate_dsc_config(&priv_info->dsc.config,
  2038. priv_info->dsc.scr_rev);
  2039. if (rc) {
  2040. DSI_DEBUG("failed populating dsc params \n");
  2041. rc = -EINVAL;
  2042. goto error;
  2043. }
  2044. rc = sde_dsc_populate_dsc_private_params(&priv_info->dsc, intf_width);
  2045. if (rc) {
  2046. DSI_DEBUG("failed populating other dsc params \n");
  2047. rc = -EINVAL;
  2048. goto error;
  2049. }
  2050. priv_info->pclk_scale.numer =
  2051. priv_info->dsc.config.bits_per_pixel >> 4;
  2052. priv_info->pclk_scale.denom = msm_get_src_bpc(
  2053. priv_info->dsc.chroma_format,
  2054. priv_info->dsc.config.bits_per_component);
  2055. mode->timing.dsc_enabled = true;
  2056. mode->timing.dsc = &priv_info->dsc;
  2057. mode->timing.pclk_scale = priv_info->pclk_scale;
  2058. error:
  2059. return rc;
  2060. }
  2061. static int dsi_panel_parse_vdc_params(struct dsi_display_mode *mode,
  2062. struct dsi_parser_utils *utils, int traffic_mode, int panel_mode)
  2063. {
  2064. u32 data;
  2065. int rc = -EINVAL;
  2066. const char *compression;
  2067. struct dsi_display_mode_priv_info *priv_info;
  2068. int intf_width;
  2069. if (!mode || !mode->priv_info)
  2070. return -EINVAL;
  2071. priv_info = mode->priv_info;
  2072. priv_info->vdc_enabled = false;
  2073. compression = utils->get_property(utils->data,
  2074. "qcom,compression-mode", NULL);
  2075. if (compression && !strcmp(compression, "vdc"))
  2076. priv_info->vdc_enabled = true;
  2077. if (!priv_info->vdc_enabled) {
  2078. DSI_DEBUG("vdc compression is not enabled for the mode\n");
  2079. return 0;
  2080. }
  2081. priv_info->vdc.panel_mode = panel_mode;
  2082. priv_info->vdc.traffic_mode = traffic_mode;
  2083. rc = utils->read_u32(utils->data, "qcom,vdc-version", &data);
  2084. if (rc) {
  2085. priv_info->vdc.version_major = 0x1;
  2086. priv_info->vdc.version_minor = 0x1;
  2087. priv_info->vdc.version_release = 0x0;
  2088. rc = 0;
  2089. } else {
  2090. /* BITS[0..3] provides minor version and BITS[4..7] provide
  2091. * major version information
  2092. */
  2093. priv_info->vdc.version_major = (data >> 4) & 0x0F;
  2094. priv_info->vdc.version_minor = data & 0x0F;
  2095. if ((priv_info->vdc.version_major != 0x1) &&
  2096. ((priv_info->vdc.version_minor
  2097. != 0x1))) {
  2098. DSI_ERR("%s:unsupported major:%d minor:%d version\n",
  2099. __func__,
  2100. priv_info->vdc.version_major,
  2101. priv_info->vdc.version_minor
  2102. );
  2103. rc = -EINVAL;
  2104. goto error;
  2105. }
  2106. }
  2107. rc = utils->read_u32(utils->data, "qcom,vdc-version-release", &data);
  2108. if (rc) {
  2109. priv_info->vdc.version_release = 0x0;
  2110. rc = 0;
  2111. } else {
  2112. priv_info->vdc.version_release = data & 0xff;
  2113. /* only one release version is supported */
  2114. if (priv_info->vdc.version_release != 0x0) {
  2115. DSI_ERR("unsupported vdc release version %d\n",
  2116. priv_info->vdc.version_release);
  2117. rc = -EINVAL;
  2118. goto error;
  2119. }
  2120. }
  2121. DSI_INFO("vdc major: 0x%x minor : 0x%x release : 0x%x\n",
  2122. priv_info->vdc.version_major,
  2123. priv_info->vdc.version_minor,
  2124. priv_info->vdc.version_release);
  2125. rc = utils->read_u32(utils->data, "qcom,vdc-slice-height", &data);
  2126. if (rc) {
  2127. DSI_ERR("failed to parse qcom,vdc-slice-height\n");
  2128. goto error;
  2129. }
  2130. priv_info->vdc.slice_height = data;
  2131. /* slice height should be atleast 16 lines */
  2132. if (priv_info->vdc.slice_height < 16) {
  2133. DSI_ERR("invalid slice height %d\n",
  2134. priv_info->vdc.slice_height);
  2135. rc = -EINVAL;
  2136. goto error;
  2137. }
  2138. rc = utils->read_u32(utils->data, "qcom,vdc-slice-width", &data);
  2139. if (rc) {
  2140. DSI_ERR("failed to parse qcom,vdc-slice-width\n");
  2141. goto error;
  2142. }
  2143. priv_info->vdc.slice_width = data;
  2144. /*
  2145. * slide-width should be multiple of 8
  2146. * slice-width should be atlease 64 pixels
  2147. */
  2148. if ((priv_info->vdc.slice_width & 7) ||
  2149. (priv_info->vdc.slice_width < 64)) {
  2150. DSI_ERR("invalid slice width:%d\n", priv_info->vdc.slice_width);
  2151. rc = -EINVAL;
  2152. goto error;
  2153. }
  2154. rc = utils->read_u32(utils->data, "qcom,vdc-slice-per-pkt", &data);
  2155. if (rc) {
  2156. DSI_ERR("failed to parse qcom,vdc-slice-per-pkt\n");
  2157. goto error;
  2158. } else if (!data || (data > 2)) {
  2159. DSI_ERR("invalid vdc slice-per-pkt:%d\n", data);
  2160. rc = -EINVAL;
  2161. goto error;
  2162. }
  2163. intf_width = mode->timing.h_active;
  2164. priv_info->vdc.slice_per_pkt = data;
  2165. priv_info->vdc.frame_width = mode->timing.h_active;
  2166. priv_info->vdc.frame_height = mode->timing.v_active;
  2167. rc = utils->read_u32(utils->data, "qcom,vdc-bit-per-component",
  2168. &data);
  2169. if (rc) {
  2170. DSI_ERR("failed to parse qcom,vdc-bit-per-component\n");
  2171. goto error;
  2172. }
  2173. priv_info->vdc.bits_per_component = data;
  2174. rc = utils->read_u32(utils->data, "qcom,mdss-pps-delay-ms", &data);
  2175. if (rc) {
  2176. DSI_DEBUG("pps-delay-ms not specified, defaulting to 0\n");
  2177. data = 0;
  2178. }
  2179. priv_info->vdc.pps_delay_ms = data;
  2180. rc = utils->read_u32(utils->data, "qcom,vdc-bit-per-pixel",
  2181. &data);
  2182. if (rc) {
  2183. DSI_ERR("failed to parse qcom,vdc-bit-per-pixel\n");
  2184. goto error;
  2185. }
  2186. priv_info->vdc.bits_per_pixel = data << 4;
  2187. rc = utils->read_u32(utils->data, "qcom,src-chroma-format",
  2188. &data);
  2189. if (rc) {
  2190. DSI_DEBUG("failed to parse qcom,src-chroma-format\n");
  2191. rc = 0;
  2192. data = MSM_CHROMA_444;
  2193. }
  2194. priv_info->vdc.chroma_format = data;
  2195. rc = utils->read_u32(utils->data, "qcom,src-color-space",
  2196. &data);
  2197. if (rc) {
  2198. DSI_DEBUG("failed to parse qcom,src-color-space\n");
  2199. rc = 0;
  2200. data = MSM_RGB;
  2201. }
  2202. priv_info->vdc.source_color_space = data;
  2203. rc = sde_vdc_populate_config(&priv_info->vdc,
  2204. intf_width, traffic_mode);
  2205. if (rc) {
  2206. DSI_DEBUG("failed populating vdc config\n");
  2207. rc = -EINVAL;
  2208. goto error;
  2209. }
  2210. priv_info->pclk_scale.numer =
  2211. priv_info->vdc.bits_per_pixel >> 4;
  2212. priv_info->pclk_scale.denom = msm_get_src_bpc(
  2213. priv_info->vdc.chroma_format,
  2214. priv_info->vdc.bits_per_component);
  2215. mode->timing.vdc_enabled = true;
  2216. mode->timing.vdc = &priv_info->vdc;
  2217. mode->timing.pclk_scale = priv_info->pclk_scale;
  2218. error:
  2219. return rc;
  2220. }
  2221. static int dsi_panel_parse_hdr_config(struct dsi_panel *panel)
  2222. {
  2223. int rc = 0;
  2224. struct drm_panel_hdr_properties *hdr_prop;
  2225. struct dsi_parser_utils *utils = &panel->utils;
  2226. hdr_prop = &panel->hdr_props;
  2227. hdr_prop->hdr_enabled = utils->read_bool(utils->data,
  2228. "qcom,mdss-dsi-panel-hdr-enabled");
  2229. if (hdr_prop->hdr_enabled) {
  2230. rc = utils->read_u32_array(utils->data,
  2231. "qcom,mdss-dsi-panel-hdr-color-primaries",
  2232. hdr_prop->display_primaries,
  2233. DISPLAY_PRIMARIES_MAX);
  2234. if (rc) {
  2235. DSI_ERR("%s:%d, Unable to read color primaries,rc:%u\n",
  2236. __func__, __LINE__, rc);
  2237. hdr_prop->hdr_enabled = false;
  2238. return rc;
  2239. }
  2240. rc = utils->read_u32(utils->data,
  2241. "qcom,mdss-dsi-panel-peak-brightness",
  2242. &(hdr_prop->peak_brightness));
  2243. if (rc) {
  2244. DSI_ERR("%s:%d, Unable to read hdr brightness, rc:%u\n",
  2245. __func__, __LINE__, rc);
  2246. hdr_prop->hdr_enabled = false;
  2247. return rc;
  2248. }
  2249. rc = utils->read_u32(utils->data,
  2250. "qcom,mdss-dsi-panel-blackness-level",
  2251. &(hdr_prop->blackness_level));
  2252. if (rc) {
  2253. DSI_ERR("%s:%d, Unable to read hdr brightness, rc:%u\n",
  2254. __func__, __LINE__, rc);
  2255. hdr_prop->hdr_enabled = false;
  2256. return rc;
  2257. }
  2258. }
  2259. return 0;
  2260. }
  2261. static int dsi_panel_parse_topology(
  2262. struct dsi_display_mode_priv_info *priv_info,
  2263. struct dsi_parser_utils *utils,
  2264. int topology_override)
  2265. {
  2266. struct msm_display_topology *topology;
  2267. u32 top_count, top_sel, *array = NULL;
  2268. int i, len = 0;
  2269. int rc = -EINVAL;
  2270. len = utils->count_u32_elems(utils->data, "qcom,display-topology");
  2271. if (len <= 0 || len % TOPOLOGY_SET_LEN ||
  2272. len > (TOPOLOGY_SET_LEN * MAX_TOPOLOGY)) {
  2273. DSI_ERR("invalid topology list for the panel, rc = %d\n", rc);
  2274. return rc;
  2275. }
  2276. top_count = len / TOPOLOGY_SET_LEN;
  2277. array = kcalloc(len, sizeof(u32), GFP_KERNEL);
  2278. if (!array)
  2279. return -ENOMEM;
  2280. rc = utils->read_u32_array(utils->data,
  2281. "qcom,display-topology", array, len);
  2282. if (rc) {
  2283. DSI_ERR("unable to read the display topologies, rc = %d\n", rc);
  2284. goto read_fail;
  2285. }
  2286. topology = kcalloc(top_count, sizeof(*topology), GFP_KERNEL);
  2287. if (!topology) {
  2288. rc = -ENOMEM;
  2289. goto read_fail;
  2290. }
  2291. for (i = 0; i < top_count; i++) {
  2292. struct msm_display_topology *top = &topology[i];
  2293. top->num_lm = array[i * TOPOLOGY_SET_LEN];
  2294. top->num_enc = array[i * TOPOLOGY_SET_LEN + 1];
  2295. top->num_intf = array[i * TOPOLOGY_SET_LEN + 2];
  2296. }
  2297. if (topology_override >= 0 && topology_override < top_count) {
  2298. DSI_INFO("override topology: cfg:%d lm:%d comp_enc:%d intf:%d\n",
  2299. topology_override,
  2300. topology[topology_override].num_lm,
  2301. topology[topology_override].num_enc,
  2302. topology[topology_override].num_intf);
  2303. top_sel = topology_override;
  2304. goto parse_done;
  2305. }
  2306. rc = utils->read_u32(utils->data,
  2307. "qcom,default-topology-index", &top_sel);
  2308. if (rc) {
  2309. DSI_ERR("no default topology selected, rc = %d\n", rc);
  2310. goto parse_fail;
  2311. }
  2312. if (top_sel >= top_count) {
  2313. rc = -EINVAL;
  2314. DSI_ERR("default topology is specified is not valid, rc = %d\n",
  2315. rc);
  2316. goto parse_fail;
  2317. }
  2318. DSI_INFO("default topology: lm: %d comp_enc:%d intf: %d\n",
  2319. topology[top_sel].num_lm,
  2320. topology[top_sel].num_enc,
  2321. topology[top_sel].num_intf);
  2322. parse_done:
  2323. memcpy(&priv_info->topology, &topology[top_sel],
  2324. sizeof(struct msm_display_topology));
  2325. parse_fail:
  2326. kfree(topology);
  2327. read_fail:
  2328. kfree(array);
  2329. return rc;
  2330. }
  2331. static int dsi_panel_parse_roi_alignment(struct dsi_parser_utils *utils,
  2332. struct msm_roi_alignment *align)
  2333. {
  2334. int len = 0, rc = 0;
  2335. u32 value[6];
  2336. struct property *data;
  2337. if (!align)
  2338. return -EINVAL;
  2339. memset(align, 0, sizeof(*align));
  2340. data = utils->find_property(utils->data,
  2341. "qcom,panel-roi-alignment", &len);
  2342. len /= sizeof(u32);
  2343. if (!data) {
  2344. DSI_ERR("panel roi alignment not found\n");
  2345. rc = -EINVAL;
  2346. } else if (len != 6) {
  2347. DSI_ERR("incorrect roi alignment len %d\n", len);
  2348. rc = -EINVAL;
  2349. } else {
  2350. rc = utils->read_u32_array(utils->data,
  2351. "qcom,panel-roi-alignment", value, len);
  2352. if (rc)
  2353. DSI_DEBUG("error reading panel roi alignment values\n");
  2354. else {
  2355. align->xstart_pix_align = value[0];
  2356. align->ystart_pix_align = value[1];
  2357. align->width_pix_align = value[2];
  2358. align->height_pix_align = value[3];
  2359. align->min_width = value[4];
  2360. align->min_height = value[5];
  2361. }
  2362. DSI_INFO("roi alignment: [%d, %d, %d, %d, %d, %d]\n",
  2363. align->xstart_pix_align,
  2364. align->width_pix_align,
  2365. align->ystart_pix_align,
  2366. align->height_pix_align,
  2367. align->min_width,
  2368. align->min_height);
  2369. }
  2370. return rc;
  2371. }
  2372. static int dsi_panel_parse_partial_update_caps(struct dsi_display_mode *mode,
  2373. struct dsi_parser_utils *utils)
  2374. {
  2375. struct msm_roi_caps *roi_caps = NULL;
  2376. const char *data;
  2377. int rc = 0;
  2378. if (!mode || !mode->priv_info) {
  2379. DSI_ERR("invalid arguments\n");
  2380. return -EINVAL;
  2381. }
  2382. roi_caps = &mode->priv_info->roi_caps;
  2383. memset(roi_caps, 0, sizeof(*roi_caps));
  2384. data = utils->get_property(utils->data,
  2385. "qcom,partial-update-enabled", NULL);
  2386. if (data) {
  2387. if (!strcmp(data, "dual_roi"))
  2388. roi_caps->num_roi = 2;
  2389. else if (!strcmp(data, "single_roi"))
  2390. roi_caps->num_roi = 1;
  2391. else {
  2392. DSI_INFO(
  2393. "invalid value for qcom,partial-update-enabled: %s\n",
  2394. data);
  2395. return 0;
  2396. }
  2397. } else {
  2398. DSI_DEBUG("partial update disabled as the property is not set\n");
  2399. return 0;
  2400. }
  2401. roi_caps->merge_rois = utils->read_bool(utils->data,
  2402. "qcom,partial-update-roi-merge");
  2403. roi_caps->enabled = roi_caps->num_roi > 0;
  2404. DSI_DEBUG("partial update num_rois=%d enabled=%d\n", roi_caps->num_roi,
  2405. roi_caps->enabled);
  2406. if (roi_caps->enabled)
  2407. rc = dsi_panel_parse_roi_alignment(utils,
  2408. &roi_caps->align);
  2409. if (rc)
  2410. memset(roi_caps, 0, sizeof(*roi_caps));
  2411. return rc;
  2412. }
  2413. static int dsi_panel_parse_panel_mode_caps(struct dsi_display_mode *mode,
  2414. struct dsi_parser_utils *utils)
  2415. {
  2416. bool vid_mode_support, cmd_mode_support;
  2417. if (!mode || !mode->priv_info) {
  2418. DSI_ERR("invalid arguments\n");
  2419. return -EINVAL;
  2420. }
  2421. vid_mode_support = utils->read_bool(utils->data,
  2422. "qcom,mdss-dsi-video-mode");
  2423. cmd_mode_support = utils->read_bool(utils->data,
  2424. "qcom,mdss-dsi-cmd-mode");
  2425. if (cmd_mode_support)
  2426. mode->panel_mode = DSI_OP_CMD_MODE;
  2427. else if (vid_mode_support)
  2428. mode->panel_mode = DSI_OP_VIDEO_MODE;
  2429. else
  2430. return -EINVAL;
  2431. return 0;
  2432. };
  2433. static int dsi_panel_parse_dms_info(struct dsi_panel *panel)
  2434. {
  2435. int dms_enabled;
  2436. const char *data;
  2437. struct dsi_parser_utils *utils = &panel->utils;
  2438. panel->dms_mode = DSI_DMS_MODE_DISABLED;
  2439. dms_enabled = utils->read_bool(utils->data,
  2440. "qcom,dynamic-mode-switch-enabled");
  2441. if (!dms_enabled)
  2442. return 0;
  2443. data = utils->get_property(utils->data,
  2444. "qcom,dynamic-mode-switch-type", NULL);
  2445. if (data && !strcmp(data, "dynamic-resolution-switch-immediate")) {
  2446. panel->dms_mode = DSI_DMS_MODE_RES_SWITCH_IMMEDIATE;
  2447. } else {
  2448. DSI_ERR("[%s] unsupported dynamic switch mode: %s\n",
  2449. panel->name, data);
  2450. return -EINVAL;
  2451. }
  2452. return 0;
  2453. };
  2454. /*
  2455. * The length of all the valid values to be checked should not be greater
  2456. * than the length of returned data from read command.
  2457. */
  2458. static bool
  2459. dsi_panel_parse_esd_check_valid_params(struct dsi_panel *panel, u32 count)
  2460. {
  2461. int i;
  2462. struct drm_panel_esd_config *config = &panel->esd_config;
  2463. for (i = 0; i < count; ++i) {
  2464. if (config->status_valid_params[i] >
  2465. config->status_cmds_rlen[i]) {
  2466. DSI_DEBUG("ignore valid params\n");
  2467. return false;
  2468. }
  2469. }
  2470. return true;
  2471. }
  2472. static bool dsi_panel_parse_esd_status_len(struct dsi_parser_utils *utils,
  2473. char *prop_key, u32 **target, u32 cmd_cnt)
  2474. {
  2475. int tmp;
  2476. if (!utils->find_property(utils->data, prop_key, &tmp))
  2477. return false;
  2478. tmp /= sizeof(u32);
  2479. if (tmp != cmd_cnt) {
  2480. DSI_ERR("request property(%d) do not match cmd count(%d)\n",
  2481. tmp, cmd_cnt);
  2482. return false;
  2483. }
  2484. *target = kcalloc(tmp, sizeof(u32), GFP_KERNEL);
  2485. if (IS_ERR_OR_NULL(*target)) {
  2486. DSI_ERR("Error allocating memory for property\n");
  2487. return false;
  2488. }
  2489. if (utils->read_u32_array(utils->data, prop_key, *target, tmp)) {
  2490. DSI_ERR("cannot get values from dts\n");
  2491. kfree(*target);
  2492. *target = NULL;
  2493. return false;
  2494. }
  2495. return true;
  2496. }
  2497. static void dsi_panel_esd_config_deinit(struct drm_panel_esd_config *esd_config)
  2498. {
  2499. kfree(esd_config->status_buf);
  2500. kfree(esd_config->return_buf);
  2501. kfree(esd_config->status_value);
  2502. kfree(esd_config->status_valid_params);
  2503. kfree(esd_config->status_cmds_rlen);
  2504. kfree(esd_config->status_cmd.cmds);
  2505. }
  2506. int dsi_panel_parse_esd_reg_read_configs(struct dsi_panel *panel)
  2507. {
  2508. struct drm_panel_esd_config *esd_config;
  2509. int rc = 0;
  2510. u32 tmp;
  2511. u32 i, status_len, *lenp;
  2512. struct property *data;
  2513. struct dsi_parser_utils *utils = &panel->utils;
  2514. if (!panel) {
  2515. DSI_ERR("Invalid Params\n");
  2516. return -EINVAL;
  2517. }
  2518. esd_config = &panel->esd_config;
  2519. if (!esd_config)
  2520. return -EINVAL;
  2521. dsi_panel_parse_cmd_sets_sub(&esd_config->status_cmd,
  2522. DSI_CMD_SET_PANEL_STATUS, utils);
  2523. if (!esd_config->status_cmd.count) {
  2524. DSI_ERR("panel status command parsing failed\n");
  2525. rc = -EINVAL;
  2526. goto error;
  2527. }
  2528. if (!dsi_panel_parse_esd_status_len(utils,
  2529. "qcom,mdss-dsi-panel-status-read-length",
  2530. &panel->esd_config.status_cmds_rlen,
  2531. esd_config->status_cmd.count)) {
  2532. DSI_ERR("Invalid status read length\n");
  2533. rc = -EINVAL;
  2534. goto error1;
  2535. }
  2536. if (dsi_panel_parse_esd_status_len(utils,
  2537. "qcom,mdss-dsi-panel-status-valid-params",
  2538. &panel->esd_config.status_valid_params,
  2539. esd_config->status_cmd.count)) {
  2540. if (!dsi_panel_parse_esd_check_valid_params(panel,
  2541. esd_config->status_cmd.count)) {
  2542. rc = -EINVAL;
  2543. goto error2;
  2544. }
  2545. }
  2546. status_len = 0;
  2547. lenp = esd_config->status_valid_params ?: esd_config->status_cmds_rlen;
  2548. for (i = 0; i < esd_config->status_cmd.count; ++i)
  2549. status_len += lenp[i];
  2550. if (!status_len) {
  2551. rc = -EINVAL;
  2552. goto error2;
  2553. }
  2554. /*
  2555. * Some panel may need multiple read commands to properly
  2556. * check panel status. Do a sanity check for proper status
  2557. * value which will be compared with the value read by dsi
  2558. * controller during ESD check. Also check if multiple read
  2559. * commands are there then, there should be corresponding
  2560. * status check values for each read command.
  2561. */
  2562. data = utils->find_property(utils->data,
  2563. "qcom,mdss-dsi-panel-status-value", &tmp);
  2564. tmp /= sizeof(u32);
  2565. if (!IS_ERR_OR_NULL(data) && tmp != 0 && (tmp % status_len) == 0) {
  2566. esd_config->groups = tmp / status_len;
  2567. } else {
  2568. DSI_ERR("error parse panel-status-value\n");
  2569. rc = -EINVAL;
  2570. goto error2;
  2571. }
  2572. esd_config->status_value =
  2573. kzalloc(sizeof(u32) * status_len * esd_config->groups,
  2574. GFP_KERNEL);
  2575. if (!esd_config->status_value) {
  2576. rc = -ENOMEM;
  2577. goto error2;
  2578. }
  2579. esd_config->return_buf = kcalloc(status_len * esd_config->groups,
  2580. sizeof(unsigned char), GFP_KERNEL);
  2581. if (!esd_config->return_buf) {
  2582. rc = -ENOMEM;
  2583. goto error3;
  2584. }
  2585. esd_config->status_buf = kzalloc(SZ_4K, GFP_KERNEL);
  2586. if (!esd_config->status_buf) {
  2587. rc = -ENOMEM;
  2588. goto error4;
  2589. }
  2590. rc = utils->read_u32_array(utils->data,
  2591. "qcom,mdss-dsi-panel-status-value",
  2592. esd_config->status_value, esd_config->groups * status_len);
  2593. if (rc) {
  2594. DSI_DEBUG("error reading panel status values\n");
  2595. memset(esd_config->status_value, 0,
  2596. esd_config->groups * status_len);
  2597. }
  2598. return 0;
  2599. error4:
  2600. kfree(esd_config->return_buf);
  2601. error3:
  2602. kfree(esd_config->status_value);
  2603. error2:
  2604. kfree(esd_config->status_valid_params);
  2605. kfree(esd_config->status_cmds_rlen);
  2606. error1:
  2607. kfree(esd_config->status_cmd.cmds);
  2608. error:
  2609. return rc;
  2610. }
  2611. static int dsi_panel_parse_esd_config(struct dsi_panel *panel)
  2612. {
  2613. int rc = 0;
  2614. const char *string;
  2615. struct drm_panel_esd_config *esd_config;
  2616. struct dsi_parser_utils *utils = &panel->utils;
  2617. u8 *esd_mode = NULL;
  2618. esd_config = &panel->esd_config;
  2619. esd_config->status_mode = ESD_MODE_MAX;
  2620. esd_config->esd_enabled = utils->read_bool(utils->data,
  2621. "qcom,esd-check-enabled");
  2622. if (!esd_config->esd_enabled)
  2623. return 0;
  2624. rc = utils->read_string(utils->data,
  2625. "qcom,mdss-dsi-panel-status-check-mode", &string);
  2626. if (!rc) {
  2627. if (!strcmp(string, "bta_check")) {
  2628. esd_config->status_mode = ESD_MODE_SW_BTA;
  2629. } else if (!strcmp(string, "reg_read")) {
  2630. esd_config->status_mode = ESD_MODE_REG_READ;
  2631. } else if (!strcmp(string, "te_signal_check")) {
  2632. if (panel->panel_mode == DSI_OP_CMD_MODE) {
  2633. esd_config->status_mode = ESD_MODE_PANEL_TE;
  2634. } else {
  2635. DSI_ERR("TE-ESD not valid for video mode\n");
  2636. rc = -EINVAL;
  2637. goto error;
  2638. }
  2639. } else {
  2640. DSI_ERR("No valid panel-status-check-mode string\n");
  2641. rc = -EINVAL;
  2642. goto error;
  2643. }
  2644. } else {
  2645. DSI_DEBUG("status check method not defined!\n");
  2646. rc = -EINVAL;
  2647. goto error;
  2648. }
  2649. if (panel->esd_config.status_mode == ESD_MODE_REG_READ) {
  2650. rc = dsi_panel_parse_esd_reg_read_configs(panel);
  2651. if (rc) {
  2652. DSI_ERR("failed to parse esd reg read mode params, rc=%d\n",
  2653. rc);
  2654. goto error;
  2655. }
  2656. esd_mode = "register_read";
  2657. } else if (panel->esd_config.status_mode == ESD_MODE_SW_BTA) {
  2658. esd_mode = "bta_trigger";
  2659. } else if (panel->esd_config.status_mode == ESD_MODE_PANEL_TE) {
  2660. esd_mode = "te_check";
  2661. }
  2662. DSI_DEBUG("ESD enabled with mode: %s\n", esd_mode);
  2663. return 0;
  2664. error:
  2665. panel->esd_config.esd_enabled = false;
  2666. return rc;
  2667. }
  2668. static void dsi_panel_update_util(struct dsi_panel *panel,
  2669. struct device_node *parser_node)
  2670. {
  2671. struct dsi_parser_utils *utils = &panel->utils;
  2672. if (parser_node) {
  2673. *utils = *dsi_parser_get_parser_utils();
  2674. utils->data = parser_node;
  2675. DSI_DEBUG("switching to parser APIs\n");
  2676. goto end;
  2677. }
  2678. *utils = *dsi_parser_get_of_utils();
  2679. utils->data = panel->panel_of_node;
  2680. end:
  2681. utils->node = panel->panel_of_node;
  2682. }
  2683. struct dsi_panel *dsi_panel_get(struct device *parent,
  2684. struct device_node *of_node,
  2685. struct device_node *parser_node,
  2686. const char *type,
  2687. int topology_override)
  2688. {
  2689. struct dsi_panel *panel;
  2690. struct dsi_parser_utils *utils;
  2691. const char *panel_physical_type;
  2692. int rc = 0;
  2693. panel = kzalloc(sizeof(*panel), GFP_KERNEL);
  2694. if (!panel)
  2695. return ERR_PTR(-ENOMEM);
  2696. panel->panel_of_node = of_node;
  2697. panel->parent = parent;
  2698. panel->type = type;
  2699. dsi_panel_update_util(panel, parser_node);
  2700. utils = &panel->utils;
  2701. panel->name = utils->get_property(utils->data,
  2702. "qcom,mdss-dsi-panel-name", NULL);
  2703. if (!panel->name)
  2704. panel->name = DSI_PANEL_DEFAULT_LABEL;
  2705. /*
  2706. * Set panel type to LCD as default.
  2707. */
  2708. panel->panel_type = DSI_DISPLAY_PANEL_TYPE_LCD;
  2709. panel_physical_type = utils->get_property(utils->data,
  2710. "qcom,mdss-dsi-panel-physical-type", NULL);
  2711. if (panel_physical_type && !strcmp(panel_physical_type, "oled"))
  2712. panel->panel_type = DSI_DISPLAY_PANEL_TYPE_OLED;
  2713. rc = dsi_panel_parse_host_config(panel);
  2714. if (rc) {
  2715. DSI_ERR("failed to parse host configuration, rc=%d\n",
  2716. rc);
  2717. goto error;
  2718. }
  2719. rc = dsi_panel_parse_panel_mode(panel);
  2720. if (rc) {
  2721. DSI_ERR("failed to parse panel mode configuration, rc=%d\n",
  2722. rc);
  2723. goto error;
  2724. }
  2725. rc = dsi_panel_parse_dfps_caps(panel);
  2726. if (rc)
  2727. DSI_ERR("failed to parse dfps configuration, rc=%d\n", rc);
  2728. rc = dsi_panel_parse_qsync_caps(panel, of_node);
  2729. if (rc)
  2730. DSI_DEBUG("failed to parse qsync features, rc=%d\n", rc);
  2731. /* allow qsync support only if DFPS is with VFP approach */
  2732. if ((panel->dfps_caps.dfps_support) &&
  2733. !(panel->dfps_caps.type == DSI_DFPS_IMMEDIATE_VFP))
  2734. panel->qsync_min_fps = 0;
  2735. rc = dsi_panel_parse_dyn_clk_caps(panel);
  2736. if (rc)
  2737. DSI_ERR("failed to parse dynamic clk config, rc=%d\n", rc);
  2738. rc = dsi_panel_parse_phy_props(panel);
  2739. if (rc) {
  2740. DSI_ERR("failed to parse panel physical dimension, rc=%d\n",
  2741. rc);
  2742. goto error;
  2743. }
  2744. rc = dsi_panel_parse_gpios(panel);
  2745. if (rc) {
  2746. DSI_ERR("failed to parse panel gpios, rc=%d\n", rc);
  2747. goto error;
  2748. }
  2749. rc = dsi_panel_parse_power_cfg(panel);
  2750. if (rc)
  2751. DSI_ERR("failed to parse power config, rc=%d\n", rc);
  2752. rc = dsi_panel_parse_bl_config(panel);
  2753. if (rc) {
  2754. DSI_ERR("failed to parse backlight config, rc=%d\n", rc);
  2755. if (rc == -EPROBE_DEFER)
  2756. goto error;
  2757. }
  2758. rc = dsi_panel_parse_misc_features(panel);
  2759. if (rc)
  2760. DSI_ERR("failed to parse misc features, rc=%d\n", rc);
  2761. rc = dsi_panel_parse_hdr_config(panel);
  2762. if (rc)
  2763. DSI_ERR("failed to parse hdr config, rc=%d\n", rc);
  2764. rc = dsi_panel_get_mode_count(panel);
  2765. if (rc) {
  2766. DSI_ERR("failed to get mode count, rc=%d\n", rc);
  2767. goto error;
  2768. }
  2769. rc = dsi_panel_parse_dms_info(panel);
  2770. if (rc)
  2771. DSI_DEBUG("failed to get dms info, rc=%d\n", rc);
  2772. rc = dsi_panel_parse_esd_config(panel);
  2773. if (rc)
  2774. DSI_DEBUG("failed to parse esd config, rc=%d\n", rc);
  2775. panel->power_mode = SDE_MODE_DPMS_OFF;
  2776. drm_panel_init(&panel->drm_panel);
  2777. panel->drm_panel.dev = &panel->mipi_device.dev;
  2778. panel->mipi_device.dev.of_node = of_node;
  2779. rc = drm_panel_add(&panel->drm_panel);
  2780. if (rc)
  2781. goto error;
  2782. mutex_init(&panel->panel_lock);
  2783. return panel;
  2784. error:
  2785. kfree(panel);
  2786. return ERR_PTR(rc);
  2787. }
  2788. void dsi_panel_put(struct dsi_panel *panel)
  2789. {
  2790. drm_panel_remove(&panel->drm_panel);
  2791. /* free resources allocated for ESD check */
  2792. dsi_panel_esd_config_deinit(&panel->esd_config);
  2793. kfree(panel);
  2794. }
  2795. int dsi_panel_drv_init(struct dsi_panel *panel,
  2796. struct mipi_dsi_host *host)
  2797. {
  2798. int rc = 0;
  2799. struct mipi_dsi_device *dev;
  2800. if (!panel || !host) {
  2801. DSI_ERR("invalid params\n");
  2802. return -EINVAL;
  2803. }
  2804. mutex_lock(&panel->panel_lock);
  2805. dev = &panel->mipi_device;
  2806. dev->host = host;
  2807. /*
  2808. * We dont have device structure since panel is not a device node.
  2809. * When using drm panel framework, the device is probed when the host is
  2810. * create.
  2811. */
  2812. dev->channel = 0;
  2813. dev->lanes = 4;
  2814. panel->host = host;
  2815. rc = dsi_panel_vreg_get(panel);
  2816. if (rc) {
  2817. DSI_ERR("[%s] failed to get panel regulators, rc=%d\n",
  2818. panel->name, rc);
  2819. goto exit;
  2820. }
  2821. rc = dsi_panel_pinctrl_init(panel);
  2822. if (rc) {
  2823. DSI_ERR("[%s] failed to init pinctrl, rc=%d\n",
  2824. panel->name, rc);
  2825. goto error_vreg_put;
  2826. }
  2827. rc = dsi_panel_gpio_request(panel);
  2828. if (rc) {
  2829. DSI_ERR("[%s] failed to request gpios, rc=%d\n", panel->name,
  2830. rc);
  2831. goto error_pinctrl_deinit;
  2832. }
  2833. rc = dsi_panel_bl_register(panel);
  2834. if (rc) {
  2835. if (rc != -EPROBE_DEFER)
  2836. DSI_ERR("[%s] failed to register backlight, rc=%d\n",
  2837. panel->name, rc);
  2838. goto error_gpio_release;
  2839. }
  2840. goto exit;
  2841. error_gpio_release:
  2842. (void)dsi_panel_gpio_release(panel);
  2843. error_pinctrl_deinit:
  2844. (void)dsi_panel_pinctrl_deinit(panel);
  2845. error_vreg_put:
  2846. (void)dsi_panel_vreg_put(panel);
  2847. exit:
  2848. mutex_unlock(&panel->panel_lock);
  2849. return rc;
  2850. }
  2851. int dsi_panel_drv_deinit(struct dsi_panel *panel)
  2852. {
  2853. int rc = 0;
  2854. if (!panel) {
  2855. DSI_ERR("invalid params\n");
  2856. return -EINVAL;
  2857. }
  2858. mutex_lock(&panel->panel_lock);
  2859. rc = dsi_panel_bl_unregister(panel);
  2860. if (rc)
  2861. DSI_ERR("[%s] failed to unregister backlight, rc=%d\n",
  2862. panel->name, rc);
  2863. rc = dsi_panel_gpio_release(panel);
  2864. if (rc)
  2865. DSI_ERR("[%s] failed to release gpios, rc=%d\n", panel->name,
  2866. rc);
  2867. rc = dsi_panel_pinctrl_deinit(panel);
  2868. if (rc)
  2869. DSI_ERR("[%s] failed to deinit gpios, rc=%d\n", panel->name,
  2870. rc);
  2871. rc = dsi_panel_vreg_put(panel);
  2872. if (rc)
  2873. DSI_ERR("[%s] failed to put regs, rc=%d\n", panel->name, rc);
  2874. panel->host = NULL;
  2875. memset(&panel->mipi_device, 0x0, sizeof(panel->mipi_device));
  2876. mutex_unlock(&panel->panel_lock);
  2877. return rc;
  2878. }
  2879. int dsi_panel_validate_mode(struct dsi_panel *panel,
  2880. struct dsi_display_mode *mode)
  2881. {
  2882. return 0;
  2883. }
  2884. int dsi_panel_get_mode_count(struct dsi_panel *panel)
  2885. {
  2886. const u32 SINGLE_MODE_SUPPORT = 1;
  2887. struct dsi_parser_utils *utils;
  2888. struct device_node *timings_np, *child_np;
  2889. int num_dfps_rates, num_bit_clks;
  2890. int num_video_modes = 0, num_cmd_modes = 0;
  2891. int count, rc = 0;
  2892. void *utils_data = NULL;
  2893. if (!panel) {
  2894. DSI_ERR("invalid params\n");
  2895. return -EINVAL;
  2896. }
  2897. utils = &panel->utils;
  2898. panel->num_timing_nodes = 0;
  2899. timings_np = utils->get_child_by_name(utils->data,
  2900. "qcom,mdss-dsi-display-timings");
  2901. if (!timings_np && !panel->host_config.ext_bridge_mode) {
  2902. DSI_ERR("no display timing nodes defined\n");
  2903. rc = -EINVAL;
  2904. goto error;
  2905. }
  2906. count = utils->get_child_count(timings_np);
  2907. if ((!count && !panel->host_config.ext_bridge_mode) ||
  2908. count > DSI_MODE_MAX) {
  2909. DSI_ERR("invalid count of timing nodes: %d\n", count);
  2910. rc = -EINVAL;
  2911. goto error;
  2912. }
  2913. /* No multiresolution support is available for video mode panels.
  2914. * Multi-mode is supported for video mode during POMS is enabled.
  2915. */
  2916. if (panel->panel_mode != DSI_OP_CMD_MODE &&
  2917. !panel->host_config.ext_bridge_mode &&
  2918. !panel->panel_mode_switch_enabled)
  2919. count = SINGLE_MODE_SUPPORT;
  2920. panel->num_timing_nodes = count;
  2921. dsi_for_each_child_node(timings_np, child_np) {
  2922. utils_data = child_np;
  2923. if (utils->read_bool(utils->data, "qcom,mdss-dsi-video-mode"))
  2924. num_video_modes++;
  2925. else if (utils->read_bool(utils->data,
  2926. "qcom,mdss-dsi-cmd-mode"))
  2927. num_cmd_modes++;
  2928. else if (panel->panel_mode == DSI_OP_VIDEO_MODE)
  2929. num_video_modes++;
  2930. else if (panel->panel_mode == DSI_OP_CMD_MODE)
  2931. num_cmd_modes++;
  2932. }
  2933. num_dfps_rates = !panel->dfps_caps.dfps_support ? 1 :
  2934. panel->dfps_caps.dfps_list_len;
  2935. num_bit_clks = !panel->dyn_clk_caps.dyn_clk_support ? 1 :
  2936. panel->dyn_clk_caps.bit_clk_list_len;
  2937. /* Inflate num_of_modes by fps and bit clks in dfps */
  2938. panel->num_display_modes = (num_cmd_modes * num_bit_clks) +
  2939. (num_video_modes * num_bit_clks * num_dfps_rates);
  2940. error:
  2941. return rc;
  2942. }
  2943. int dsi_panel_get_phy_props(struct dsi_panel *panel,
  2944. struct dsi_panel_phy_props *phy_props)
  2945. {
  2946. int rc = 0;
  2947. if (!panel || !phy_props) {
  2948. DSI_ERR("invalid params\n");
  2949. return -EINVAL;
  2950. }
  2951. memcpy(phy_props, &panel->phy_props, sizeof(*phy_props));
  2952. return rc;
  2953. }
  2954. int dsi_panel_get_dfps_caps(struct dsi_panel *panel,
  2955. struct dsi_dfps_capabilities *dfps_caps)
  2956. {
  2957. int rc = 0;
  2958. if (!panel || !dfps_caps) {
  2959. DSI_ERR("invalid params\n");
  2960. return -EINVAL;
  2961. }
  2962. memcpy(dfps_caps, &panel->dfps_caps, sizeof(*dfps_caps));
  2963. return rc;
  2964. }
  2965. void dsi_panel_put_mode(struct dsi_display_mode *mode)
  2966. {
  2967. int i;
  2968. if (!mode->priv_info)
  2969. return;
  2970. for (i = 0; i < DSI_CMD_SET_MAX; i++) {
  2971. dsi_panel_destroy_cmd_packets(&mode->priv_info->cmd_sets[i]);
  2972. dsi_panel_dealloc_cmd_packets(&mode->priv_info->cmd_sets[i]);
  2973. }
  2974. kfree(mode->priv_info);
  2975. }
  2976. void dsi_panel_calc_dsi_transfer_time(struct dsi_host_common_cfg *config,
  2977. struct dsi_display_mode *mode, u32 frame_threshold_us)
  2978. {
  2979. u32 frame_time_us,nslices;
  2980. u64 min_bitclk_hz, total_active_pixels, bits_per_line, pclk_rate_hz,
  2981. dsi_transfer_time_us, pixel_clk_khz;
  2982. struct msm_display_dsc_info *dsc = mode->timing.dsc;
  2983. struct dsi_mode_info *timing = &mode->timing;
  2984. struct dsi_display_mode *display_mode;
  2985. u32 jitter_numer, jitter_denom, prefill_lines;
  2986. u32 min_threshold_us, prefill_time_us;
  2987. u16 bpp;
  2988. /* Packet overlead in bits,2 bytes header + 2 bytes checksum
  2989. * + 1 byte dcs data command.
  2990. */
  2991. const u32 packet_overhead = 56;
  2992. display_mode = container_of(timing, struct dsi_display_mode, timing);
  2993. jitter_numer = display_mode->priv_info->panel_jitter_numer;
  2994. jitter_denom = display_mode->priv_info->panel_jitter_denom;
  2995. frame_time_us = mult_frac(1000, 1000, (timing->refresh_rate));
  2996. if (timing->dsc_enabled) {
  2997. nslices = (timing->h_active)/(dsc->config.slice_width);
  2998. /* (slice width x bit-per-pixel + packet overhead) x
  2999. * number of slices x height x fps / lane
  3000. */
  3001. bpp = DSC_BPP(dsc->config);
  3002. bits_per_line = ((dsc->config.slice_width * bpp) +
  3003. packet_overhead) * nslices;
  3004. bits_per_line = bits_per_line / (config->num_data_lanes);
  3005. min_bitclk_hz = (bits_per_line * timing->v_active *
  3006. timing->refresh_rate);
  3007. } else {
  3008. total_active_pixels = ((dsi_h_active_dce(timing)
  3009. * timing->v_active));
  3010. /* calculate the actual bitclk needed to transfer the frame */
  3011. min_bitclk_hz = (total_active_pixels * (timing->refresh_rate) *
  3012. (config->bpp));
  3013. do_div(min_bitclk_hz, config->num_data_lanes);
  3014. }
  3015. timing->min_dsi_clk_hz = min_bitclk_hz;
  3016. if (timing->clk_rate_hz) {
  3017. /* adjust the transfer time proportionately for bit clk*/
  3018. dsi_transfer_time_us = frame_time_us * min_bitclk_hz;
  3019. do_div(dsi_transfer_time_us, timing->clk_rate_hz);
  3020. timing->dsi_transfer_time_us = dsi_transfer_time_us;
  3021. } else if (mode->priv_info->mdp_transfer_time_us) {
  3022. timing->dsi_transfer_time_us =
  3023. mode->priv_info->mdp_transfer_time_us;
  3024. } else {
  3025. min_threshold_us = mult_frac(frame_time_us,
  3026. jitter_numer, (jitter_denom * 100));
  3027. /*
  3028. * Increase the prefill_lines proportionately as recommended
  3029. * 35lines for 60fps, 52 for 90fps, 70lines for 120fps.
  3030. */
  3031. prefill_lines = mult_frac(MIN_PREFILL_LINES,
  3032. timing->refresh_rate, 60);
  3033. prefill_time_us = mult_frac(frame_time_us, prefill_lines,
  3034. (timing->v_active));
  3035. /*
  3036. * Threshold is sum of panel jitter time, prefill line time
  3037. * plus 100usec buffer time.
  3038. */
  3039. min_threshold_us = min_threshold_us + 100 + prefill_time_us;
  3040. DSI_DEBUG("min threshold time=%d\n", min_threshold_us);
  3041. if (min_threshold_us > frame_threshold_us)
  3042. frame_threshold_us = min_threshold_us;
  3043. timing->dsi_transfer_time_us = frame_time_us -
  3044. frame_threshold_us;
  3045. }
  3046. timing->mdp_transfer_time_us = timing->dsi_transfer_time_us;
  3047. /* Force update mdp xfer time to hal,if clk and mdp xfer time is set */
  3048. if (mode->priv_info->mdp_transfer_time_us && timing->clk_rate_hz) {
  3049. timing->mdp_transfer_time_us =
  3050. mode->priv_info->mdp_transfer_time_us;
  3051. }
  3052. /* Calculate pclk_khz to update modeinfo */
  3053. pclk_rate_hz = min_bitclk_hz * frame_time_us;
  3054. do_div(pclk_rate_hz, timing->dsi_transfer_time_us);
  3055. pixel_clk_khz = pclk_rate_hz * config->num_data_lanes;
  3056. do_div(pixel_clk_khz, config->bpp);
  3057. display_mode->pixel_clk_khz = pixel_clk_khz;
  3058. display_mode->pixel_clk_khz = display_mode->pixel_clk_khz / 1000;
  3059. }
  3060. int dsi_panel_get_mode(struct dsi_panel *panel,
  3061. u32 index, struct dsi_display_mode *mode,
  3062. int topology_override)
  3063. {
  3064. struct device_node *timings_np, *child_np;
  3065. struct dsi_parser_utils *utils;
  3066. struct dsi_display_mode_priv_info *prv_info;
  3067. u32 child_idx = 0;
  3068. int rc = 0, num_timings;
  3069. int traffic_mode;
  3070. int panel_mode;
  3071. void *utils_data = NULL;
  3072. if (!panel || !mode) {
  3073. DSI_ERR("invalid params\n");
  3074. return -EINVAL;
  3075. }
  3076. mutex_lock(&panel->panel_lock);
  3077. utils = &panel->utils;
  3078. mode->priv_info = kzalloc(sizeof(*mode->priv_info), GFP_KERNEL);
  3079. if (!mode->priv_info) {
  3080. rc = -ENOMEM;
  3081. goto done;
  3082. }
  3083. prv_info = mode->priv_info;
  3084. timings_np = utils->get_child_by_name(utils->data,
  3085. "qcom,mdss-dsi-display-timings");
  3086. if (!timings_np) {
  3087. DSI_ERR("no display timing nodes defined\n");
  3088. rc = -EINVAL;
  3089. goto parse_fail;
  3090. }
  3091. num_timings = utils->get_child_count(timings_np);
  3092. if (!num_timings || num_timings > DSI_MODE_MAX) {
  3093. DSI_ERR("invalid count of timing nodes: %d\n", num_timings);
  3094. rc = -EINVAL;
  3095. goto parse_fail;
  3096. }
  3097. utils_data = utils->data;
  3098. traffic_mode = panel->video_config.traffic_mode;
  3099. panel_mode = panel->panel_mode;
  3100. dsi_for_each_child_node(timings_np, child_np) {
  3101. if (index != child_idx++)
  3102. continue;
  3103. utils->data = child_np;
  3104. rc = dsi_panel_parse_timing(&mode->timing, utils);
  3105. if (rc) {
  3106. DSI_ERR("failed to parse panel timing, rc=%d\n", rc);
  3107. goto parse_fail;
  3108. }
  3109. rc = dsi_panel_parse_dsc_params(mode, utils);
  3110. if (rc) {
  3111. DSI_ERR("failed to parse dsc params, rc=%d\n", rc);
  3112. goto parse_fail;
  3113. }
  3114. rc = dsi_panel_parse_vdc_params(mode, utils, traffic_mode,
  3115. panel_mode);
  3116. if (rc) {
  3117. DSI_ERR("failed to parse vdc params, rc=%d\n", rc);
  3118. goto parse_fail;
  3119. }
  3120. rc = dsi_panel_parse_topology(prv_info, utils,
  3121. topology_override);
  3122. if (rc) {
  3123. DSI_ERR("failed to parse panel topology, rc=%d\n", rc);
  3124. goto parse_fail;
  3125. }
  3126. rc = dsi_panel_parse_cmd_sets(prv_info, utils);
  3127. if (rc) {
  3128. DSI_ERR("failed to parse command sets, rc=%d\n", rc);
  3129. goto parse_fail;
  3130. }
  3131. rc = dsi_panel_parse_jitter_config(mode, utils);
  3132. if (rc)
  3133. DSI_ERR(
  3134. "failed to parse panel jitter config, rc=%d\n", rc);
  3135. rc = dsi_panel_parse_phy_timing(mode, utils);
  3136. if (rc) {
  3137. DSI_ERR(
  3138. "failed to parse panel phy timings, rc=%d\n", rc);
  3139. goto parse_fail;
  3140. }
  3141. rc = dsi_panel_parse_partial_update_caps(mode, utils);
  3142. if (rc)
  3143. DSI_ERR("failed to partial update caps, rc=%d\n", rc);
  3144. if (panel->panel_mode_switch_enabled) {
  3145. rc = dsi_panel_parse_panel_mode_caps(mode, utils);
  3146. if (rc) {
  3147. rc = 0;
  3148. mode->panel_mode = panel->panel_mode;
  3149. DSI_INFO(
  3150. "POMS: panel mode isn't specified in timing[%d]\n",
  3151. child_idx);
  3152. }
  3153. } else {
  3154. mode->panel_mode = panel->panel_mode;
  3155. }
  3156. }
  3157. goto done;
  3158. parse_fail:
  3159. kfree(mode->priv_info);
  3160. mode->priv_info = NULL;
  3161. done:
  3162. utils->data = utils_data;
  3163. mutex_unlock(&panel->panel_lock);
  3164. return rc;
  3165. }
  3166. int dsi_panel_get_host_cfg_for_mode(struct dsi_panel *panel,
  3167. struct dsi_display_mode *mode,
  3168. struct dsi_host_config *config)
  3169. {
  3170. int rc = 0;
  3171. struct dsi_dyn_clk_caps *dyn_clk_caps = &panel->dyn_clk_caps;
  3172. if (!panel || !mode || !config) {
  3173. DSI_ERR("invalid params\n");
  3174. return -EINVAL;
  3175. }
  3176. mutex_lock(&panel->panel_lock);
  3177. config->panel_mode = panel->panel_mode;
  3178. memcpy(&config->common_config, &panel->host_config,
  3179. sizeof(config->common_config));
  3180. if (panel->panel_mode == DSI_OP_VIDEO_MODE) {
  3181. memcpy(&config->u.video_engine, &panel->video_config,
  3182. sizeof(config->u.video_engine));
  3183. } else {
  3184. memcpy(&config->u.cmd_engine, &panel->cmd_config,
  3185. sizeof(config->u.cmd_engine));
  3186. }
  3187. memcpy(&config->video_timing, &mode->timing,
  3188. sizeof(config->video_timing));
  3189. config->video_timing.mdp_transfer_time_us =
  3190. mode->priv_info->mdp_transfer_time_us;
  3191. config->video_timing.dsc_enabled = mode->priv_info->dsc_enabled;
  3192. config->video_timing.dsc = &mode->priv_info->dsc;
  3193. config->video_timing.vdc_enabled = mode->priv_info->vdc_enabled;
  3194. config->video_timing.vdc = &mode->priv_info->vdc;
  3195. if (dyn_clk_caps->dyn_clk_support)
  3196. config->bit_clk_rate_hz_override = mode->timing.clk_rate_hz;
  3197. else
  3198. config->bit_clk_rate_hz_override = mode->priv_info->clk_rate_hz;
  3199. config->esc_clk_rate_hz = 19200000;
  3200. mutex_unlock(&panel->panel_lock);
  3201. return rc;
  3202. }
  3203. int dsi_panel_pre_prepare(struct dsi_panel *panel)
  3204. {
  3205. int rc = 0;
  3206. if (!panel) {
  3207. DSI_ERR("invalid params\n");
  3208. return -EINVAL;
  3209. }
  3210. mutex_lock(&panel->panel_lock);
  3211. /* If LP11_INIT is set, panel will be powered up during prepare() */
  3212. if (panel->lp11_init)
  3213. goto error;
  3214. rc = dsi_panel_power_on(panel);
  3215. if (rc) {
  3216. DSI_ERR("[%s] panel power on failed, rc=%d\n", panel->name, rc);
  3217. goto error;
  3218. }
  3219. error:
  3220. mutex_unlock(&panel->panel_lock);
  3221. return rc;
  3222. }
  3223. int dsi_panel_update_pps(struct dsi_panel *panel)
  3224. {
  3225. int rc = 0;
  3226. struct dsi_panel_cmd_set *set = NULL;
  3227. struct dsi_display_mode_priv_info *priv_info = NULL;
  3228. if (!panel || !panel->cur_mode) {
  3229. DSI_ERR("invalid params\n");
  3230. return -EINVAL;
  3231. }
  3232. mutex_lock(&panel->panel_lock);
  3233. priv_info = panel->cur_mode->priv_info;
  3234. set = &priv_info->cmd_sets[DSI_CMD_SET_PPS];
  3235. if (priv_info->dsc_enabled)
  3236. dsi_dsc_create_pps_buf_cmd(&priv_info->dsc,
  3237. panel->dce_pps_cmd, 0,
  3238. DSI_CMD_PPS_SIZE - DSI_CMD_PPS_HDR_SIZE);
  3239. else if (priv_info->vdc_enabled)
  3240. dsi_vdc_create_pps_buf_cmd(&priv_info->vdc,
  3241. panel->dce_pps_cmd, 0,
  3242. DSI_CMD_PPS_SIZE - DSI_CMD_PPS_HDR_SIZE);
  3243. if (priv_info->dsc_enabled || priv_info->vdc_enabled) {
  3244. rc = dsi_panel_create_cmd_packets(panel->dce_pps_cmd,
  3245. DSI_CMD_PPS_SIZE, 1, set->cmds);
  3246. if (rc) {
  3247. DSI_ERR("failed to create cmd packets, rc=%d\n", rc);
  3248. goto error;
  3249. }
  3250. }
  3251. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PPS);
  3252. if (rc) {
  3253. DSI_ERR("[%s] failed to send DSI_CMD_SET_PPS cmds, rc=%d\n",
  3254. panel->name, rc);
  3255. }
  3256. dsi_panel_destroy_cmd_packets(set);
  3257. error:
  3258. mutex_unlock(&panel->panel_lock);
  3259. return rc;
  3260. }
  3261. int dsi_panel_set_lp1(struct dsi_panel *panel)
  3262. {
  3263. int rc = 0;
  3264. if (!panel) {
  3265. DSI_ERR("invalid params\n");
  3266. return -EINVAL;
  3267. }
  3268. mutex_lock(&panel->panel_lock);
  3269. if (!panel->panel_initialized)
  3270. goto exit;
  3271. /*
  3272. * Consider LP1->LP2->LP1.
  3273. * If the panel is already in LP mode, do not need to
  3274. * set the regulator.
  3275. * IBB and AB power mode would be set at the same time
  3276. * in PMIC driver, so we only call ibb setting that is enough.
  3277. */
  3278. if (dsi_panel_is_type_oled(panel) &&
  3279. panel->power_mode != SDE_MODE_DPMS_LP2)
  3280. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3281. "ibb", REGULATOR_MODE_IDLE);
  3282. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_LP1);
  3283. if (rc)
  3284. DSI_ERR("[%s] failed to send DSI_CMD_SET_LP1 cmd, rc=%d\n",
  3285. panel->name, rc);
  3286. exit:
  3287. mutex_unlock(&panel->panel_lock);
  3288. return rc;
  3289. }
  3290. int dsi_panel_set_lp2(struct dsi_panel *panel)
  3291. {
  3292. int rc = 0;
  3293. if (!panel) {
  3294. DSI_ERR("invalid params\n");
  3295. return -EINVAL;
  3296. }
  3297. mutex_lock(&panel->panel_lock);
  3298. if (!panel->panel_initialized)
  3299. goto exit;
  3300. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_LP2);
  3301. if (rc)
  3302. DSI_ERR("[%s] failed to send DSI_CMD_SET_LP2 cmd, rc=%d\n",
  3303. panel->name, rc);
  3304. exit:
  3305. mutex_unlock(&panel->panel_lock);
  3306. return rc;
  3307. }
  3308. int dsi_panel_set_nolp(struct dsi_panel *panel)
  3309. {
  3310. int rc = 0;
  3311. if (!panel) {
  3312. DSI_ERR("invalid params\n");
  3313. return -EINVAL;
  3314. }
  3315. mutex_lock(&panel->panel_lock);
  3316. if (!panel->panel_initialized)
  3317. goto exit;
  3318. /*
  3319. * Consider about LP1->LP2->NOLP.
  3320. */
  3321. if (dsi_panel_is_type_oled(panel) &&
  3322. (panel->power_mode == SDE_MODE_DPMS_LP1 ||
  3323. panel->power_mode == SDE_MODE_DPMS_LP2))
  3324. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3325. "ibb", REGULATOR_MODE_NORMAL);
  3326. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_NOLP);
  3327. if (rc)
  3328. DSI_ERR("[%s] failed to send DSI_CMD_SET_NOLP cmd, rc=%d\n",
  3329. panel->name, rc);
  3330. exit:
  3331. mutex_unlock(&panel->panel_lock);
  3332. return rc;
  3333. }
  3334. int dsi_panel_prepare(struct dsi_panel *panel)
  3335. {
  3336. int rc = 0;
  3337. if (!panel) {
  3338. DSI_ERR("invalid params\n");
  3339. return -EINVAL;
  3340. }
  3341. mutex_lock(&panel->panel_lock);
  3342. if (panel->lp11_init) {
  3343. rc = dsi_panel_power_on(panel);
  3344. if (rc) {
  3345. DSI_ERR("[%s] panel power on failed, rc=%d\n",
  3346. panel->name, rc);
  3347. goto error;
  3348. }
  3349. }
  3350. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_ON);
  3351. if (rc) {
  3352. DSI_ERR("[%s] failed to send DSI_CMD_SET_PRE_ON cmds, rc=%d\n",
  3353. panel->name, rc);
  3354. goto error;
  3355. }
  3356. error:
  3357. mutex_unlock(&panel->panel_lock);
  3358. return rc;
  3359. }
  3360. static int dsi_panel_roi_prepare_dcs_cmds(struct dsi_panel_cmd_set *set,
  3361. struct dsi_rect *roi, int ctrl_idx, int unicast)
  3362. {
  3363. static const int ROI_CMD_LEN = 5;
  3364. int rc = 0;
  3365. /* DTYPE_DCS_LWRITE */
  3366. char *caset, *paset;
  3367. set->cmds = NULL;
  3368. caset = kzalloc(ROI_CMD_LEN, GFP_KERNEL);
  3369. if (!caset) {
  3370. rc = -ENOMEM;
  3371. goto exit;
  3372. }
  3373. caset[0] = 0x2a;
  3374. caset[1] = (roi->x & 0xFF00) >> 8;
  3375. caset[2] = roi->x & 0xFF;
  3376. caset[3] = ((roi->x - 1 + roi->w) & 0xFF00) >> 8;
  3377. caset[4] = (roi->x - 1 + roi->w) & 0xFF;
  3378. paset = kzalloc(ROI_CMD_LEN, GFP_KERNEL);
  3379. if (!paset) {
  3380. rc = -ENOMEM;
  3381. goto error_free_mem;
  3382. }
  3383. paset[0] = 0x2b;
  3384. paset[1] = (roi->y & 0xFF00) >> 8;
  3385. paset[2] = roi->y & 0xFF;
  3386. paset[3] = ((roi->y - 1 + roi->h) & 0xFF00) >> 8;
  3387. paset[4] = (roi->y - 1 + roi->h) & 0xFF;
  3388. set->type = DSI_CMD_SET_ROI;
  3389. set->state = DSI_CMD_SET_STATE_LP;
  3390. set->count = 2; /* send caset + paset together */
  3391. set->cmds = kcalloc(set->count, sizeof(*set->cmds), GFP_KERNEL);
  3392. if (!set->cmds) {
  3393. rc = -ENOMEM;
  3394. goto error_free_mem;
  3395. }
  3396. set->cmds[0].msg.channel = 0;
  3397. set->cmds[0].msg.type = MIPI_DSI_DCS_LONG_WRITE;
  3398. set->cmds[0].msg.flags = unicast ? MIPI_DSI_MSG_UNICAST : 0;
  3399. set->cmds[0].msg.ctrl = unicast ? ctrl_idx : 0;
  3400. set->cmds[0].msg.tx_len = ROI_CMD_LEN;
  3401. set->cmds[0].msg.tx_buf = caset;
  3402. set->cmds[0].msg.rx_len = 0;
  3403. set->cmds[0].msg.rx_buf = 0;
  3404. set->cmds[0].msg.wait_ms = 0;
  3405. set->cmds[0].last_command = 0;
  3406. set->cmds[0].post_wait_ms = 0;
  3407. set->cmds[1].msg.channel = 0;
  3408. set->cmds[1].msg.type = MIPI_DSI_DCS_LONG_WRITE;
  3409. set->cmds[1].msg.flags = unicast ? MIPI_DSI_MSG_UNICAST : 0;
  3410. set->cmds[1].msg.ctrl = unicast ? ctrl_idx : 0;
  3411. set->cmds[1].msg.tx_len = ROI_CMD_LEN;
  3412. set->cmds[1].msg.tx_buf = paset;
  3413. set->cmds[1].msg.rx_len = 0;
  3414. set->cmds[1].msg.rx_buf = 0;
  3415. set->cmds[1].msg.wait_ms = 0;
  3416. set->cmds[1].last_command = 1;
  3417. set->cmds[1].post_wait_ms = 0;
  3418. goto exit;
  3419. error_free_mem:
  3420. kfree(caset);
  3421. kfree(paset);
  3422. kfree(set->cmds);
  3423. exit:
  3424. return rc;
  3425. }
  3426. int dsi_panel_send_qsync_on_dcs(struct dsi_panel *panel,
  3427. int ctrl_idx)
  3428. {
  3429. int rc = 0;
  3430. if (!panel) {
  3431. DSI_ERR("invalid params\n");
  3432. return -EINVAL;
  3433. }
  3434. mutex_lock(&panel->panel_lock);
  3435. DSI_DEBUG("ctrl:%d qsync on\n", ctrl_idx);
  3436. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_QSYNC_ON);
  3437. if (rc)
  3438. DSI_ERR("[%s] failed to send DSI_CMD_SET_QSYNC_ON cmds rc=%d\n",
  3439. panel->name, rc);
  3440. mutex_unlock(&panel->panel_lock);
  3441. return rc;
  3442. }
  3443. int dsi_panel_send_qsync_off_dcs(struct dsi_panel *panel,
  3444. int ctrl_idx)
  3445. {
  3446. int rc = 0;
  3447. if (!panel) {
  3448. DSI_ERR("invalid params\n");
  3449. return -EINVAL;
  3450. }
  3451. mutex_lock(&panel->panel_lock);
  3452. DSI_DEBUG("ctrl:%d qsync off\n", ctrl_idx);
  3453. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_QSYNC_OFF);
  3454. if (rc)
  3455. DSI_ERR("[%s] failed to send DSI_CMD_SET_QSYNC_OFF cmds rc=%d\n",
  3456. panel->name, rc);
  3457. mutex_unlock(&panel->panel_lock);
  3458. return rc;
  3459. }
  3460. int dsi_panel_send_roi_dcs(struct dsi_panel *panel, int ctrl_idx,
  3461. struct dsi_rect *roi)
  3462. {
  3463. int rc = 0;
  3464. struct dsi_panel_cmd_set *set;
  3465. struct dsi_display_mode_priv_info *priv_info;
  3466. if (!panel || !panel->cur_mode) {
  3467. DSI_ERR("Invalid params\n");
  3468. return -EINVAL;
  3469. }
  3470. priv_info = panel->cur_mode->priv_info;
  3471. set = &priv_info->cmd_sets[DSI_CMD_SET_ROI];
  3472. rc = dsi_panel_roi_prepare_dcs_cmds(set, roi, ctrl_idx, true);
  3473. if (rc) {
  3474. DSI_ERR("[%s] failed to prepare DSI_CMD_SET_ROI cmds, rc=%d\n",
  3475. panel->name, rc);
  3476. return rc;
  3477. }
  3478. DSI_DEBUG("[%s] send roi x %d y %d w %d h %d\n", panel->name,
  3479. roi->x, roi->y, roi->w, roi->h);
  3480. mutex_lock(&panel->panel_lock);
  3481. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ROI);
  3482. if (rc)
  3483. DSI_ERR("[%s] failed to send DSI_CMD_SET_ROI cmds, rc=%d\n",
  3484. panel->name, rc);
  3485. mutex_unlock(&panel->panel_lock);
  3486. dsi_panel_destroy_cmd_packets(set);
  3487. dsi_panel_dealloc_cmd_packets(set);
  3488. return rc;
  3489. }
  3490. int dsi_panel_pre_mode_switch_to_video(struct dsi_panel *panel)
  3491. {
  3492. int rc = 0;
  3493. if (!panel) {
  3494. DSI_ERR("Invalid params\n");
  3495. return -EINVAL;
  3496. }
  3497. mutex_lock(&panel->panel_lock);
  3498. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_CMD_TO_VID_SWITCH);
  3499. if (rc)
  3500. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_TO_VID_SWITCH cmds, rc=%d\n",
  3501. panel->name, rc);
  3502. mutex_unlock(&panel->panel_lock);
  3503. return rc;
  3504. }
  3505. int dsi_panel_pre_mode_switch_to_cmd(struct dsi_panel *panel)
  3506. {
  3507. int rc = 0;
  3508. if (!panel) {
  3509. DSI_ERR("Invalid params\n");
  3510. return -EINVAL;
  3511. }
  3512. mutex_lock(&panel->panel_lock);
  3513. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_VID_TO_CMD_SWITCH);
  3514. if (rc)
  3515. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_TO_VID_SWITCH cmds, rc=%d\n",
  3516. panel->name, rc);
  3517. mutex_unlock(&panel->panel_lock);
  3518. return rc;
  3519. }
  3520. int dsi_panel_mode_switch_to_cmd(struct dsi_panel *panel)
  3521. {
  3522. int rc = 0;
  3523. if (!panel) {
  3524. DSI_ERR("Invalid params\n");
  3525. return -EINVAL;
  3526. }
  3527. mutex_lock(&panel->panel_lock);
  3528. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_VID_TO_CMD_SWITCH);
  3529. if (rc)
  3530. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_TO_VID_SWITCH cmds, rc=%d\n",
  3531. panel->name, rc);
  3532. mutex_unlock(&panel->panel_lock);
  3533. return rc;
  3534. }
  3535. int dsi_panel_mode_switch_to_vid(struct dsi_panel *panel)
  3536. {
  3537. int rc = 0;
  3538. if (!panel) {
  3539. DSI_ERR("Invalid params\n");
  3540. return -EINVAL;
  3541. }
  3542. mutex_lock(&panel->panel_lock);
  3543. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_CMD_TO_VID_SWITCH);
  3544. if (rc)
  3545. DSI_ERR("[%s] failed to send DSI_CMD_SET_CMD_TO_VID_SWITCH cmds, rc=%d\n",
  3546. panel->name, rc);
  3547. mutex_unlock(&panel->panel_lock);
  3548. return rc;
  3549. }
  3550. int dsi_panel_switch(struct dsi_panel *panel)
  3551. {
  3552. int rc = 0;
  3553. if (!panel) {
  3554. DSI_ERR("Invalid params\n");
  3555. return -EINVAL;
  3556. }
  3557. mutex_lock(&panel->panel_lock);
  3558. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_TIMING_SWITCH);
  3559. if (rc)
  3560. DSI_ERR("[%s] failed to send DSI_CMD_SET_TIMING_SWITCH cmds, rc=%d\n",
  3561. panel->name, rc);
  3562. mutex_unlock(&panel->panel_lock);
  3563. return rc;
  3564. }
  3565. int dsi_panel_post_switch(struct dsi_panel *panel)
  3566. {
  3567. int rc = 0;
  3568. if (!panel) {
  3569. DSI_ERR("Invalid params\n");
  3570. return -EINVAL;
  3571. }
  3572. mutex_lock(&panel->panel_lock);
  3573. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_TIMING_SWITCH);
  3574. if (rc)
  3575. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_TIMING_SWITCH cmds, rc=%d\n",
  3576. panel->name, rc);
  3577. mutex_unlock(&panel->panel_lock);
  3578. return rc;
  3579. }
  3580. int dsi_panel_enable(struct dsi_panel *panel)
  3581. {
  3582. int rc = 0;
  3583. if (!panel) {
  3584. DSI_ERR("Invalid params\n");
  3585. return -EINVAL;
  3586. }
  3587. mutex_lock(&panel->panel_lock);
  3588. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_ON);
  3589. if (rc)
  3590. DSI_ERR("[%s] failed to send DSI_CMD_SET_ON cmds, rc=%d\n",
  3591. panel->name, rc);
  3592. else
  3593. panel->panel_initialized = true;
  3594. mutex_unlock(&panel->panel_lock);
  3595. return rc;
  3596. }
  3597. int dsi_panel_post_enable(struct dsi_panel *panel)
  3598. {
  3599. int rc = 0;
  3600. if (!panel) {
  3601. DSI_ERR("invalid params\n");
  3602. return -EINVAL;
  3603. }
  3604. mutex_lock(&panel->panel_lock);
  3605. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_ON);
  3606. if (rc) {
  3607. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_ON cmds, rc=%d\n",
  3608. panel->name, rc);
  3609. goto error;
  3610. }
  3611. error:
  3612. mutex_unlock(&panel->panel_lock);
  3613. return rc;
  3614. }
  3615. int dsi_panel_pre_disable(struct dsi_panel *panel)
  3616. {
  3617. int rc = 0;
  3618. if (!panel) {
  3619. DSI_ERR("invalid params\n");
  3620. return -EINVAL;
  3621. }
  3622. mutex_lock(&panel->panel_lock);
  3623. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_PRE_OFF);
  3624. if (rc) {
  3625. DSI_ERR("[%s] failed to send DSI_CMD_SET_PRE_OFF cmds, rc=%d\n",
  3626. panel->name, rc);
  3627. goto error;
  3628. }
  3629. error:
  3630. mutex_unlock(&panel->panel_lock);
  3631. return rc;
  3632. }
  3633. int dsi_panel_disable(struct dsi_panel *panel)
  3634. {
  3635. int rc = 0;
  3636. if (!panel) {
  3637. DSI_ERR("invalid params\n");
  3638. return -EINVAL;
  3639. }
  3640. mutex_lock(&panel->panel_lock);
  3641. /* Avoid sending panel off commands when ESD recovery is underway */
  3642. if (!atomic_read(&panel->esd_recovery_pending)) {
  3643. /*
  3644. * Need to set IBB/AB regulator mode to STANDBY,
  3645. * if panel is going off from AOD mode.
  3646. */
  3647. if (dsi_panel_is_type_oled(panel) &&
  3648. (panel->power_mode == SDE_MODE_DPMS_LP1 ||
  3649. panel->power_mode == SDE_MODE_DPMS_LP2))
  3650. dsi_pwr_panel_regulator_mode_set(&panel->power_info,
  3651. "ibb", REGULATOR_MODE_STANDBY);
  3652. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_OFF);
  3653. if (rc) {
  3654. /*
  3655. * Sending panel off commands may fail when DSI
  3656. * controller is in a bad state. These failures can be
  3657. * ignored since controller will go for full reset on
  3658. * subsequent display enable anyway.
  3659. */
  3660. pr_warn_ratelimited("[%s] failed to send DSI_CMD_SET_OFF cmds, rc=%d\n",
  3661. panel->name, rc);
  3662. rc = 0;
  3663. }
  3664. }
  3665. panel->panel_initialized = false;
  3666. panel->power_mode = SDE_MODE_DPMS_OFF;
  3667. mutex_unlock(&panel->panel_lock);
  3668. return rc;
  3669. }
  3670. int dsi_panel_unprepare(struct dsi_panel *panel)
  3671. {
  3672. int rc = 0;
  3673. if (!panel) {
  3674. DSI_ERR("invalid params\n");
  3675. return -EINVAL;
  3676. }
  3677. mutex_lock(&panel->panel_lock);
  3678. rc = dsi_panel_tx_cmd_set(panel, DSI_CMD_SET_POST_OFF);
  3679. if (rc) {
  3680. DSI_ERR("[%s] failed to send DSI_CMD_SET_POST_OFF cmds, rc=%d\n",
  3681. panel->name, rc);
  3682. goto error;
  3683. }
  3684. error:
  3685. mutex_unlock(&panel->panel_lock);
  3686. return rc;
  3687. }
  3688. int dsi_panel_post_unprepare(struct dsi_panel *panel)
  3689. {
  3690. int rc = 0;
  3691. if (!panel) {
  3692. DSI_ERR("invalid params\n");
  3693. return -EINVAL;
  3694. }
  3695. mutex_lock(&panel->panel_lock);
  3696. rc = dsi_panel_power_off(panel);
  3697. if (rc) {
  3698. DSI_ERR("[%s] panel power_Off failed, rc=%d\n",
  3699. panel->name, rc);
  3700. goto error;
  3701. }
  3702. error:
  3703. mutex_unlock(&panel->panel_lock);
  3704. return rc;
  3705. }