dsi.c 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2009 Nokia Corporation
  4. * Author: Tomi Valkeinen <tomi.valkeinen@ti.com>
  5. */
  6. #define DSS_SUBSYS_NAME "DSI"
  7. #include <linux/kernel.h>
  8. #include <linux/mfd/syscon.h>
  9. #include <linux/regmap.h>
  10. #include <linux/io.h>
  11. #include <linux/clk.h>
  12. #include <linux/device.h>
  13. #include <linux/err.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/irq.h>
  16. #include <linux/delay.h>
  17. #include <linux/gpio/consumer.h>
  18. #include <linux/mutex.h>
  19. #include <linux/module.h>
  20. #include <linux/semaphore.h>
  21. #include <linux/seq_file.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/regulator/consumer.h>
  24. #include <linux/wait.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/sched.h>
  27. #include <linux/slab.h>
  28. #include <linux/debugfs.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/of.h>
  31. #include <linux/of_graph.h>
  32. #include <linux/of_platform.h>
  33. #include <linux/component.h>
  34. #include <linux/sys_soc.h>
  35. #include <drm/drm_bridge.h>
  36. #include <drm/drm_mipi_dsi.h>
  37. #include <drm/drm_panel.h>
  38. #include <video/mipi_display.h>
  39. #include "omapdss.h"
  40. #include "dss.h"
  41. #define DSI_CATCH_MISSING_TE
  42. #include "dsi.h"
  43. #define REG_GET(dsi, idx, start, end) \
  44. FLD_GET(dsi_read_reg(dsi, idx), start, end)
  45. #define REG_FLD_MOD(dsi, idx, val, start, end) \
  46. dsi_write_reg(dsi, idx, FLD_MOD(dsi_read_reg(dsi, idx), val, start, end))
  47. static int dsi_init_dispc(struct dsi_data *dsi);
  48. static void dsi_uninit_dispc(struct dsi_data *dsi);
  49. static int dsi_vc_send_null(struct dsi_data *dsi, int vc, int channel);
  50. static ssize_t _omap_dsi_host_transfer(struct dsi_data *dsi, int vc,
  51. const struct mipi_dsi_msg *msg);
  52. #ifdef DSI_PERF_MEASURE
  53. static bool dsi_perf;
  54. module_param(dsi_perf, bool, 0644);
  55. #endif
  56. /* Note: for some reason video mode seems to work only if VC_VIDEO is 0 */
  57. #define VC_VIDEO 0
  58. #define VC_CMD 1
  59. #define drm_bridge_to_dsi(bridge) \
  60. container_of(bridge, struct dsi_data, bridge)
  61. static inline struct dsi_data *to_dsi_data(struct omap_dss_device *dssdev)
  62. {
  63. return dev_get_drvdata(dssdev->dev);
  64. }
  65. static inline struct dsi_data *host_to_omap(struct mipi_dsi_host *host)
  66. {
  67. return container_of(host, struct dsi_data, host);
  68. }
  69. static inline void dsi_write_reg(struct dsi_data *dsi,
  70. const struct dsi_reg idx, u32 val)
  71. {
  72. void __iomem *base;
  73. switch(idx.module) {
  74. case DSI_PROTO: base = dsi->proto_base; break;
  75. case DSI_PHY: base = dsi->phy_base; break;
  76. case DSI_PLL: base = dsi->pll_base; break;
  77. default: return;
  78. }
  79. __raw_writel(val, base + idx.idx);
  80. }
  81. static inline u32 dsi_read_reg(struct dsi_data *dsi, const struct dsi_reg idx)
  82. {
  83. void __iomem *base;
  84. switch(idx.module) {
  85. case DSI_PROTO: base = dsi->proto_base; break;
  86. case DSI_PHY: base = dsi->phy_base; break;
  87. case DSI_PLL: base = dsi->pll_base; break;
  88. default: return 0;
  89. }
  90. return __raw_readl(base + idx.idx);
  91. }
  92. static void dsi_bus_lock(struct dsi_data *dsi)
  93. {
  94. down(&dsi->bus_lock);
  95. }
  96. static void dsi_bus_unlock(struct dsi_data *dsi)
  97. {
  98. up(&dsi->bus_lock);
  99. }
  100. static bool dsi_bus_is_locked(struct dsi_data *dsi)
  101. {
  102. return dsi->bus_lock.count == 0;
  103. }
  104. static void dsi_completion_handler(void *data, u32 mask)
  105. {
  106. complete((struct completion *)data);
  107. }
  108. static inline bool wait_for_bit_change(struct dsi_data *dsi,
  109. const struct dsi_reg idx,
  110. int bitnum, int value)
  111. {
  112. unsigned long timeout;
  113. ktime_t wait;
  114. int t;
  115. /* first busyloop to see if the bit changes right away */
  116. t = 100;
  117. while (t-- > 0) {
  118. if (REG_GET(dsi, idx, bitnum, bitnum) == value)
  119. return true;
  120. }
  121. /* then loop for 500ms, sleeping for 1ms in between */
  122. timeout = jiffies + msecs_to_jiffies(500);
  123. while (time_before(jiffies, timeout)) {
  124. if (REG_GET(dsi, idx, bitnum, bitnum) == value)
  125. return true;
  126. wait = ns_to_ktime(1000 * 1000);
  127. set_current_state(TASK_UNINTERRUPTIBLE);
  128. schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
  129. }
  130. return false;
  131. }
  132. #ifdef DSI_PERF_MEASURE
  133. static void dsi_perf_mark_setup(struct dsi_data *dsi)
  134. {
  135. dsi->perf_setup_time = ktime_get();
  136. }
  137. static void dsi_perf_mark_start(struct dsi_data *dsi)
  138. {
  139. dsi->perf_start_time = ktime_get();
  140. }
  141. static void dsi_perf_show(struct dsi_data *dsi, const char *name)
  142. {
  143. ktime_t t, setup_time, trans_time;
  144. u32 total_bytes;
  145. u32 setup_us, trans_us, total_us;
  146. if (!dsi_perf)
  147. return;
  148. t = ktime_get();
  149. setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
  150. setup_us = (u32)ktime_to_us(setup_time);
  151. if (setup_us == 0)
  152. setup_us = 1;
  153. trans_time = ktime_sub(t, dsi->perf_start_time);
  154. trans_us = (u32)ktime_to_us(trans_time);
  155. if (trans_us == 0)
  156. trans_us = 1;
  157. total_us = setup_us + trans_us;
  158. total_bytes = dsi->update_bytes;
  159. pr_info("DSI(%s): %u us + %u us = %u us (%uHz), %u bytes, %u kbytes/sec\n",
  160. name,
  161. setup_us,
  162. trans_us,
  163. total_us,
  164. 1000 * 1000 / total_us,
  165. total_bytes,
  166. total_bytes * 1000 / total_us);
  167. }
  168. #else
  169. static inline void dsi_perf_mark_setup(struct dsi_data *dsi)
  170. {
  171. }
  172. static inline void dsi_perf_mark_start(struct dsi_data *dsi)
  173. {
  174. }
  175. static inline void dsi_perf_show(struct dsi_data *dsi, const char *name)
  176. {
  177. }
  178. #endif
  179. static int verbose_irq;
  180. static void print_irq_status(u32 status)
  181. {
  182. if (status == 0)
  183. return;
  184. if (!verbose_irq && (status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  185. return;
  186. #define PIS(x) (status & DSI_IRQ_##x) ? (#x " ") : ""
  187. pr_debug("DSI IRQ: 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  188. status,
  189. verbose_irq ? PIS(VC0) : "",
  190. verbose_irq ? PIS(VC1) : "",
  191. verbose_irq ? PIS(VC2) : "",
  192. verbose_irq ? PIS(VC3) : "",
  193. PIS(WAKEUP),
  194. PIS(RESYNC),
  195. PIS(PLL_LOCK),
  196. PIS(PLL_UNLOCK),
  197. PIS(PLL_RECALL),
  198. PIS(COMPLEXIO_ERR),
  199. PIS(HS_TX_TIMEOUT),
  200. PIS(LP_RX_TIMEOUT),
  201. PIS(TE_TRIGGER),
  202. PIS(ACK_TRIGGER),
  203. PIS(SYNC_LOST),
  204. PIS(LDO_POWER_GOOD),
  205. PIS(TA_TIMEOUT));
  206. #undef PIS
  207. }
  208. static void print_irq_status_vc(int vc, u32 status)
  209. {
  210. if (status == 0)
  211. return;
  212. if (!verbose_irq && (status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  213. return;
  214. #define PIS(x) (status & DSI_VC_IRQ_##x) ? (#x " ") : ""
  215. pr_debug("DSI VC(%d) IRQ 0x%x: %s%s%s%s%s%s%s%s%s\n",
  216. vc,
  217. status,
  218. PIS(CS),
  219. PIS(ECC_CORR),
  220. PIS(ECC_NO_CORR),
  221. verbose_irq ? PIS(PACKET_SENT) : "",
  222. PIS(BTA),
  223. PIS(FIFO_TX_OVF),
  224. PIS(FIFO_RX_OVF),
  225. PIS(FIFO_TX_UDF),
  226. PIS(PP_BUSY_CHANGE));
  227. #undef PIS
  228. }
  229. static void print_irq_status_cio(u32 status)
  230. {
  231. if (status == 0)
  232. return;
  233. #define PIS(x) (status & DSI_CIO_IRQ_##x) ? (#x " ") : ""
  234. pr_debug("DSI CIO IRQ 0x%x: %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s\n",
  235. status,
  236. PIS(ERRSYNCESC1),
  237. PIS(ERRSYNCESC2),
  238. PIS(ERRSYNCESC3),
  239. PIS(ERRESC1),
  240. PIS(ERRESC2),
  241. PIS(ERRESC3),
  242. PIS(ERRCONTROL1),
  243. PIS(ERRCONTROL2),
  244. PIS(ERRCONTROL3),
  245. PIS(STATEULPS1),
  246. PIS(STATEULPS2),
  247. PIS(STATEULPS3),
  248. PIS(ERRCONTENTIONLP0_1),
  249. PIS(ERRCONTENTIONLP1_1),
  250. PIS(ERRCONTENTIONLP0_2),
  251. PIS(ERRCONTENTIONLP1_2),
  252. PIS(ERRCONTENTIONLP0_3),
  253. PIS(ERRCONTENTIONLP1_3),
  254. PIS(ULPSACTIVENOT_ALL0),
  255. PIS(ULPSACTIVENOT_ALL1));
  256. #undef PIS
  257. }
  258. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  259. static void dsi_collect_irq_stats(struct dsi_data *dsi, u32 irqstatus,
  260. u32 *vcstatus, u32 ciostatus)
  261. {
  262. int i;
  263. spin_lock(&dsi->irq_stats_lock);
  264. dsi->irq_stats.irq_count++;
  265. dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
  266. for (i = 0; i < 4; ++i)
  267. dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
  268. dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
  269. spin_unlock(&dsi->irq_stats_lock);
  270. }
  271. #else
  272. #define dsi_collect_irq_stats(dsi, irqstatus, vcstatus, ciostatus)
  273. #endif
  274. static int debug_irq;
  275. static void dsi_handle_irq_errors(struct dsi_data *dsi, u32 irqstatus,
  276. u32 *vcstatus, u32 ciostatus)
  277. {
  278. int i;
  279. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  280. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  281. print_irq_status(irqstatus);
  282. spin_lock(&dsi->errors_lock);
  283. dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  284. spin_unlock(&dsi->errors_lock);
  285. } else if (debug_irq) {
  286. print_irq_status(irqstatus);
  287. }
  288. for (i = 0; i < 4; ++i) {
  289. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  290. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  291. i, vcstatus[i]);
  292. print_irq_status_vc(i, vcstatus[i]);
  293. } else if (debug_irq) {
  294. print_irq_status_vc(i, vcstatus[i]);
  295. }
  296. }
  297. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  298. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  299. print_irq_status_cio(ciostatus);
  300. } else if (debug_irq) {
  301. print_irq_status_cio(ciostatus);
  302. }
  303. }
  304. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  305. unsigned int isr_array_size, u32 irqstatus)
  306. {
  307. struct dsi_isr_data *isr_data;
  308. int i;
  309. for (i = 0; i < isr_array_size; i++) {
  310. isr_data = &isr_array[i];
  311. if (isr_data->isr && isr_data->mask & irqstatus)
  312. isr_data->isr(isr_data->arg, irqstatus);
  313. }
  314. }
  315. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  316. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  317. {
  318. int i;
  319. dsi_call_isrs(isr_tables->isr_table,
  320. ARRAY_SIZE(isr_tables->isr_table),
  321. irqstatus);
  322. for (i = 0; i < 4; ++i) {
  323. if (vcstatus[i] == 0)
  324. continue;
  325. dsi_call_isrs(isr_tables->isr_table_vc[i],
  326. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  327. vcstatus[i]);
  328. }
  329. if (ciostatus != 0)
  330. dsi_call_isrs(isr_tables->isr_table_cio,
  331. ARRAY_SIZE(isr_tables->isr_table_cio),
  332. ciostatus);
  333. }
  334. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  335. {
  336. struct dsi_data *dsi = arg;
  337. u32 irqstatus, vcstatus[4], ciostatus;
  338. int i;
  339. if (!dsi->is_enabled)
  340. return IRQ_NONE;
  341. spin_lock(&dsi->irq_lock);
  342. irqstatus = dsi_read_reg(dsi, DSI_IRQSTATUS);
  343. /* IRQ is not for us */
  344. if (!irqstatus) {
  345. spin_unlock(&dsi->irq_lock);
  346. return IRQ_NONE;
  347. }
  348. dsi_write_reg(dsi, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  349. /* flush posted write */
  350. dsi_read_reg(dsi, DSI_IRQSTATUS);
  351. for (i = 0; i < 4; ++i) {
  352. if ((irqstatus & (1 << i)) == 0) {
  353. vcstatus[i] = 0;
  354. continue;
  355. }
  356. vcstatus[i] = dsi_read_reg(dsi, DSI_VC_IRQSTATUS(i));
  357. dsi_write_reg(dsi, DSI_VC_IRQSTATUS(i), vcstatus[i]);
  358. /* flush posted write */
  359. dsi_read_reg(dsi, DSI_VC_IRQSTATUS(i));
  360. }
  361. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  362. ciostatus = dsi_read_reg(dsi, DSI_COMPLEXIO_IRQ_STATUS);
  363. dsi_write_reg(dsi, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  364. /* flush posted write */
  365. dsi_read_reg(dsi, DSI_COMPLEXIO_IRQ_STATUS);
  366. } else {
  367. ciostatus = 0;
  368. }
  369. #ifdef DSI_CATCH_MISSING_TE
  370. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  371. timer_delete(&dsi->te_timer);
  372. #endif
  373. /* make a copy and unlock, so that isrs can unregister
  374. * themselves */
  375. memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
  376. sizeof(dsi->isr_tables));
  377. spin_unlock(&dsi->irq_lock);
  378. dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
  379. dsi_handle_irq_errors(dsi, irqstatus, vcstatus, ciostatus);
  380. dsi_collect_irq_stats(dsi, irqstatus, vcstatus, ciostatus);
  381. return IRQ_HANDLED;
  382. }
  383. /* dsi->irq_lock has to be locked by the caller */
  384. static void _omap_dsi_configure_irqs(struct dsi_data *dsi,
  385. struct dsi_isr_data *isr_array,
  386. unsigned int isr_array_size,
  387. u32 default_mask,
  388. const struct dsi_reg enable_reg,
  389. const struct dsi_reg status_reg)
  390. {
  391. struct dsi_isr_data *isr_data;
  392. u32 mask;
  393. u32 old_mask;
  394. int i;
  395. mask = default_mask;
  396. for (i = 0; i < isr_array_size; i++) {
  397. isr_data = &isr_array[i];
  398. if (isr_data->isr == NULL)
  399. continue;
  400. mask |= isr_data->mask;
  401. }
  402. old_mask = dsi_read_reg(dsi, enable_reg);
  403. /* clear the irqstatus for newly enabled irqs */
  404. dsi_write_reg(dsi, status_reg, (mask ^ old_mask) & mask);
  405. dsi_write_reg(dsi, enable_reg, mask);
  406. /* flush posted writes */
  407. dsi_read_reg(dsi, enable_reg);
  408. dsi_read_reg(dsi, status_reg);
  409. }
  410. /* dsi->irq_lock has to be locked by the caller */
  411. static void _omap_dsi_set_irqs(struct dsi_data *dsi)
  412. {
  413. u32 mask = DSI_IRQ_ERROR_MASK;
  414. #ifdef DSI_CATCH_MISSING_TE
  415. mask |= DSI_IRQ_TE_TRIGGER;
  416. #endif
  417. _omap_dsi_configure_irqs(dsi, dsi->isr_tables.isr_table,
  418. ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
  419. DSI_IRQENABLE, DSI_IRQSTATUS);
  420. }
  421. /* dsi->irq_lock has to be locked by the caller */
  422. static void _omap_dsi_set_irqs_vc(struct dsi_data *dsi, int vc)
  423. {
  424. _omap_dsi_configure_irqs(dsi, dsi->isr_tables.isr_table_vc[vc],
  425. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
  426. DSI_VC_IRQ_ERROR_MASK,
  427. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  428. }
  429. /* dsi->irq_lock has to be locked by the caller */
  430. static void _omap_dsi_set_irqs_cio(struct dsi_data *dsi)
  431. {
  432. _omap_dsi_configure_irqs(dsi, dsi->isr_tables.isr_table_cio,
  433. ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
  434. DSI_CIO_IRQ_ERROR_MASK,
  435. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  436. }
  437. static void _dsi_initialize_irq(struct dsi_data *dsi)
  438. {
  439. unsigned long flags;
  440. int vc;
  441. spin_lock_irqsave(&dsi->irq_lock, flags);
  442. memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
  443. _omap_dsi_set_irqs(dsi);
  444. for (vc = 0; vc < 4; ++vc)
  445. _omap_dsi_set_irqs_vc(dsi, vc);
  446. _omap_dsi_set_irqs_cio(dsi);
  447. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  448. }
  449. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  450. struct dsi_isr_data *isr_array, unsigned int isr_array_size)
  451. {
  452. struct dsi_isr_data *isr_data;
  453. int free_idx;
  454. int i;
  455. BUG_ON(isr == NULL);
  456. /* check for duplicate entry and find a free slot */
  457. free_idx = -1;
  458. for (i = 0; i < isr_array_size; i++) {
  459. isr_data = &isr_array[i];
  460. if (isr_data->isr == isr && isr_data->arg == arg &&
  461. isr_data->mask == mask) {
  462. return -EINVAL;
  463. }
  464. if (isr_data->isr == NULL && free_idx == -1)
  465. free_idx = i;
  466. }
  467. if (free_idx == -1)
  468. return -EBUSY;
  469. isr_data = &isr_array[free_idx];
  470. isr_data->isr = isr;
  471. isr_data->arg = arg;
  472. isr_data->mask = mask;
  473. return 0;
  474. }
  475. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  476. struct dsi_isr_data *isr_array, unsigned int isr_array_size)
  477. {
  478. struct dsi_isr_data *isr_data;
  479. int i;
  480. for (i = 0; i < isr_array_size; i++) {
  481. isr_data = &isr_array[i];
  482. if (isr_data->isr != isr || isr_data->arg != arg ||
  483. isr_data->mask != mask)
  484. continue;
  485. isr_data->isr = NULL;
  486. isr_data->arg = NULL;
  487. isr_data->mask = 0;
  488. return 0;
  489. }
  490. return -EINVAL;
  491. }
  492. static int dsi_register_isr(struct dsi_data *dsi, omap_dsi_isr_t isr,
  493. void *arg, u32 mask)
  494. {
  495. unsigned long flags;
  496. int r;
  497. spin_lock_irqsave(&dsi->irq_lock, flags);
  498. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  499. ARRAY_SIZE(dsi->isr_tables.isr_table));
  500. if (r == 0)
  501. _omap_dsi_set_irqs(dsi);
  502. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  503. return r;
  504. }
  505. static int dsi_unregister_isr(struct dsi_data *dsi, omap_dsi_isr_t isr,
  506. void *arg, u32 mask)
  507. {
  508. unsigned long flags;
  509. int r;
  510. spin_lock_irqsave(&dsi->irq_lock, flags);
  511. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  512. ARRAY_SIZE(dsi->isr_tables.isr_table));
  513. if (r == 0)
  514. _omap_dsi_set_irqs(dsi);
  515. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  516. return r;
  517. }
  518. static int dsi_register_isr_vc(struct dsi_data *dsi, int vc,
  519. omap_dsi_isr_t isr, void *arg, u32 mask)
  520. {
  521. unsigned long flags;
  522. int r;
  523. spin_lock_irqsave(&dsi->irq_lock, flags);
  524. r = _dsi_register_isr(isr, arg, mask,
  525. dsi->isr_tables.isr_table_vc[vc],
  526. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]));
  527. if (r == 0)
  528. _omap_dsi_set_irqs_vc(dsi, vc);
  529. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  530. return r;
  531. }
  532. static int dsi_unregister_isr_vc(struct dsi_data *dsi, int vc,
  533. omap_dsi_isr_t isr, void *arg, u32 mask)
  534. {
  535. unsigned long flags;
  536. int r;
  537. spin_lock_irqsave(&dsi->irq_lock, flags);
  538. r = _dsi_unregister_isr(isr, arg, mask,
  539. dsi->isr_tables.isr_table_vc[vc],
  540. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]));
  541. if (r == 0)
  542. _omap_dsi_set_irqs_vc(dsi, vc);
  543. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  544. return r;
  545. }
  546. static u32 dsi_get_errors(struct dsi_data *dsi)
  547. {
  548. unsigned long flags;
  549. u32 e;
  550. spin_lock_irqsave(&dsi->errors_lock, flags);
  551. e = dsi->errors;
  552. dsi->errors = 0;
  553. spin_unlock_irqrestore(&dsi->errors_lock, flags);
  554. return e;
  555. }
  556. static int dsi_runtime_get(struct dsi_data *dsi)
  557. {
  558. int r;
  559. DSSDBG("dsi_runtime_get\n");
  560. r = pm_runtime_get_sync(dsi->dev);
  561. if (WARN_ON(r < 0)) {
  562. pm_runtime_put_noidle(dsi->dev);
  563. return r;
  564. }
  565. return 0;
  566. }
  567. static void dsi_runtime_put(struct dsi_data *dsi)
  568. {
  569. int r;
  570. DSSDBG("dsi_runtime_put\n");
  571. r = pm_runtime_put_sync(dsi->dev);
  572. WARN_ON(r < 0 && r != -ENOSYS);
  573. }
  574. static void _dsi_print_reset_status(struct dsi_data *dsi)
  575. {
  576. int b0, b1, b2;
  577. /* A dummy read using the SCP interface to any DSIPHY register is
  578. * required after DSIPHY reset to complete the reset of the DSI complex
  579. * I/O. */
  580. dsi_read_reg(dsi, DSI_DSIPHY_CFG5);
  581. if (dsi->data->quirks & DSI_QUIRK_REVERSE_TXCLKESC) {
  582. b0 = 28;
  583. b1 = 27;
  584. b2 = 26;
  585. } else {
  586. b0 = 24;
  587. b1 = 25;
  588. b2 = 26;
  589. }
  590. #define DSI_FLD_GET(fld, start, end)\
  591. FLD_GET(dsi_read_reg(dsi, DSI_##fld), start, end)
  592. pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n",
  593. DSI_FLD_GET(PLL_STATUS, 0, 0),
  594. DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29),
  595. DSI_FLD_GET(DSIPHY_CFG5, b0, b0),
  596. DSI_FLD_GET(DSIPHY_CFG5, b1, b1),
  597. DSI_FLD_GET(DSIPHY_CFG5, b2, b2),
  598. DSI_FLD_GET(DSIPHY_CFG5, 29, 29),
  599. DSI_FLD_GET(DSIPHY_CFG5, 30, 30),
  600. DSI_FLD_GET(DSIPHY_CFG5, 31, 31));
  601. #undef DSI_FLD_GET
  602. }
  603. static inline int dsi_if_enable(struct dsi_data *dsi, bool enable)
  604. {
  605. DSSDBG("dsi_if_enable(%d)\n", enable);
  606. enable = enable ? 1 : 0;
  607. REG_FLD_MOD(dsi, DSI_CTRL, enable, 0, 0); /* IF_EN */
  608. if (!wait_for_bit_change(dsi, DSI_CTRL, 0, enable)) {
  609. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  610. return -EIO;
  611. }
  612. return 0;
  613. }
  614. static unsigned long dsi_get_pll_hsdiv_dispc_rate(struct dsi_data *dsi)
  615. {
  616. return dsi->pll.cinfo.clkout[HSDIV_DISPC];
  617. }
  618. static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct dsi_data *dsi)
  619. {
  620. return dsi->pll.cinfo.clkout[HSDIV_DSI];
  621. }
  622. static unsigned long dsi_get_txbyteclkhs(struct dsi_data *dsi)
  623. {
  624. return dsi->pll.cinfo.clkdco / 16;
  625. }
  626. static unsigned long dsi_fclk_rate(struct dsi_data *dsi)
  627. {
  628. unsigned long r;
  629. enum dss_clk_source source;
  630. source = dss_get_dsi_clk_source(dsi->dss, dsi->module_id);
  631. if (source == DSS_CLK_SRC_FCK) {
  632. /* DSI FCLK source is DSS_CLK_FCK */
  633. r = clk_get_rate(dsi->dss_clk);
  634. } else {
  635. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  636. r = dsi_get_pll_hsdiv_dsi_rate(dsi);
  637. }
  638. return r;
  639. }
  640. static int dsi_lp_clock_calc(unsigned long dsi_fclk,
  641. unsigned long lp_clk_min, unsigned long lp_clk_max,
  642. struct dsi_lp_clock_info *lp_cinfo)
  643. {
  644. unsigned int lp_clk_div;
  645. unsigned long lp_clk;
  646. lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2);
  647. lp_clk = dsi_fclk / 2 / lp_clk_div;
  648. if (lp_clk < lp_clk_min || lp_clk > lp_clk_max)
  649. return -EINVAL;
  650. lp_cinfo->lp_clk_div = lp_clk_div;
  651. lp_cinfo->lp_clk = lp_clk;
  652. return 0;
  653. }
  654. static int dsi_set_lp_clk_divisor(struct dsi_data *dsi)
  655. {
  656. unsigned long dsi_fclk;
  657. unsigned int lp_clk_div;
  658. unsigned long lp_clk;
  659. unsigned int lpdiv_max = dsi->data->max_pll_lpdiv;
  660. lp_clk_div = dsi->user_lp_cinfo.lp_clk_div;
  661. if (lp_clk_div == 0 || lp_clk_div > lpdiv_max)
  662. return -EINVAL;
  663. dsi_fclk = dsi_fclk_rate(dsi);
  664. lp_clk = dsi_fclk / 2 / lp_clk_div;
  665. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  666. dsi->current_lp_cinfo.lp_clk = lp_clk;
  667. dsi->current_lp_cinfo.lp_clk_div = lp_clk_div;
  668. /* LP_CLK_DIVISOR */
  669. REG_FLD_MOD(dsi, DSI_CLK_CTRL, lp_clk_div, 12, 0);
  670. /* LP_RX_SYNCHRO_ENABLE */
  671. REG_FLD_MOD(dsi, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
  672. return 0;
  673. }
  674. static void dsi_enable_scp_clk(struct dsi_data *dsi)
  675. {
  676. if (dsi->scp_clk_refcount++ == 0)
  677. REG_FLD_MOD(dsi, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
  678. }
  679. static void dsi_disable_scp_clk(struct dsi_data *dsi)
  680. {
  681. WARN_ON(dsi->scp_clk_refcount == 0);
  682. if (--dsi->scp_clk_refcount == 0)
  683. REG_FLD_MOD(dsi, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
  684. }
  685. enum dsi_pll_power_state {
  686. DSI_PLL_POWER_OFF = 0x0,
  687. DSI_PLL_POWER_ON_HSCLK = 0x1,
  688. DSI_PLL_POWER_ON_ALL = 0x2,
  689. DSI_PLL_POWER_ON_DIV = 0x3,
  690. };
  691. static int dsi_pll_power(struct dsi_data *dsi, enum dsi_pll_power_state state)
  692. {
  693. int t = 0;
  694. /* DSI-PLL power command 0x3 is not working */
  695. if ((dsi->data->quirks & DSI_QUIRK_PLL_PWR_BUG) &&
  696. state == DSI_PLL_POWER_ON_DIV)
  697. state = DSI_PLL_POWER_ON_ALL;
  698. /* PLL_PWR_CMD */
  699. REG_FLD_MOD(dsi, DSI_CLK_CTRL, state, 31, 30);
  700. /* PLL_PWR_STATUS */
  701. while (FLD_GET(dsi_read_reg(dsi, DSI_CLK_CTRL), 29, 28) != state) {
  702. if (++t > 1000) {
  703. DSSERR("Failed to set DSI PLL power mode to %d\n",
  704. state);
  705. return -ENODEV;
  706. }
  707. udelay(1);
  708. }
  709. return 0;
  710. }
  711. static void dsi_pll_calc_dsi_fck(struct dsi_data *dsi,
  712. struct dss_pll_clock_info *cinfo)
  713. {
  714. unsigned long max_dsi_fck;
  715. max_dsi_fck = dsi->data->max_fck_freq;
  716. cinfo->mX[HSDIV_DSI] = DIV_ROUND_UP(cinfo->clkdco, max_dsi_fck);
  717. cinfo->clkout[HSDIV_DSI] = cinfo->clkdco / cinfo->mX[HSDIV_DSI];
  718. }
  719. static int dsi_pll_enable(struct dss_pll *pll)
  720. {
  721. struct dsi_data *dsi = container_of(pll, struct dsi_data, pll);
  722. int r = 0;
  723. DSSDBG("PLL init\n");
  724. r = dsi_runtime_get(dsi);
  725. if (r)
  726. return r;
  727. /*
  728. * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
  729. */
  730. dsi_enable_scp_clk(dsi);
  731. r = regulator_enable(dsi->vdds_dsi_reg);
  732. if (r)
  733. goto err0;
  734. /* XXX PLL does not come out of reset without this... */
  735. dispc_pck_free_enable(dsi->dss->dispc, 1);
  736. if (!wait_for_bit_change(dsi, DSI_PLL_STATUS, 0, 1)) {
  737. DSSERR("PLL not coming out of reset.\n");
  738. r = -ENODEV;
  739. dispc_pck_free_enable(dsi->dss->dispc, 0);
  740. goto err1;
  741. }
  742. /* XXX ... but if left on, we get problems when planes do not
  743. * fill the whole display. No idea about this */
  744. dispc_pck_free_enable(dsi->dss->dispc, 0);
  745. r = dsi_pll_power(dsi, DSI_PLL_POWER_ON_ALL);
  746. if (r)
  747. goto err1;
  748. DSSDBG("PLL init done\n");
  749. return 0;
  750. err1:
  751. regulator_disable(dsi->vdds_dsi_reg);
  752. err0:
  753. dsi_disable_scp_clk(dsi);
  754. dsi_runtime_put(dsi);
  755. return r;
  756. }
  757. static void dsi_pll_disable(struct dss_pll *pll)
  758. {
  759. struct dsi_data *dsi = container_of(pll, struct dsi_data, pll);
  760. dsi_pll_power(dsi, DSI_PLL_POWER_OFF);
  761. regulator_disable(dsi->vdds_dsi_reg);
  762. dsi_disable_scp_clk(dsi);
  763. dsi_runtime_put(dsi);
  764. DSSDBG("PLL disable done\n");
  765. }
  766. static int dsi_dump_dsi_clocks(struct seq_file *s, void *p)
  767. {
  768. struct dsi_data *dsi = s->private;
  769. struct dss_pll_clock_info *cinfo = &dsi->pll.cinfo;
  770. enum dss_clk_source dispc_clk_src, dsi_clk_src;
  771. int dsi_module = dsi->module_id;
  772. struct dss_pll *pll = &dsi->pll;
  773. dispc_clk_src = dss_get_dispc_clk_source(dsi->dss);
  774. dsi_clk_src = dss_get_dsi_clk_source(dsi->dss, dsi_module);
  775. if (dsi_runtime_get(dsi))
  776. return 0;
  777. seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
  778. seq_printf(s, "dsi pll clkin\t%lu\n", clk_get_rate(pll->clkin));
  779. seq_printf(s, "Fint\t\t%-16lun %u\n", cinfo->fint, cinfo->n);
  780. seq_printf(s, "CLKIN4DDR\t%-16lum %u\n",
  781. cinfo->clkdco, cinfo->m);
  782. seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16lum_dispc %u\t(%s)\n",
  783. dss_get_clk_source_name(dsi_module == 0 ?
  784. DSS_CLK_SRC_PLL1_1 :
  785. DSS_CLK_SRC_PLL2_1),
  786. cinfo->clkout[HSDIV_DISPC],
  787. cinfo->mX[HSDIV_DISPC],
  788. dispc_clk_src == DSS_CLK_SRC_FCK ?
  789. "off" : "on");
  790. seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16lum_dsi %u\t(%s)\n",
  791. dss_get_clk_source_name(dsi_module == 0 ?
  792. DSS_CLK_SRC_PLL1_2 :
  793. DSS_CLK_SRC_PLL2_2),
  794. cinfo->clkout[HSDIV_DSI],
  795. cinfo->mX[HSDIV_DSI],
  796. dsi_clk_src == DSS_CLK_SRC_FCK ?
  797. "off" : "on");
  798. seq_printf(s, "- DSI%d -\n", dsi_module + 1);
  799. seq_printf(s, "dsi fclk source = %s\n",
  800. dss_get_clk_source_name(dsi_clk_src));
  801. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsi));
  802. seq_printf(s, "DDR_CLK\t\t%lu\n",
  803. cinfo->clkdco / 4);
  804. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsi));
  805. seq_printf(s, "LP_CLK\t\t%lu\n", dsi->current_lp_cinfo.lp_clk);
  806. dsi_runtime_put(dsi);
  807. return 0;
  808. }
  809. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  810. static int dsi_dump_dsi_irqs(struct seq_file *s, void *p)
  811. {
  812. struct dsi_data *dsi = s->private;
  813. unsigned long flags;
  814. struct dsi_irq_stats *stats;
  815. stats = kmalloc_obj(*stats);
  816. if (!stats)
  817. return -ENOMEM;
  818. spin_lock_irqsave(&dsi->irq_stats_lock, flags);
  819. *stats = dsi->irq_stats;
  820. memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
  821. dsi->irq_stats.last_reset = jiffies;
  822. spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
  823. seq_printf(s, "period %u ms\n",
  824. jiffies_to_msecs(jiffies - stats->last_reset));
  825. seq_printf(s, "irqs %d\n", stats->irq_count);
  826. #define PIS(x) \
  827. seq_printf(s, "%-20s %10d\n", #x, stats->dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  828. seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
  829. PIS(VC0);
  830. PIS(VC1);
  831. PIS(VC2);
  832. PIS(VC3);
  833. PIS(WAKEUP);
  834. PIS(RESYNC);
  835. PIS(PLL_LOCK);
  836. PIS(PLL_UNLOCK);
  837. PIS(PLL_RECALL);
  838. PIS(COMPLEXIO_ERR);
  839. PIS(HS_TX_TIMEOUT);
  840. PIS(LP_RX_TIMEOUT);
  841. PIS(TE_TRIGGER);
  842. PIS(ACK_TRIGGER);
  843. PIS(SYNC_LOST);
  844. PIS(LDO_POWER_GOOD);
  845. PIS(TA_TIMEOUT);
  846. #undef PIS
  847. #define PIS(x) \
  848. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  849. stats->vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  850. stats->vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  851. stats->vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  852. stats->vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  853. seq_printf(s, "-- VC interrupts --\n");
  854. PIS(CS);
  855. PIS(ECC_CORR);
  856. PIS(PACKET_SENT);
  857. PIS(FIFO_TX_OVF);
  858. PIS(FIFO_RX_OVF);
  859. PIS(BTA);
  860. PIS(ECC_NO_CORR);
  861. PIS(FIFO_TX_UDF);
  862. PIS(PP_BUSY_CHANGE);
  863. #undef PIS
  864. #define PIS(x) \
  865. seq_printf(s, "%-20s %10d\n", #x, \
  866. stats->cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  867. seq_printf(s, "-- CIO interrupts --\n");
  868. PIS(ERRSYNCESC1);
  869. PIS(ERRSYNCESC2);
  870. PIS(ERRSYNCESC3);
  871. PIS(ERRESC1);
  872. PIS(ERRESC2);
  873. PIS(ERRESC3);
  874. PIS(ERRCONTROL1);
  875. PIS(ERRCONTROL2);
  876. PIS(ERRCONTROL3);
  877. PIS(STATEULPS1);
  878. PIS(STATEULPS2);
  879. PIS(STATEULPS3);
  880. PIS(ERRCONTENTIONLP0_1);
  881. PIS(ERRCONTENTIONLP1_1);
  882. PIS(ERRCONTENTIONLP0_2);
  883. PIS(ERRCONTENTIONLP1_2);
  884. PIS(ERRCONTENTIONLP0_3);
  885. PIS(ERRCONTENTIONLP1_3);
  886. PIS(ULPSACTIVENOT_ALL0);
  887. PIS(ULPSACTIVENOT_ALL1);
  888. #undef PIS
  889. kfree(stats);
  890. return 0;
  891. }
  892. #endif
  893. static int dsi_dump_dsi_regs(struct seq_file *s, void *p)
  894. {
  895. struct dsi_data *dsi = s->private;
  896. if (dsi_runtime_get(dsi))
  897. return 0;
  898. dsi_enable_scp_clk(dsi);
  899. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsi, r))
  900. DUMPREG(DSI_REVISION);
  901. DUMPREG(DSI_SYSCONFIG);
  902. DUMPREG(DSI_SYSSTATUS);
  903. DUMPREG(DSI_IRQSTATUS);
  904. DUMPREG(DSI_IRQENABLE);
  905. DUMPREG(DSI_CTRL);
  906. DUMPREG(DSI_COMPLEXIO_CFG1);
  907. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  908. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  909. DUMPREG(DSI_CLK_CTRL);
  910. DUMPREG(DSI_TIMING1);
  911. DUMPREG(DSI_TIMING2);
  912. DUMPREG(DSI_VM_TIMING1);
  913. DUMPREG(DSI_VM_TIMING2);
  914. DUMPREG(DSI_VM_TIMING3);
  915. DUMPREG(DSI_CLK_TIMING);
  916. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  917. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  918. DUMPREG(DSI_COMPLEXIO_CFG2);
  919. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  920. DUMPREG(DSI_VM_TIMING4);
  921. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  922. DUMPREG(DSI_VM_TIMING5);
  923. DUMPREG(DSI_VM_TIMING6);
  924. DUMPREG(DSI_VM_TIMING7);
  925. DUMPREG(DSI_STOPCLK_TIMING);
  926. DUMPREG(DSI_VC_CTRL(0));
  927. DUMPREG(DSI_VC_TE(0));
  928. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  929. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  930. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  931. DUMPREG(DSI_VC_IRQSTATUS(0));
  932. DUMPREG(DSI_VC_IRQENABLE(0));
  933. DUMPREG(DSI_VC_CTRL(1));
  934. DUMPREG(DSI_VC_TE(1));
  935. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  936. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  937. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  938. DUMPREG(DSI_VC_IRQSTATUS(1));
  939. DUMPREG(DSI_VC_IRQENABLE(1));
  940. DUMPREG(DSI_VC_CTRL(2));
  941. DUMPREG(DSI_VC_TE(2));
  942. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  943. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  944. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  945. DUMPREG(DSI_VC_IRQSTATUS(2));
  946. DUMPREG(DSI_VC_IRQENABLE(2));
  947. DUMPREG(DSI_VC_CTRL(3));
  948. DUMPREG(DSI_VC_TE(3));
  949. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  950. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  951. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  952. DUMPREG(DSI_VC_IRQSTATUS(3));
  953. DUMPREG(DSI_VC_IRQENABLE(3));
  954. DUMPREG(DSI_DSIPHY_CFG0);
  955. DUMPREG(DSI_DSIPHY_CFG1);
  956. DUMPREG(DSI_DSIPHY_CFG2);
  957. DUMPREG(DSI_DSIPHY_CFG5);
  958. DUMPREG(DSI_PLL_CONTROL);
  959. DUMPREG(DSI_PLL_STATUS);
  960. DUMPREG(DSI_PLL_GO);
  961. DUMPREG(DSI_PLL_CONFIGURATION1);
  962. DUMPREG(DSI_PLL_CONFIGURATION2);
  963. #undef DUMPREG
  964. dsi_disable_scp_clk(dsi);
  965. dsi_runtime_put(dsi);
  966. return 0;
  967. }
  968. enum dsi_cio_power_state {
  969. DSI_COMPLEXIO_POWER_OFF = 0x0,
  970. DSI_COMPLEXIO_POWER_ON = 0x1,
  971. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  972. };
  973. static int dsi_cio_power(struct dsi_data *dsi, enum dsi_cio_power_state state)
  974. {
  975. int t = 0;
  976. /* PWR_CMD */
  977. REG_FLD_MOD(dsi, DSI_COMPLEXIO_CFG1, state, 28, 27);
  978. /* PWR_STATUS */
  979. while (FLD_GET(dsi_read_reg(dsi, DSI_COMPLEXIO_CFG1),
  980. 26, 25) != state) {
  981. if (++t > 1000) {
  982. DSSERR("failed to set complexio power state to "
  983. "%d\n", state);
  984. return -ENODEV;
  985. }
  986. udelay(1);
  987. }
  988. return 0;
  989. }
  990. static unsigned int dsi_get_line_buf_size(struct dsi_data *dsi)
  991. {
  992. int val;
  993. /* line buffer on OMAP3 is 1024 x 24bits */
  994. /* XXX: for some reason using full buffer size causes
  995. * considerable TX slowdown with update sizes that fill the
  996. * whole buffer */
  997. if (!(dsi->data->quirks & DSI_QUIRK_GNQ))
  998. return 1023 * 3;
  999. val = REG_GET(dsi, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
  1000. switch (val) {
  1001. case 1:
  1002. return 512 * 3; /* 512x24 bits */
  1003. case 2:
  1004. return 682 * 3; /* 682x24 bits */
  1005. case 3:
  1006. return 853 * 3; /* 853x24 bits */
  1007. case 4:
  1008. return 1024 * 3; /* 1024x24 bits */
  1009. case 5:
  1010. return 1194 * 3; /* 1194x24 bits */
  1011. case 6:
  1012. return 1365 * 3; /* 1365x24 bits */
  1013. case 7:
  1014. return 1920 * 3; /* 1920x24 bits */
  1015. default:
  1016. BUG();
  1017. return 0;
  1018. }
  1019. }
  1020. static int dsi_set_lane_config(struct dsi_data *dsi)
  1021. {
  1022. static const u8 offsets[] = { 0, 4, 8, 12, 16 };
  1023. static const enum dsi_lane_function functions[] = {
  1024. DSI_LANE_CLK,
  1025. DSI_LANE_DATA1,
  1026. DSI_LANE_DATA2,
  1027. DSI_LANE_DATA3,
  1028. DSI_LANE_DATA4,
  1029. };
  1030. u32 r;
  1031. int i;
  1032. r = dsi_read_reg(dsi, DSI_COMPLEXIO_CFG1);
  1033. for (i = 0; i < dsi->num_lanes_used; ++i) {
  1034. unsigned int offset = offsets[i];
  1035. unsigned int polarity, lane_number;
  1036. unsigned int t;
  1037. for (t = 0; t < dsi->num_lanes_supported; ++t)
  1038. if (dsi->lanes[t].function == functions[i])
  1039. break;
  1040. if (t == dsi->num_lanes_supported)
  1041. return -EINVAL;
  1042. lane_number = t;
  1043. polarity = dsi->lanes[t].polarity;
  1044. r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
  1045. r = FLD_MOD(r, polarity, offset + 3, offset + 3);
  1046. }
  1047. /* clear the unused lanes */
  1048. for (; i < dsi->num_lanes_supported; ++i) {
  1049. unsigned int offset = offsets[i];
  1050. r = FLD_MOD(r, 0, offset + 2, offset);
  1051. r = FLD_MOD(r, 0, offset + 3, offset + 3);
  1052. }
  1053. dsi_write_reg(dsi, DSI_COMPLEXIO_CFG1, r);
  1054. return 0;
  1055. }
  1056. static inline unsigned int ns2ddr(struct dsi_data *dsi, unsigned int ns)
  1057. {
  1058. /* convert time in ns to ddr ticks, rounding up */
  1059. unsigned long ddr_clk = dsi->pll.cinfo.clkdco / 4;
  1060. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1061. }
  1062. static inline unsigned int ddr2ns(struct dsi_data *dsi, unsigned int ddr)
  1063. {
  1064. unsigned long ddr_clk = dsi->pll.cinfo.clkdco / 4;
  1065. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1066. }
  1067. static void dsi_cio_timings(struct dsi_data *dsi)
  1068. {
  1069. u32 r;
  1070. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1071. u32 tlpx_half, tclk_trail, tclk_zero;
  1072. u32 tclk_prepare;
  1073. /* calculate timings */
  1074. /* 1 * DDR_CLK = 2 * UI */
  1075. /* min 40ns + 4*UI max 85ns + 6*UI */
  1076. ths_prepare = ns2ddr(dsi, 70) + 2;
  1077. /* min 145ns + 10*UI */
  1078. ths_prepare_ths_zero = ns2ddr(dsi, 175) + 2;
  1079. /* min max(8*UI, 60ns+4*UI) */
  1080. ths_trail = ns2ddr(dsi, 60) + 5;
  1081. /* min 100ns */
  1082. ths_exit = ns2ddr(dsi, 145);
  1083. /* tlpx min 50n */
  1084. tlpx_half = ns2ddr(dsi, 25);
  1085. /* min 60ns */
  1086. tclk_trail = ns2ddr(dsi, 60) + 2;
  1087. /* min 38ns, max 95ns */
  1088. tclk_prepare = ns2ddr(dsi, 65);
  1089. /* min tclk-prepare + tclk-zero = 300ns */
  1090. tclk_zero = ns2ddr(dsi, 260);
  1091. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1092. ths_prepare, ddr2ns(dsi, ths_prepare),
  1093. ths_prepare_ths_zero, ddr2ns(dsi, ths_prepare_ths_zero));
  1094. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1095. ths_trail, ddr2ns(dsi, ths_trail),
  1096. ths_exit, ddr2ns(dsi, ths_exit));
  1097. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1098. "tclk_zero %u (%uns)\n",
  1099. tlpx_half, ddr2ns(dsi, tlpx_half),
  1100. tclk_trail, ddr2ns(dsi, tclk_trail),
  1101. tclk_zero, ddr2ns(dsi, tclk_zero));
  1102. DSSDBG("tclk_prepare %u (%uns)\n",
  1103. tclk_prepare, ddr2ns(dsi, tclk_prepare));
  1104. /* program timings */
  1105. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG0);
  1106. r = FLD_MOD(r, ths_prepare, 31, 24);
  1107. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1108. r = FLD_MOD(r, ths_trail, 15, 8);
  1109. r = FLD_MOD(r, ths_exit, 7, 0);
  1110. dsi_write_reg(dsi, DSI_DSIPHY_CFG0, r);
  1111. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG1);
  1112. r = FLD_MOD(r, tlpx_half, 20, 16);
  1113. r = FLD_MOD(r, tclk_trail, 15, 8);
  1114. r = FLD_MOD(r, tclk_zero, 7, 0);
  1115. if (dsi->data->quirks & DSI_QUIRK_PHY_DCC) {
  1116. r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */
  1117. r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */
  1118. r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */
  1119. }
  1120. dsi_write_reg(dsi, DSI_DSIPHY_CFG1, r);
  1121. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG2);
  1122. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1123. dsi_write_reg(dsi, DSI_DSIPHY_CFG2, r);
  1124. }
  1125. static int dsi_cio_wait_tx_clk_esc_reset(struct dsi_data *dsi)
  1126. {
  1127. int t, i;
  1128. bool in_use[DSI_MAX_NR_LANES];
  1129. static const u8 offsets_old[] = { 28, 27, 26 };
  1130. static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
  1131. const u8 *offsets;
  1132. if (dsi->data->quirks & DSI_QUIRK_REVERSE_TXCLKESC)
  1133. offsets = offsets_old;
  1134. else
  1135. offsets = offsets_new;
  1136. for (i = 0; i < dsi->num_lanes_supported; ++i)
  1137. in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
  1138. t = 100000;
  1139. while (true) {
  1140. u32 l;
  1141. int ok;
  1142. l = dsi_read_reg(dsi, DSI_DSIPHY_CFG5);
  1143. ok = 0;
  1144. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1145. if (!in_use[i] || (l & (1 << offsets[i])))
  1146. ok++;
  1147. }
  1148. if (ok == dsi->num_lanes_supported)
  1149. break;
  1150. if (--t == 0) {
  1151. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1152. if (!in_use[i] || (l & (1 << offsets[i])))
  1153. continue;
  1154. DSSERR("CIO TXCLKESC%d domain not coming " \
  1155. "out of reset\n", i);
  1156. }
  1157. return -EIO;
  1158. }
  1159. }
  1160. return 0;
  1161. }
  1162. /* return bitmask of enabled lanes, lane0 being the lsb */
  1163. static unsigned int dsi_get_lane_mask(struct dsi_data *dsi)
  1164. {
  1165. unsigned int mask = 0;
  1166. int i;
  1167. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1168. if (dsi->lanes[i].function != DSI_LANE_UNUSED)
  1169. mask |= 1 << i;
  1170. }
  1171. return mask;
  1172. }
  1173. /* OMAP4 CONTROL_DSIPHY */
  1174. #define OMAP4_DSIPHY_SYSCON_OFFSET 0x78
  1175. #define OMAP4_DSI2_LANEENABLE_SHIFT 29
  1176. #define OMAP4_DSI2_LANEENABLE_MASK (0x7 << 29)
  1177. #define OMAP4_DSI1_LANEENABLE_SHIFT 24
  1178. #define OMAP4_DSI1_LANEENABLE_MASK (0x1f << 24)
  1179. #define OMAP4_DSI1_PIPD_SHIFT 19
  1180. #define OMAP4_DSI1_PIPD_MASK (0x1f << 19)
  1181. #define OMAP4_DSI2_PIPD_SHIFT 14
  1182. #define OMAP4_DSI2_PIPD_MASK (0x1f << 14)
  1183. static int dsi_omap4_mux_pads(struct dsi_data *dsi, unsigned int lanes)
  1184. {
  1185. u32 enable_mask, enable_shift;
  1186. u32 pipd_mask, pipd_shift;
  1187. if (dsi->module_id == 0) {
  1188. enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
  1189. enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
  1190. pipd_mask = OMAP4_DSI1_PIPD_MASK;
  1191. pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
  1192. } else if (dsi->module_id == 1) {
  1193. enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
  1194. enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
  1195. pipd_mask = OMAP4_DSI2_PIPD_MASK;
  1196. pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
  1197. } else {
  1198. return -ENODEV;
  1199. }
  1200. return regmap_update_bits(dsi->syscon, OMAP4_DSIPHY_SYSCON_OFFSET,
  1201. enable_mask | pipd_mask,
  1202. (lanes << enable_shift) | (lanes << pipd_shift));
  1203. }
  1204. /* OMAP5 CONTROL_DSIPHY */
  1205. #define OMAP5_DSIPHY_SYSCON_OFFSET 0x74
  1206. #define OMAP5_DSI1_LANEENABLE_SHIFT 24
  1207. #define OMAP5_DSI2_LANEENABLE_SHIFT 19
  1208. #define OMAP5_DSI_LANEENABLE_MASK 0x1f
  1209. static int dsi_omap5_mux_pads(struct dsi_data *dsi, unsigned int lanes)
  1210. {
  1211. u32 enable_shift;
  1212. if (dsi->module_id == 0)
  1213. enable_shift = OMAP5_DSI1_LANEENABLE_SHIFT;
  1214. else if (dsi->module_id == 1)
  1215. enable_shift = OMAP5_DSI2_LANEENABLE_SHIFT;
  1216. else
  1217. return -ENODEV;
  1218. return regmap_update_bits(dsi->syscon, OMAP5_DSIPHY_SYSCON_OFFSET,
  1219. OMAP5_DSI_LANEENABLE_MASK << enable_shift,
  1220. lanes << enable_shift);
  1221. }
  1222. static int dsi_enable_pads(struct dsi_data *dsi, unsigned int lane_mask)
  1223. {
  1224. if (dsi->data->model == DSI_MODEL_OMAP4)
  1225. return dsi_omap4_mux_pads(dsi, lane_mask);
  1226. if (dsi->data->model == DSI_MODEL_OMAP5)
  1227. return dsi_omap5_mux_pads(dsi, lane_mask);
  1228. return 0;
  1229. }
  1230. static void dsi_disable_pads(struct dsi_data *dsi)
  1231. {
  1232. if (dsi->data->model == DSI_MODEL_OMAP4)
  1233. dsi_omap4_mux_pads(dsi, 0);
  1234. else if (dsi->data->model == DSI_MODEL_OMAP5)
  1235. dsi_omap5_mux_pads(dsi, 0);
  1236. }
  1237. static int dsi_cio_init(struct dsi_data *dsi)
  1238. {
  1239. int r;
  1240. u32 l;
  1241. DSSDBG("DSI CIO init starts");
  1242. r = dsi_enable_pads(dsi, dsi_get_lane_mask(dsi));
  1243. if (r)
  1244. return r;
  1245. dsi_enable_scp_clk(dsi);
  1246. /* A dummy read using the SCP interface to any DSIPHY register is
  1247. * required after DSIPHY reset to complete the reset of the DSI complex
  1248. * I/O. */
  1249. dsi_read_reg(dsi, DSI_DSIPHY_CFG5);
  1250. if (!wait_for_bit_change(dsi, DSI_DSIPHY_CFG5, 30, 1)) {
  1251. DSSERR("CIO SCP Clock domain not coming out of reset.\n");
  1252. r = -EIO;
  1253. goto err_scp_clk_dom;
  1254. }
  1255. r = dsi_set_lane_config(dsi);
  1256. if (r)
  1257. goto err_scp_clk_dom;
  1258. /* set TX STOP MODE timer to maximum for this operation */
  1259. l = dsi_read_reg(dsi, DSI_TIMING1);
  1260. l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1261. l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
  1262. l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
  1263. l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
  1264. dsi_write_reg(dsi, DSI_TIMING1, l);
  1265. r = dsi_cio_power(dsi, DSI_COMPLEXIO_POWER_ON);
  1266. if (r)
  1267. goto err_cio_pwr;
  1268. if (!wait_for_bit_change(dsi, DSI_COMPLEXIO_CFG1, 29, 1)) {
  1269. DSSERR("CIO PWR clock domain not coming out of reset.\n");
  1270. r = -ENODEV;
  1271. goto err_cio_pwr_dom;
  1272. }
  1273. dsi_if_enable(dsi, true);
  1274. dsi_if_enable(dsi, false);
  1275. REG_FLD_MOD(dsi, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1276. r = dsi_cio_wait_tx_clk_esc_reset(dsi);
  1277. if (r)
  1278. goto err_tx_clk_esc_rst;
  1279. /* FORCE_TX_STOP_MODE_IO */
  1280. REG_FLD_MOD(dsi, DSI_TIMING1, 0, 15, 15);
  1281. dsi_cio_timings(dsi);
  1282. /* DDR_CLK_ALWAYS_ON */
  1283. REG_FLD_MOD(dsi, DSI_CLK_CTRL,
  1284. !(dsi->dsidev->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS),
  1285. 13, 13);
  1286. DSSDBG("CIO init done\n");
  1287. return 0;
  1288. err_tx_clk_esc_rst:
  1289. REG_FLD_MOD(dsi, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
  1290. err_cio_pwr_dom:
  1291. dsi_cio_power(dsi, DSI_COMPLEXIO_POWER_OFF);
  1292. err_cio_pwr:
  1293. err_scp_clk_dom:
  1294. dsi_disable_scp_clk(dsi);
  1295. dsi_disable_pads(dsi);
  1296. return r;
  1297. }
  1298. static void dsi_cio_uninit(struct dsi_data *dsi)
  1299. {
  1300. /* DDR_CLK_ALWAYS_ON */
  1301. REG_FLD_MOD(dsi, DSI_CLK_CTRL, 0, 13, 13);
  1302. dsi_cio_power(dsi, DSI_COMPLEXIO_POWER_OFF);
  1303. dsi_disable_scp_clk(dsi);
  1304. dsi_disable_pads(dsi);
  1305. }
  1306. static void dsi_config_tx_fifo(struct dsi_data *dsi,
  1307. enum fifo_size size1, enum fifo_size size2,
  1308. enum fifo_size size3, enum fifo_size size4)
  1309. {
  1310. u32 r = 0;
  1311. int add = 0;
  1312. int i;
  1313. dsi->vc[0].tx_fifo_size = size1;
  1314. dsi->vc[1].tx_fifo_size = size2;
  1315. dsi->vc[2].tx_fifo_size = size3;
  1316. dsi->vc[3].tx_fifo_size = size4;
  1317. for (i = 0; i < 4; i++) {
  1318. u8 v;
  1319. int size = dsi->vc[i].tx_fifo_size;
  1320. if (add + size > 4) {
  1321. DSSERR("Illegal FIFO configuration\n");
  1322. BUG();
  1323. return;
  1324. }
  1325. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1326. r |= v << (8 * i);
  1327. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1328. add += size;
  1329. }
  1330. dsi_write_reg(dsi, DSI_TX_FIFO_VC_SIZE, r);
  1331. }
  1332. static void dsi_config_rx_fifo(struct dsi_data *dsi,
  1333. enum fifo_size size1, enum fifo_size size2,
  1334. enum fifo_size size3, enum fifo_size size4)
  1335. {
  1336. u32 r = 0;
  1337. int add = 0;
  1338. int i;
  1339. dsi->vc[0].rx_fifo_size = size1;
  1340. dsi->vc[1].rx_fifo_size = size2;
  1341. dsi->vc[2].rx_fifo_size = size3;
  1342. dsi->vc[3].rx_fifo_size = size4;
  1343. for (i = 0; i < 4; i++) {
  1344. u8 v;
  1345. int size = dsi->vc[i].rx_fifo_size;
  1346. if (add + size > 4) {
  1347. DSSERR("Illegal FIFO configuration\n");
  1348. BUG();
  1349. return;
  1350. }
  1351. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1352. r |= v << (8 * i);
  1353. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1354. add += size;
  1355. }
  1356. dsi_write_reg(dsi, DSI_RX_FIFO_VC_SIZE, r);
  1357. }
  1358. static int dsi_force_tx_stop_mode_io(struct dsi_data *dsi)
  1359. {
  1360. u32 r;
  1361. r = dsi_read_reg(dsi, DSI_TIMING1);
  1362. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1363. dsi_write_reg(dsi, DSI_TIMING1, r);
  1364. if (!wait_for_bit_change(dsi, DSI_TIMING1, 15, 0)) {
  1365. DSSERR("TX_STOP bit not going down\n");
  1366. return -EIO;
  1367. }
  1368. return 0;
  1369. }
  1370. static bool dsi_vc_is_enabled(struct dsi_data *dsi, int vc)
  1371. {
  1372. return REG_GET(dsi, DSI_VC_CTRL(vc), 0, 0);
  1373. }
  1374. static void dsi_packet_sent_handler_vp(void *data, u32 mask)
  1375. {
  1376. struct dsi_packet_sent_handler_data *vp_data =
  1377. (struct dsi_packet_sent_handler_data *) data;
  1378. struct dsi_data *dsi = vp_data->dsi;
  1379. const int vc = dsi->update_vc;
  1380. u8 bit = dsi->te_enabled ? 30 : 31;
  1381. if (REG_GET(dsi, DSI_VC_TE(vc), bit, bit) == 0)
  1382. complete(vp_data->completion);
  1383. }
  1384. static int dsi_sync_vc_vp(struct dsi_data *dsi, int vc)
  1385. {
  1386. DECLARE_COMPLETION_ONSTACK(completion);
  1387. struct dsi_packet_sent_handler_data vp_data = {
  1388. .dsi = dsi,
  1389. .completion = &completion
  1390. };
  1391. int r = 0;
  1392. u8 bit;
  1393. bit = dsi->te_enabled ? 30 : 31;
  1394. r = dsi_register_isr_vc(dsi, vc, dsi_packet_sent_handler_vp,
  1395. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  1396. if (r)
  1397. goto err0;
  1398. /* Wait for completion only if TE_EN/TE_START is still set */
  1399. if (REG_GET(dsi, DSI_VC_TE(vc), bit, bit)) {
  1400. if (wait_for_completion_timeout(&completion,
  1401. msecs_to_jiffies(10)) == 0) {
  1402. DSSERR("Failed to complete previous frame transfer\n");
  1403. r = -EIO;
  1404. goto err1;
  1405. }
  1406. }
  1407. dsi_unregister_isr_vc(dsi, vc, dsi_packet_sent_handler_vp,
  1408. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  1409. return 0;
  1410. err1:
  1411. dsi_unregister_isr_vc(dsi, vc, dsi_packet_sent_handler_vp,
  1412. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  1413. err0:
  1414. return r;
  1415. }
  1416. static void dsi_packet_sent_handler_l4(void *data, u32 mask)
  1417. {
  1418. struct dsi_packet_sent_handler_data *l4_data =
  1419. (struct dsi_packet_sent_handler_data *) data;
  1420. struct dsi_data *dsi = l4_data->dsi;
  1421. const int vc = dsi->update_vc;
  1422. if (REG_GET(dsi, DSI_VC_CTRL(vc), 5, 5) == 0)
  1423. complete(l4_data->completion);
  1424. }
  1425. static int dsi_sync_vc_l4(struct dsi_data *dsi, int vc)
  1426. {
  1427. DECLARE_COMPLETION_ONSTACK(completion);
  1428. struct dsi_packet_sent_handler_data l4_data = {
  1429. .dsi = dsi,
  1430. .completion = &completion
  1431. };
  1432. int r = 0;
  1433. r = dsi_register_isr_vc(dsi, vc, dsi_packet_sent_handler_l4,
  1434. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  1435. if (r)
  1436. goto err0;
  1437. /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
  1438. if (REG_GET(dsi, DSI_VC_CTRL(vc), 5, 5)) {
  1439. if (wait_for_completion_timeout(&completion,
  1440. msecs_to_jiffies(10)) == 0) {
  1441. DSSERR("Failed to complete previous l4 transfer\n");
  1442. r = -EIO;
  1443. goto err1;
  1444. }
  1445. }
  1446. dsi_unregister_isr_vc(dsi, vc, dsi_packet_sent_handler_l4,
  1447. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  1448. return 0;
  1449. err1:
  1450. dsi_unregister_isr_vc(dsi, vc, dsi_packet_sent_handler_l4,
  1451. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  1452. err0:
  1453. return r;
  1454. }
  1455. static int dsi_sync_vc(struct dsi_data *dsi, int vc)
  1456. {
  1457. WARN_ON(!dsi_bus_is_locked(dsi));
  1458. WARN_ON(in_interrupt());
  1459. if (!dsi_vc_is_enabled(dsi, vc))
  1460. return 0;
  1461. switch (dsi->vc[vc].source) {
  1462. case DSI_VC_SOURCE_VP:
  1463. return dsi_sync_vc_vp(dsi, vc);
  1464. case DSI_VC_SOURCE_L4:
  1465. return dsi_sync_vc_l4(dsi, vc);
  1466. default:
  1467. BUG();
  1468. return -EINVAL;
  1469. }
  1470. }
  1471. static int dsi_vc_enable(struct dsi_data *dsi, int vc, bool enable)
  1472. {
  1473. DSSDBG("dsi_vc_enable vc %d, enable %d\n",
  1474. vc, enable);
  1475. enable = enable ? 1 : 0;
  1476. REG_FLD_MOD(dsi, DSI_VC_CTRL(vc), enable, 0, 0);
  1477. if (!wait_for_bit_change(dsi, DSI_VC_CTRL(vc), 0, enable)) {
  1478. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  1479. return -EIO;
  1480. }
  1481. return 0;
  1482. }
  1483. static void dsi_vc_initial_config(struct dsi_data *dsi, int vc)
  1484. {
  1485. u32 r;
  1486. DSSDBG("Initial config of VC %d", vc);
  1487. r = dsi_read_reg(dsi, DSI_VC_CTRL(vc));
  1488. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  1489. DSSERR("VC(%d) busy when trying to configure it!\n",
  1490. vc);
  1491. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  1492. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  1493. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  1494. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  1495. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  1496. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  1497. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  1498. if (dsi->data->quirks & DSI_QUIRK_VC_OCP_WIDTH)
  1499. r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
  1500. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  1501. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  1502. dsi_write_reg(dsi, DSI_VC_CTRL(vc), r);
  1503. dsi->vc[vc].source = DSI_VC_SOURCE_L4;
  1504. }
  1505. static void dsi_vc_enable_hs(struct omap_dss_device *dssdev, int vc,
  1506. bool enable)
  1507. {
  1508. struct dsi_data *dsi = to_dsi_data(dssdev);
  1509. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", vc, enable);
  1510. if (REG_GET(dsi, DSI_VC_CTRL(vc), 9, 9) == enable)
  1511. return;
  1512. WARN_ON(!dsi_bus_is_locked(dsi));
  1513. dsi_vc_enable(dsi, vc, 0);
  1514. dsi_if_enable(dsi, 0);
  1515. REG_FLD_MOD(dsi, DSI_VC_CTRL(vc), enable, 9, 9);
  1516. dsi_vc_enable(dsi, vc, 1);
  1517. dsi_if_enable(dsi, 1);
  1518. dsi_force_tx_stop_mode_io(dsi);
  1519. }
  1520. static void dsi_vc_flush_long_data(struct dsi_data *dsi, int vc)
  1521. {
  1522. while (REG_GET(dsi, DSI_VC_CTRL(vc), 20, 20)) {
  1523. u32 val;
  1524. val = dsi_read_reg(dsi, DSI_VC_SHORT_PACKET_HEADER(vc));
  1525. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  1526. (val >> 0) & 0xff,
  1527. (val >> 8) & 0xff,
  1528. (val >> 16) & 0xff,
  1529. (val >> 24) & 0xff);
  1530. }
  1531. }
  1532. static void dsi_show_rx_ack_with_err(u16 err)
  1533. {
  1534. DSSERR("\tACK with ERROR (%#x):\n", err);
  1535. if (err & (1 << 0))
  1536. DSSERR("\t\tSoT Error\n");
  1537. if (err & (1 << 1))
  1538. DSSERR("\t\tSoT Sync Error\n");
  1539. if (err & (1 << 2))
  1540. DSSERR("\t\tEoT Sync Error\n");
  1541. if (err & (1 << 3))
  1542. DSSERR("\t\tEscape Mode Entry Command Error\n");
  1543. if (err & (1 << 4))
  1544. DSSERR("\t\tLP Transmit Sync Error\n");
  1545. if (err & (1 << 5))
  1546. DSSERR("\t\tHS Receive Timeout Error\n");
  1547. if (err & (1 << 6))
  1548. DSSERR("\t\tFalse Control Error\n");
  1549. if (err & (1 << 7))
  1550. DSSERR("\t\t(reserved7)\n");
  1551. if (err & (1 << 8))
  1552. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  1553. if (err & (1 << 9))
  1554. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  1555. if (err & (1 << 10))
  1556. DSSERR("\t\tChecksum Error\n");
  1557. if (err & (1 << 11))
  1558. DSSERR("\t\tData type not recognized\n");
  1559. if (err & (1 << 12))
  1560. DSSERR("\t\tInvalid VC ID\n");
  1561. if (err & (1 << 13))
  1562. DSSERR("\t\tInvalid Transmission Length\n");
  1563. if (err & (1 << 14))
  1564. DSSERR("\t\t(reserved14)\n");
  1565. if (err & (1 << 15))
  1566. DSSERR("\t\tDSI Protocol Violation\n");
  1567. }
  1568. static u16 dsi_vc_flush_receive_data(struct dsi_data *dsi, int vc)
  1569. {
  1570. /* RX_FIFO_NOT_EMPTY */
  1571. while (REG_GET(dsi, DSI_VC_CTRL(vc), 20, 20)) {
  1572. u32 val;
  1573. u8 dt;
  1574. val = dsi_read_reg(dsi, DSI_VC_SHORT_PACKET_HEADER(vc));
  1575. DSSERR("\trawval %#08x\n", val);
  1576. dt = FLD_GET(val, 5, 0);
  1577. if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
  1578. u16 err = FLD_GET(val, 23, 8);
  1579. dsi_show_rx_ack_with_err(err);
  1580. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
  1581. DSSERR("\tDCS short response, 1 byte: %#x\n",
  1582. FLD_GET(val, 23, 8));
  1583. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
  1584. DSSERR("\tDCS short response, 2 byte: %#x\n",
  1585. FLD_GET(val, 23, 8));
  1586. } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
  1587. DSSERR("\tDCS long response, len %d\n",
  1588. FLD_GET(val, 23, 8));
  1589. dsi_vc_flush_long_data(dsi, vc);
  1590. } else {
  1591. DSSERR("\tunknown datatype 0x%02x\n", dt);
  1592. }
  1593. }
  1594. return 0;
  1595. }
  1596. static int dsi_vc_send_bta(struct dsi_data *dsi, int vc)
  1597. {
  1598. if (dsi->debug_write || dsi->debug_read)
  1599. DSSDBG("dsi_vc_send_bta %d\n", vc);
  1600. WARN_ON(!dsi_bus_is_locked(dsi));
  1601. /* RX_FIFO_NOT_EMPTY */
  1602. if (REG_GET(dsi, DSI_VC_CTRL(vc), 20, 20)) {
  1603. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  1604. dsi_vc_flush_receive_data(dsi, vc);
  1605. }
  1606. REG_FLD_MOD(dsi, DSI_VC_CTRL(vc), 1, 6, 6); /* BTA_EN */
  1607. /* flush posted write */
  1608. dsi_read_reg(dsi, DSI_VC_CTRL(vc));
  1609. return 0;
  1610. }
  1611. static int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int vc)
  1612. {
  1613. struct dsi_data *dsi = to_dsi_data(dssdev);
  1614. DECLARE_COMPLETION_ONSTACK(completion);
  1615. int r = 0;
  1616. u32 err;
  1617. r = dsi_register_isr_vc(dsi, vc, dsi_completion_handler,
  1618. &completion, DSI_VC_IRQ_BTA);
  1619. if (r)
  1620. goto err0;
  1621. r = dsi_register_isr(dsi, dsi_completion_handler, &completion,
  1622. DSI_IRQ_ERROR_MASK);
  1623. if (r)
  1624. goto err1;
  1625. r = dsi_vc_send_bta(dsi, vc);
  1626. if (r)
  1627. goto err2;
  1628. if (wait_for_completion_timeout(&completion,
  1629. msecs_to_jiffies(500)) == 0) {
  1630. DSSERR("Failed to receive BTA\n");
  1631. r = -EIO;
  1632. goto err2;
  1633. }
  1634. err = dsi_get_errors(dsi);
  1635. if (err) {
  1636. DSSERR("Error while sending BTA: %x\n", err);
  1637. r = -EIO;
  1638. goto err2;
  1639. }
  1640. err2:
  1641. dsi_unregister_isr(dsi, dsi_completion_handler, &completion,
  1642. DSI_IRQ_ERROR_MASK);
  1643. err1:
  1644. dsi_unregister_isr_vc(dsi, vc, dsi_completion_handler,
  1645. &completion, DSI_VC_IRQ_BTA);
  1646. err0:
  1647. return r;
  1648. }
  1649. static inline void dsi_vc_write_long_header(struct dsi_data *dsi, int vc,
  1650. int channel, u8 data_type, u16 len,
  1651. u8 ecc)
  1652. {
  1653. u32 val;
  1654. u8 data_id;
  1655. WARN_ON(!dsi_bus_is_locked(dsi));
  1656. data_id = data_type | channel << 6;
  1657. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  1658. FLD_VAL(ecc, 31, 24);
  1659. dsi_write_reg(dsi, DSI_VC_LONG_PACKET_HEADER(vc), val);
  1660. }
  1661. static inline void dsi_vc_write_long_payload(struct dsi_data *dsi, int vc,
  1662. u8 b1, u8 b2, u8 b3, u8 b4)
  1663. {
  1664. u32 val;
  1665. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  1666. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  1667. b1, b2, b3, b4, val); */
  1668. dsi_write_reg(dsi, DSI_VC_LONG_PACKET_PAYLOAD(vc), val);
  1669. }
  1670. static int dsi_vc_send_long(struct dsi_data *dsi, int vc,
  1671. const struct mipi_dsi_msg *msg)
  1672. {
  1673. /*u32 val; */
  1674. int i;
  1675. const u8 *p;
  1676. int r = 0;
  1677. u8 b1, b2, b3, b4;
  1678. if (dsi->debug_write)
  1679. DSSDBG("dsi_vc_send_long, %zu bytes\n", msg->tx_len);
  1680. /* len + header */
  1681. if (dsi->vc[vc].tx_fifo_size * 32 * 4 < msg->tx_len + 4) {
  1682. DSSERR("unable to send long packet: packet too long.\n");
  1683. return -EINVAL;
  1684. }
  1685. dsi_vc_write_long_header(dsi, vc, msg->channel, msg->type, msg->tx_len, 0);
  1686. p = msg->tx_buf;
  1687. for (i = 0; i < msg->tx_len >> 2; i++) {
  1688. if (dsi->debug_write)
  1689. DSSDBG("\tsending full packet %d\n", i);
  1690. b1 = *p++;
  1691. b2 = *p++;
  1692. b3 = *p++;
  1693. b4 = *p++;
  1694. dsi_vc_write_long_payload(dsi, vc, b1, b2, b3, b4);
  1695. }
  1696. i = msg->tx_len % 4;
  1697. if (i) {
  1698. b1 = 0; b2 = 0; b3 = 0;
  1699. if (dsi->debug_write)
  1700. DSSDBG("\tsending remainder bytes %d\n", i);
  1701. switch (i) {
  1702. case 3:
  1703. b1 = *p++;
  1704. b2 = *p++;
  1705. b3 = *p++;
  1706. break;
  1707. case 2:
  1708. b1 = *p++;
  1709. b2 = *p++;
  1710. break;
  1711. case 1:
  1712. b1 = *p++;
  1713. break;
  1714. }
  1715. dsi_vc_write_long_payload(dsi, vc, b1, b2, b3, 0);
  1716. }
  1717. return r;
  1718. }
  1719. static int dsi_vc_send_short(struct dsi_data *dsi, int vc,
  1720. const struct mipi_dsi_msg *msg)
  1721. {
  1722. struct mipi_dsi_packet pkt;
  1723. int ret;
  1724. u32 r;
  1725. ret = mipi_dsi_create_packet(&pkt, msg);
  1726. if (ret < 0)
  1727. return ret;
  1728. WARN_ON(!dsi_bus_is_locked(dsi));
  1729. if (dsi->debug_write)
  1730. DSSDBG("dsi_vc_send_short(vc%d, dt %#x, b1 %#x, b2 %#x)\n",
  1731. vc, msg->type, pkt.header[1], pkt.header[2]);
  1732. if (FLD_GET(dsi_read_reg(dsi, DSI_VC_CTRL(vc)), 16, 16)) {
  1733. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  1734. return -EINVAL;
  1735. }
  1736. r = pkt.header[3] << 24 | pkt.header[2] << 16 | pkt.header[1] << 8 |
  1737. pkt.header[0];
  1738. dsi_write_reg(dsi, DSI_VC_SHORT_PACKET_HEADER(vc), r);
  1739. return 0;
  1740. }
  1741. static int dsi_vc_send_null(struct dsi_data *dsi, int vc, int channel)
  1742. {
  1743. const struct mipi_dsi_msg msg = {
  1744. .channel = channel,
  1745. .type = MIPI_DSI_NULL_PACKET,
  1746. };
  1747. return dsi_vc_send_long(dsi, vc, &msg);
  1748. }
  1749. static int dsi_vc_write_common(struct omap_dss_device *dssdev, int vc,
  1750. const struct mipi_dsi_msg *msg)
  1751. {
  1752. struct dsi_data *dsi = to_dsi_data(dssdev);
  1753. int r;
  1754. if (mipi_dsi_packet_format_is_short(msg->type))
  1755. r = dsi_vc_send_short(dsi, vc, msg);
  1756. else
  1757. r = dsi_vc_send_long(dsi, vc, msg);
  1758. if (r < 0)
  1759. return r;
  1760. /*
  1761. * TODO: we do not always have to do the BTA sync, for example
  1762. * we can improve performance by setting the update window
  1763. * information without sending BTA sync between the commands.
  1764. * In that case we can return early.
  1765. */
  1766. r = dsi_vc_send_bta_sync(dssdev, vc);
  1767. if (r) {
  1768. DSSERR("bta sync failed\n");
  1769. return r;
  1770. }
  1771. /* RX_FIFO_NOT_EMPTY */
  1772. if (REG_GET(dsi, DSI_VC_CTRL(vc), 20, 20)) {
  1773. DSSERR("rx fifo not empty after write, dumping data:\n");
  1774. dsi_vc_flush_receive_data(dsi, vc);
  1775. return -EIO;
  1776. }
  1777. return 0;
  1778. }
  1779. static int dsi_vc_read_rx_fifo(struct dsi_data *dsi, int vc, u8 *buf,
  1780. int buflen, enum dss_dsi_content_type type)
  1781. {
  1782. u32 val;
  1783. u8 dt;
  1784. int r;
  1785. /* RX_FIFO_NOT_EMPTY */
  1786. if (REG_GET(dsi, DSI_VC_CTRL(vc), 20, 20) == 0) {
  1787. DSSERR("RX fifo empty when trying to read.\n");
  1788. r = -EIO;
  1789. goto err;
  1790. }
  1791. val = dsi_read_reg(dsi, DSI_VC_SHORT_PACKET_HEADER(vc));
  1792. if (dsi->debug_read)
  1793. DSSDBG("\theader: %08x\n", val);
  1794. dt = FLD_GET(val, 5, 0);
  1795. if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
  1796. u16 err = FLD_GET(val, 23, 8);
  1797. dsi_show_rx_ack_with_err(err);
  1798. r = -EIO;
  1799. goto err;
  1800. } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
  1801. MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
  1802. MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
  1803. u8 data = FLD_GET(val, 15, 8);
  1804. if (dsi->debug_read)
  1805. DSSDBG("\t%s short response, 1 byte: %02x\n",
  1806. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
  1807. "DCS", data);
  1808. if (buflen < 1) {
  1809. r = -EIO;
  1810. goto err;
  1811. }
  1812. buf[0] = data;
  1813. return 1;
  1814. } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
  1815. MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
  1816. MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
  1817. u16 data = FLD_GET(val, 23, 8);
  1818. if (dsi->debug_read)
  1819. DSSDBG("\t%s short response, 2 byte: %04x\n",
  1820. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
  1821. "DCS", data);
  1822. if (buflen < 2) {
  1823. r = -EIO;
  1824. goto err;
  1825. }
  1826. buf[0] = data & 0xff;
  1827. buf[1] = (data >> 8) & 0xff;
  1828. return 2;
  1829. } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
  1830. MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
  1831. MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
  1832. int w;
  1833. int len = FLD_GET(val, 23, 8);
  1834. if (dsi->debug_read)
  1835. DSSDBG("\t%s long response, len %d\n",
  1836. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
  1837. "DCS", len);
  1838. if (len > buflen) {
  1839. r = -EIO;
  1840. goto err;
  1841. }
  1842. /* two byte checksum ends the packet, not included in len */
  1843. for (w = 0; w < len + 2;) {
  1844. int b;
  1845. val = dsi_read_reg(dsi,
  1846. DSI_VC_SHORT_PACKET_HEADER(vc));
  1847. if (dsi->debug_read)
  1848. DSSDBG("\t\t%02x %02x %02x %02x\n",
  1849. (val >> 0) & 0xff,
  1850. (val >> 8) & 0xff,
  1851. (val >> 16) & 0xff,
  1852. (val >> 24) & 0xff);
  1853. for (b = 0; b < 4; ++b) {
  1854. if (w < len)
  1855. buf[w] = (val >> (b * 8)) & 0xff;
  1856. /* we discard the 2 byte checksum */
  1857. ++w;
  1858. }
  1859. }
  1860. return len;
  1861. } else {
  1862. DSSERR("\tunknown datatype 0x%02x\n", dt);
  1863. r = -EIO;
  1864. goto err;
  1865. }
  1866. err:
  1867. DSSERR("dsi_vc_read_rx_fifo(vc %d type %s) failed\n", vc,
  1868. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
  1869. return r;
  1870. }
  1871. static int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int vc,
  1872. const struct mipi_dsi_msg *msg)
  1873. {
  1874. struct dsi_data *dsi = to_dsi_data(dssdev);
  1875. u8 cmd = ((u8 *)msg->tx_buf)[0];
  1876. int r;
  1877. if (dsi->debug_read)
  1878. DSSDBG("%s(vc %d, cmd %x)\n", __func__, vc, cmd);
  1879. r = dsi_vc_send_short(dsi, vc, msg);
  1880. if (r)
  1881. goto err;
  1882. r = dsi_vc_send_bta_sync(dssdev, vc);
  1883. if (r)
  1884. goto err;
  1885. r = dsi_vc_read_rx_fifo(dsi, vc, msg->rx_buf, msg->rx_len,
  1886. DSS_DSI_CONTENT_DCS);
  1887. if (r < 0)
  1888. goto err;
  1889. if (r != msg->rx_len) {
  1890. r = -EIO;
  1891. goto err;
  1892. }
  1893. return 0;
  1894. err:
  1895. DSSERR("%s(vc %d, cmd 0x%02x) failed\n", __func__, vc, cmd);
  1896. return r;
  1897. }
  1898. static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int vc,
  1899. const struct mipi_dsi_msg *msg)
  1900. {
  1901. struct dsi_data *dsi = to_dsi_data(dssdev);
  1902. int r;
  1903. r = dsi_vc_send_short(dsi, vc, msg);
  1904. if (r)
  1905. goto err;
  1906. r = dsi_vc_send_bta_sync(dssdev, vc);
  1907. if (r)
  1908. goto err;
  1909. r = dsi_vc_read_rx_fifo(dsi, vc, msg->rx_buf, msg->rx_len,
  1910. DSS_DSI_CONTENT_GENERIC);
  1911. if (r < 0)
  1912. goto err;
  1913. if (r != msg->rx_len) {
  1914. r = -EIO;
  1915. goto err;
  1916. }
  1917. return 0;
  1918. err:
  1919. DSSERR("%s(vc %d, reqlen %zu) failed\n", __func__, vc, msg->tx_len);
  1920. return r;
  1921. }
  1922. static void dsi_set_lp_rx_timeout(struct dsi_data *dsi, unsigned int ticks,
  1923. bool x4, bool x16)
  1924. {
  1925. unsigned long fck;
  1926. unsigned long total_ticks;
  1927. u32 r;
  1928. BUG_ON(ticks > 0x1fff);
  1929. /* ticks in DSI_FCK */
  1930. fck = dsi_fclk_rate(dsi);
  1931. r = dsi_read_reg(dsi, DSI_TIMING2);
  1932. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  1933. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  1934. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  1935. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  1936. dsi_write_reg(dsi, DSI_TIMING2, r);
  1937. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  1938. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  1939. total_ticks,
  1940. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  1941. (total_ticks * 1000) / (fck / 1000 / 1000));
  1942. }
  1943. static void dsi_set_ta_timeout(struct dsi_data *dsi, unsigned int ticks,
  1944. bool x8, bool x16)
  1945. {
  1946. unsigned long fck;
  1947. unsigned long total_ticks;
  1948. u32 r;
  1949. BUG_ON(ticks > 0x1fff);
  1950. /* ticks in DSI_FCK */
  1951. fck = dsi_fclk_rate(dsi);
  1952. r = dsi_read_reg(dsi, DSI_TIMING1);
  1953. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  1954. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  1955. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  1956. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  1957. dsi_write_reg(dsi, DSI_TIMING1, r);
  1958. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  1959. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  1960. total_ticks,
  1961. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  1962. (total_ticks * 1000) / (fck / 1000 / 1000));
  1963. }
  1964. static void dsi_set_stop_state_counter(struct dsi_data *dsi, unsigned int ticks,
  1965. bool x4, bool x16)
  1966. {
  1967. unsigned long fck;
  1968. unsigned long total_ticks;
  1969. u32 r;
  1970. BUG_ON(ticks > 0x1fff);
  1971. /* ticks in DSI_FCK */
  1972. fck = dsi_fclk_rate(dsi);
  1973. r = dsi_read_reg(dsi, DSI_TIMING1);
  1974. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1975. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  1976. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  1977. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  1978. dsi_write_reg(dsi, DSI_TIMING1, r);
  1979. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  1980. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  1981. total_ticks,
  1982. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  1983. (total_ticks * 1000) / (fck / 1000 / 1000));
  1984. }
  1985. static void dsi_set_hs_tx_timeout(struct dsi_data *dsi, unsigned int ticks,
  1986. bool x4, bool x16)
  1987. {
  1988. unsigned long fck;
  1989. unsigned long total_ticks;
  1990. u32 r;
  1991. BUG_ON(ticks > 0x1fff);
  1992. /* ticks in TxByteClkHS */
  1993. fck = dsi_get_txbyteclkhs(dsi);
  1994. r = dsi_read_reg(dsi, DSI_TIMING2);
  1995. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  1996. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  1997. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  1998. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  1999. dsi_write_reg(dsi, DSI_TIMING2, r);
  2000. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2001. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2002. total_ticks,
  2003. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2004. (total_ticks * 1000) / (fck / 1000 / 1000));
  2005. }
  2006. static void dsi_config_vp_num_line_buffers(struct dsi_data *dsi)
  2007. {
  2008. int num_line_buffers;
  2009. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  2010. int bpp = mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt);
  2011. const struct videomode *vm = &dsi->vm;
  2012. /*
  2013. * Don't use line buffers if width is greater than the video
  2014. * port's line buffer size
  2015. */
  2016. if (dsi->line_buffer_size <= vm->hactive * bpp / 8)
  2017. num_line_buffers = 0;
  2018. else
  2019. num_line_buffers = 2;
  2020. } else {
  2021. /* Use maximum number of line buffers in command mode */
  2022. num_line_buffers = 2;
  2023. }
  2024. /* LINE_BUFFER */
  2025. REG_FLD_MOD(dsi, DSI_CTRL, num_line_buffers, 13, 12);
  2026. }
  2027. static void dsi_config_vp_sync_events(struct dsi_data *dsi)
  2028. {
  2029. bool sync_end;
  2030. u32 r;
  2031. if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE)
  2032. sync_end = true;
  2033. else
  2034. sync_end = false;
  2035. r = dsi_read_reg(dsi, DSI_CTRL);
  2036. r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
  2037. r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
  2038. r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
  2039. r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
  2040. r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */
  2041. r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
  2042. r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */
  2043. dsi_write_reg(dsi, DSI_CTRL, r);
  2044. }
  2045. static void dsi_config_blanking_modes(struct dsi_data *dsi)
  2046. {
  2047. int blanking_mode = dsi->vm_timings.blanking_mode;
  2048. int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
  2049. int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
  2050. int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
  2051. u32 r;
  2052. /*
  2053. * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
  2054. * 1 = Long blanking packets are sent in corresponding blanking periods
  2055. */
  2056. r = dsi_read_reg(dsi, DSI_CTRL);
  2057. r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
  2058. r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
  2059. r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
  2060. r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
  2061. dsi_write_reg(dsi, DSI_CTRL, r);
  2062. }
  2063. /*
  2064. * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
  2065. * results in maximum transition time for data and clock lanes to enter and
  2066. * exit HS mode. Hence, this is the scenario where the least amount of command
  2067. * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
  2068. * clock cycles that can be used to interleave command mode data in HS so that
  2069. * all scenarios are satisfied.
  2070. */
  2071. static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
  2072. int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
  2073. {
  2074. int transition;
  2075. /*
  2076. * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
  2077. * time of data lanes only, if it isn't set, we need to consider HS
  2078. * transition time of both data and clock lanes. HS transition time
  2079. * of Scenario 3 is considered.
  2080. */
  2081. if (ddr_alwon) {
  2082. transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
  2083. } else {
  2084. int trans1, trans2;
  2085. trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
  2086. trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
  2087. enter_hs + 1;
  2088. transition = max(trans1, trans2);
  2089. }
  2090. return blank > transition ? blank - transition : 0;
  2091. }
  2092. /*
  2093. * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
  2094. * results in maximum transition time for data lanes to enter and exit LP mode.
  2095. * Hence, this is the scenario where the least amount of command mode data can
  2096. * be interleaved. We program the minimum amount of bytes that can be
  2097. * interleaved in LP so that all scenarios are satisfied.
  2098. */
  2099. static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
  2100. int lp_clk_div, int tdsi_fclk)
  2101. {
  2102. int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
  2103. int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
  2104. int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
  2105. int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
  2106. int lp_inter; /* cmd mode data that can be interleaved, in bytes */
  2107. /* maximum LP transition time according to Scenario 1 */
  2108. trans_lp = exit_hs + max(enter_hs, 2) + 1;
  2109. /* CLKIN4DDR = 16 * TXBYTECLKHS */
  2110. tlp_avail = thsbyte_clk * (blank - trans_lp);
  2111. ttxclkesc = tdsi_fclk * lp_clk_div;
  2112. lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
  2113. 26) / 16;
  2114. return max(lp_inter, 0);
  2115. }
  2116. static void dsi_config_cmd_mode_interleaving(struct dsi_data *dsi)
  2117. {
  2118. int blanking_mode;
  2119. int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
  2120. int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
  2121. int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
  2122. int tclk_trail, ths_exit, exiths_clk;
  2123. bool ddr_alwon;
  2124. const struct videomode *vm = &dsi->vm;
  2125. int bpp = mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt);
  2126. int ndl = dsi->num_lanes_used - 1;
  2127. int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.mX[HSDIV_DSI] + 1;
  2128. int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
  2129. int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
  2130. int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
  2131. int bl_interleave_hs = 0, bl_interleave_lp = 0;
  2132. u32 r;
  2133. r = dsi_read_reg(dsi, DSI_CTRL);
  2134. blanking_mode = FLD_GET(r, 20, 20);
  2135. hfp_blanking_mode = FLD_GET(r, 21, 21);
  2136. hbp_blanking_mode = FLD_GET(r, 22, 22);
  2137. hsa_blanking_mode = FLD_GET(r, 23, 23);
  2138. r = dsi_read_reg(dsi, DSI_VM_TIMING1);
  2139. hbp = FLD_GET(r, 11, 0);
  2140. hfp = FLD_GET(r, 23, 12);
  2141. hsa = FLD_GET(r, 31, 24);
  2142. r = dsi_read_reg(dsi, DSI_CLK_TIMING);
  2143. ddr_clk_post = FLD_GET(r, 7, 0);
  2144. ddr_clk_pre = FLD_GET(r, 15, 8);
  2145. r = dsi_read_reg(dsi, DSI_VM_TIMING7);
  2146. exit_hs_mode_lat = FLD_GET(r, 15, 0);
  2147. enter_hs_mode_lat = FLD_GET(r, 31, 16);
  2148. r = dsi_read_reg(dsi, DSI_CLK_CTRL);
  2149. lp_clk_div = FLD_GET(r, 12, 0);
  2150. ddr_alwon = FLD_GET(r, 13, 13);
  2151. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG0);
  2152. ths_exit = FLD_GET(r, 7, 0);
  2153. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG1);
  2154. tclk_trail = FLD_GET(r, 15, 8);
  2155. exiths_clk = ths_exit + tclk_trail;
  2156. width_bytes = DIV_ROUND_UP(vm->hactive * bpp, 8);
  2157. bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
  2158. if (!hsa_blanking_mode) {
  2159. hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
  2160. enter_hs_mode_lat, exit_hs_mode_lat,
  2161. exiths_clk, ddr_clk_pre, ddr_clk_post);
  2162. hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
  2163. enter_hs_mode_lat, exit_hs_mode_lat,
  2164. lp_clk_div, dsi_fclk_hsdiv);
  2165. }
  2166. if (!hfp_blanking_mode) {
  2167. hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
  2168. enter_hs_mode_lat, exit_hs_mode_lat,
  2169. exiths_clk, ddr_clk_pre, ddr_clk_post);
  2170. hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
  2171. enter_hs_mode_lat, exit_hs_mode_lat,
  2172. lp_clk_div, dsi_fclk_hsdiv);
  2173. }
  2174. if (!hbp_blanking_mode) {
  2175. hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
  2176. enter_hs_mode_lat, exit_hs_mode_lat,
  2177. exiths_clk, ddr_clk_pre, ddr_clk_post);
  2178. hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
  2179. enter_hs_mode_lat, exit_hs_mode_lat,
  2180. lp_clk_div, dsi_fclk_hsdiv);
  2181. }
  2182. if (!blanking_mode) {
  2183. bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
  2184. enter_hs_mode_lat, exit_hs_mode_lat,
  2185. exiths_clk, ddr_clk_pre, ddr_clk_post);
  2186. bl_interleave_lp = dsi_compute_interleave_lp(bllp,
  2187. enter_hs_mode_lat, exit_hs_mode_lat,
  2188. lp_clk_div, dsi_fclk_hsdiv);
  2189. }
  2190. DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
  2191. hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
  2192. bl_interleave_hs);
  2193. DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
  2194. hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
  2195. bl_interleave_lp);
  2196. r = dsi_read_reg(dsi, DSI_VM_TIMING4);
  2197. r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
  2198. r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
  2199. r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
  2200. dsi_write_reg(dsi, DSI_VM_TIMING4, r);
  2201. r = dsi_read_reg(dsi, DSI_VM_TIMING5);
  2202. r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
  2203. r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
  2204. r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
  2205. dsi_write_reg(dsi, DSI_VM_TIMING5, r);
  2206. r = dsi_read_reg(dsi, DSI_VM_TIMING6);
  2207. r = FLD_MOD(r, bl_interleave_hs, 31, 15);
  2208. r = FLD_MOD(r, bl_interleave_lp, 16, 0);
  2209. dsi_write_reg(dsi, DSI_VM_TIMING6, r);
  2210. }
  2211. static int dsi_proto_config(struct dsi_data *dsi)
  2212. {
  2213. u32 r;
  2214. int buswidth = 0;
  2215. dsi_config_tx_fifo(dsi, DSI_FIFO_SIZE_32,
  2216. DSI_FIFO_SIZE_32,
  2217. DSI_FIFO_SIZE_32,
  2218. DSI_FIFO_SIZE_32);
  2219. dsi_config_rx_fifo(dsi, DSI_FIFO_SIZE_32,
  2220. DSI_FIFO_SIZE_32,
  2221. DSI_FIFO_SIZE_32,
  2222. DSI_FIFO_SIZE_32);
  2223. /* XXX what values for the timeouts? */
  2224. dsi_set_stop_state_counter(dsi, 0x1000, false, false);
  2225. dsi_set_ta_timeout(dsi, 0x1fff, true, true);
  2226. dsi_set_lp_rx_timeout(dsi, 0x1fff, true, true);
  2227. dsi_set_hs_tx_timeout(dsi, 0x1fff, true, true);
  2228. switch (mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt)) {
  2229. case 16:
  2230. buswidth = 0;
  2231. break;
  2232. case 18:
  2233. buswidth = 1;
  2234. break;
  2235. case 24:
  2236. buswidth = 2;
  2237. break;
  2238. default:
  2239. BUG();
  2240. return -EINVAL;
  2241. }
  2242. r = dsi_read_reg(dsi, DSI_CTRL);
  2243. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2244. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2245. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2246. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2247. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2248. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2249. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2250. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2251. if (!(dsi->data->quirks & DSI_QUIRK_DCS_CMD_CONFIG_VC)) {
  2252. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2253. /* DCS_CMD_CODE, 1=start, 0=continue */
  2254. r = FLD_MOD(r, 0, 25, 25);
  2255. }
  2256. dsi_write_reg(dsi, DSI_CTRL, r);
  2257. dsi_config_vp_num_line_buffers(dsi);
  2258. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  2259. dsi_config_vp_sync_events(dsi);
  2260. dsi_config_blanking_modes(dsi);
  2261. dsi_config_cmd_mode_interleaving(dsi);
  2262. }
  2263. dsi_vc_initial_config(dsi, 0);
  2264. dsi_vc_initial_config(dsi, 1);
  2265. dsi_vc_initial_config(dsi, 2);
  2266. dsi_vc_initial_config(dsi, 3);
  2267. return 0;
  2268. }
  2269. static void dsi_proto_timings(struct dsi_data *dsi)
  2270. {
  2271. unsigned int tlpx, tclk_zero, tclk_prepare;
  2272. unsigned int tclk_pre, tclk_post;
  2273. unsigned int ths_prepare, ths_prepare_ths_zero, ths_zero;
  2274. unsigned int ths_trail, ths_exit;
  2275. unsigned int ddr_clk_pre, ddr_clk_post;
  2276. unsigned int enter_hs_mode_lat, exit_hs_mode_lat;
  2277. unsigned int ths_eot;
  2278. int ndl = dsi->num_lanes_used - 1;
  2279. u32 r;
  2280. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG0);
  2281. ths_prepare = FLD_GET(r, 31, 24);
  2282. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  2283. ths_zero = ths_prepare_ths_zero - ths_prepare;
  2284. ths_trail = FLD_GET(r, 15, 8);
  2285. ths_exit = FLD_GET(r, 7, 0);
  2286. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG1);
  2287. tlpx = FLD_GET(r, 20, 16) * 2;
  2288. tclk_zero = FLD_GET(r, 7, 0);
  2289. r = dsi_read_reg(dsi, DSI_DSIPHY_CFG2);
  2290. tclk_prepare = FLD_GET(r, 7, 0);
  2291. /* min 8*UI */
  2292. tclk_pre = 20;
  2293. /* min 60ns + 52*UI */
  2294. tclk_post = ns2ddr(dsi, 60) + 26;
  2295. ths_eot = DIV_ROUND_UP(4, ndl);
  2296. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  2297. 4);
  2298. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  2299. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  2300. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  2301. r = dsi_read_reg(dsi, DSI_CLK_TIMING);
  2302. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  2303. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  2304. dsi_write_reg(dsi, DSI_CLK_TIMING, r);
  2305. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  2306. ddr_clk_pre,
  2307. ddr_clk_post);
  2308. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  2309. DIV_ROUND_UP(ths_prepare, 4) +
  2310. DIV_ROUND_UP(ths_zero + 3, 4);
  2311. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  2312. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  2313. FLD_VAL(exit_hs_mode_lat, 15, 0);
  2314. dsi_write_reg(dsi, DSI_VM_TIMING7, r);
  2315. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  2316. enter_hs_mode_lat, exit_hs_mode_lat);
  2317. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  2318. /* TODO: Implement a video mode check_timings function */
  2319. int hsa = dsi->vm_timings.hsa;
  2320. int hfp = dsi->vm_timings.hfp;
  2321. int hbp = dsi->vm_timings.hbp;
  2322. int vsa = dsi->vm_timings.vsa;
  2323. int vfp = dsi->vm_timings.vfp;
  2324. int vbp = dsi->vm_timings.vbp;
  2325. int window_sync = dsi->vm_timings.window_sync;
  2326. bool hsync_end;
  2327. const struct videomode *vm = &dsi->vm;
  2328. int bpp = mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt);
  2329. int tl, t_he, width_bytes;
  2330. hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE;
  2331. t_he = hsync_end ?
  2332. ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
  2333. width_bytes = DIV_ROUND_UP(vm->hactive * bpp, 8);
  2334. /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
  2335. tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
  2336. DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
  2337. DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
  2338. hfp, hsync_end ? hsa : 0, tl);
  2339. DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
  2340. vsa, vm->vactive);
  2341. r = dsi_read_reg(dsi, DSI_VM_TIMING1);
  2342. r = FLD_MOD(r, hbp, 11, 0); /* HBP */
  2343. r = FLD_MOD(r, hfp, 23, 12); /* HFP */
  2344. r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
  2345. dsi_write_reg(dsi, DSI_VM_TIMING1, r);
  2346. r = dsi_read_reg(dsi, DSI_VM_TIMING2);
  2347. r = FLD_MOD(r, vbp, 7, 0); /* VBP */
  2348. r = FLD_MOD(r, vfp, 15, 8); /* VFP */
  2349. r = FLD_MOD(r, vsa, 23, 16); /* VSA */
  2350. r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
  2351. dsi_write_reg(dsi, DSI_VM_TIMING2, r);
  2352. r = dsi_read_reg(dsi, DSI_VM_TIMING3);
  2353. r = FLD_MOD(r, vm->vactive, 14, 0); /* VACT */
  2354. r = FLD_MOD(r, tl, 31, 16); /* TL */
  2355. dsi_write_reg(dsi, DSI_VM_TIMING3, r);
  2356. }
  2357. }
  2358. static int dsi_configure_pins(struct dsi_data *dsi,
  2359. int num_pins, const u32 *pins)
  2360. {
  2361. struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
  2362. int num_lanes;
  2363. int i;
  2364. static const enum dsi_lane_function functions[] = {
  2365. DSI_LANE_CLK,
  2366. DSI_LANE_DATA1,
  2367. DSI_LANE_DATA2,
  2368. DSI_LANE_DATA3,
  2369. DSI_LANE_DATA4,
  2370. };
  2371. if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
  2372. || num_pins % 2 != 0)
  2373. return -EINVAL;
  2374. for (i = 0; i < DSI_MAX_NR_LANES; ++i)
  2375. lanes[i].function = DSI_LANE_UNUSED;
  2376. num_lanes = 0;
  2377. for (i = 0; i < num_pins; i += 2) {
  2378. u8 lane, pol;
  2379. u32 dx, dy;
  2380. dx = pins[i];
  2381. dy = pins[i + 1];
  2382. if (dx >= dsi->num_lanes_supported * 2)
  2383. return -EINVAL;
  2384. if (dy >= dsi->num_lanes_supported * 2)
  2385. return -EINVAL;
  2386. if (dx & 1) {
  2387. if (dy != dx - 1)
  2388. return -EINVAL;
  2389. pol = 1;
  2390. } else {
  2391. if (dy != dx + 1)
  2392. return -EINVAL;
  2393. pol = 0;
  2394. }
  2395. lane = dx / 2;
  2396. lanes[lane].function = functions[i / 2];
  2397. lanes[lane].polarity = pol;
  2398. num_lanes++;
  2399. }
  2400. memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
  2401. dsi->num_lanes_used = num_lanes;
  2402. return 0;
  2403. }
  2404. static int dsi_enable_video_mode(struct dsi_data *dsi, int vc)
  2405. {
  2406. int bpp = mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt);
  2407. u8 data_type;
  2408. u16 word_count;
  2409. switch (dsi->pix_fmt) {
  2410. case MIPI_DSI_FMT_RGB888:
  2411. data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
  2412. break;
  2413. case MIPI_DSI_FMT_RGB666:
  2414. data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
  2415. break;
  2416. case MIPI_DSI_FMT_RGB666_PACKED:
  2417. data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
  2418. break;
  2419. case MIPI_DSI_FMT_RGB565:
  2420. data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
  2421. break;
  2422. default:
  2423. return -EINVAL;
  2424. }
  2425. dsi_if_enable(dsi, false);
  2426. dsi_vc_enable(dsi, vc, false);
  2427. /* MODE, 1 = video mode */
  2428. REG_FLD_MOD(dsi, DSI_VC_CTRL(vc), 1, 4, 4);
  2429. word_count = DIV_ROUND_UP(dsi->vm.hactive * bpp, 8);
  2430. dsi_vc_write_long_header(dsi, vc, dsi->dsidev->channel, data_type,
  2431. word_count, 0);
  2432. dsi_vc_enable(dsi, vc, true);
  2433. dsi_if_enable(dsi, true);
  2434. return 0;
  2435. }
  2436. static void dsi_disable_video_mode(struct dsi_data *dsi, int vc)
  2437. {
  2438. dsi_if_enable(dsi, false);
  2439. dsi_vc_enable(dsi, vc, false);
  2440. /* MODE, 0 = command mode */
  2441. REG_FLD_MOD(dsi, DSI_VC_CTRL(vc), 0, 4, 4);
  2442. dsi_vc_enable(dsi, vc, true);
  2443. dsi_if_enable(dsi, true);
  2444. }
  2445. static void dsi_enable_video_output(struct omap_dss_device *dssdev, int vc)
  2446. {
  2447. struct dsi_data *dsi = to_dsi_data(dssdev);
  2448. int r;
  2449. r = dsi_init_dispc(dsi);
  2450. if (r) {
  2451. dev_err(dsi->dev, "failed to init dispc!\n");
  2452. return;
  2453. }
  2454. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  2455. r = dsi_enable_video_mode(dsi, vc);
  2456. if (r)
  2457. goto err_video_mode;
  2458. }
  2459. r = dss_mgr_enable(&dsi->output);
  2460. if (r)
  2461. goto err_mgr_enable;
  2462. return;
  2463. err_mgr_enable:
  2464. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  2465. dsi_if_enable(dsi, false);
  2466. dsi_vc_enable(dsi, vc, false);
  2467. }
  2468. err_video_mode:
  2469. dsi_uninit_dispc(dsi);
  2470. dev_err(dsi->dev, "failed to enable DSI encoder!\n");
  2471. return;
  2472. }
  2473. static void dsi_disable_video_output(struct omap_dss_device *dssdev, int vc)
  2474. {
  2475. struct dsi_data *dsi = to_dsi_data(dssdev);
  2476. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE)
  2477. dsi_disable_video_mode(dsi, vc);
  2478. dss_mgr_disable(&dsi->output);
  2479. dsi_uninit_dispc(dsi);
  2480. }
  2481. static void dsi_update_screen_dispc(struct dsi_data *dsi)
  2482. {
  2483. unsigned int bytespp;
  2484. unsigned int bytespl;
  2485. unsigned int bytespf;
  2486. unsigned int total_len;
  2487. unsigned int packet_payload;
  2488. unsigned int packet_len;
  2489. u32 l;
  2490. int r;
  2491. const unsigned vc = dsi->update_vc;
  2492. const unsigned int line_buf_size = dsi->line_buffer_size;
  2493. u16 w = dsi->vm.hactive;
  2494. u16 h = dsi->vm.vactive;
  2495. DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
  2496. bytespp = mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt) / 8;
  2497. bytespl = w * bytespp;
  2498. bytespf = bytespl * h;
  2499. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  2500. * number of lines in a packet. See errata about VP_CLK_RATIO */
  2501. if (bytespf < line_buf_size)
  2502. packet_payload = bytespf;
  2503. else
  2504. packet_payload = (line_buf_size) / bytespl * bytespl;
  2505. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  2506. total_len = (bytespf / packet_payload) * packet_len;
  2507. if (bytespf % packet_payload)
  2508. total_len += (bytespf % packet_payload) + 1;
  2509. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  2510. dsi_write_reg(dsi, DSI_VC_TE(vc), l);
  2511. dsi_vc_write_long_header(dsi, vc, dsi->dsidev->channel, MIPI_DSI_DCS_LONG_WRITE,
  2512. packet_len, 0);
  2513. if (dsi->te_enabled)
  2514. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  2515. else
  2516. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  2517. dsi_write_reg(dsi, DSI_VC_TE(vc), l);
  2518. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  2519. * because DSS interrupts are not capable of waking up the CPU and the
  2520. * framedone interrupt could be delayed for quite a long time. I think
  2521. * the same goes for any DSS interrupts, but for some reason I have not
  2522. * seen the problem anywhere else than here.
  2523. */
  2524. dispc_disable_sidle(dsi->dss->dispc);
  2525. dsi_perf_mark_start(dsi);
  2526. r = schedule_delayed_work(&dsi->framedone_timeout_work,
  2527. msecs_to_jiffies(250));
  2528. BUG_ON(r == 0);
  2529. dss_mgr_start_update(&dsi->output);
  2530. if (dsi->te_enabled) {
  2531. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  2532. * for TE is longer than the timer allows */
  2533. REG_FLD_MOD(dsi, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  2534. dsi_vc_send_bta(dsi, vc);
  2535. #ifdef DSI_CATCH_MISSING_TE
  2536. mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
  2537. #endif
  2538. }
  2539. }
  2540. #ifdef DSI_CATCH_MISSING_TE
  2541. static void dsi_te_timeout(struct timer_list *unused)
  2542. {
  2543. DSSERR("TE not received for 250ms!\n");
  2544. }
  2545. #endif
  2546. static void dsi_handle_framedone(struct dsi_data *dsi, int error)
  2547. {
  2548. /* SIDLEMODE back to smart-idle */
  2549. dispc_enable_sidle(dsi->dss->dispc);
  2550. if (dsi->te_enabled) {
  2551. /* enable LP_RX_TO again after the TE */
  2552. REG_FLD_MOD(dsi, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2553. }
  2554. dsi_bus_unlock(dsi);
  2555. if (!error)
  2556. dsi_perf_show(dsi, "DISPC");
  2557. }
  2558. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  2559. {
  2560. struct dsi_data *dsi = container_of(work, struct dsi_data,
  2561. framedone_timeout_work.work);
  2562. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  2563. * 250ms which would conflict with this timeout work. What should be
  2564. * done is first cancel the transfer on the HW, and then cancel the
  2565. * possibly scheduled framedone work. However, cancelling the transfer
  2566. * on the HW is buggy, and would probably require resetting the whole
  2567. * DSI */
  2568. DSSERR("Framedone not received for 250ms!\n");
  2569. dsi_handle_framedone(dsi, -ETIMEDOUT);
  2570. }
  2571. static void dsi_framedone_irq_callback(void *data)
  2572. {
  2573. struct dsi_data *dsi = data;
  2574. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  2575. * turns itself off. However, DSI still has the pixels in its buffers,
  2576. * and is sending the data.
  2577. */
  2578. cancel_delayed_work(&dsi->framedone_timeout_work);
  2579. DSSDBG("Framedone received!\n");
  2580. dsi_handle_framedone(dsi, 0);
  2581. }
  2582. static int _dsi_update(struct dsi_data *dsi)
  2583. {
  2584. dsi_perf_mark_setup(dsi);
  2585. #ifdef DSI_PERF_MEASURE
  2586. dsi->update_bytes = dsi->vm.hactive * dsi->vm.vactive *
  2587. mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt) / 8;
  2588. #endif
  2589. dsi_update_screen_dispc(dsi);
  2590. return 0;
  2591. }
  2592. static int _dsi_send_nop(struct dsi_data *dsi, int vc, int channel)
  2593. {
  2594. const u8 payload[] = { MIPI_DCS_NOP };
  2595. const struct mipi_dsi_msg msg = {
  2596. .channel = channel,
  2597. .type = MIPI_DSI_DCS_SHORT_WRITE,
  2598. .tx_len = 1,
  2599. .tx_buf = payload,
  2600. };
  2601. WARN_ON(!dsi_bus_is_locked(dsi));
  2602. return _omap_dsi_host_transfer(dsi, vc, &msg);
  2603. }
  2604. static int dsi_update_channel(struct omap_dss_device *dssdev, int vc)
  2605. {
  2606. struct dsi_data *dsi = to_dsi_data(dssdev);
  2607. int r;
  2608. dsi_bus_lock(dsi);
  2609. if (!dsi->video_enabled) {
  2610. r = -EIO;
  2611. goto err;
  2612. }
  2613. if (dsi->vm.hactive == 0 || dsi->vm.vactive == 0) {
  2614. r = -EINVAL;
  2615. goto err;
  2616. }
  2617. DSSDBG("dsi_update_channel: %d", vc);
  2618. /*
  2619. * Send NOP between the frames. If we don't send something here, the
  2620. * updates stop working. This is probably related to DSI spec stating
  2621. * that the DSI host should transition to LP at least once per frame.
  2622. */
  2623. r = _dsi_send_nop(dsi, VC_CMD, dsi->dsidev->channel);
  2624. if (r < 0) {
  2625. DSSWARN("failed to send nop between frames: %d\n", r);
  2626. goto err;
  2627. }
  2628. dsi->update_vc = vc;
  2629. if (dsi->te_enabled && dsi->te_gpio) {
  2630. schedule_delayed_work(&dsi->te_timeout_work,
  2631. msecs_to_jiffies(250));
  2632. atomic_set(&dsi->do_ext_te_update, 1);
  2633. } else {
  2634. _dsi_update(dsi);
  2635. }
  2636. return 0;
  2637. err:
  2638. dsi_bus_unlock(dsi);
  2639. return r;
  2640. }
  2641. static int dsi_update_all(struct omap_dss_device *dssdev)
  2642. {
  2643. return dsi_update_channel(dssdev, VC_VIDEO);
  2644. }
  2645. /* Display funcs */
  2646. static int dsi_configure_dispc_clocks(struct dsi_data *dsi)
  2647. {
  2648. struct dispc_clock_info dispc_cinfo;
  2649. int r;
  2650. unsigned long fck;
  2651. fck = dsi_get_pll_hsdiv_dispc_rate(dsi);
  2652. dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div;
  2653. dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div;
  2654. r = dispc_calc_clock_rates(dsi->dss->dispc, fck, &dispc_cinfo);
  2655. if (r) {
  2656. DSSERR("Failed to calc dispc clocks\n");
  2657. return r;
  2658. }
  2659. dsi->mgr_config.clock_info = dispc_cinfo;
  2660. return 0;
  2661. }
  2662. static int dsi_init_dispc(struct dsi_data *dsi)
  2663. {
  2664. enum omap_channel dispc_channel = dsi->output.dispc_channel;
  2665. int r;
  2666. dss_select_lcd_clk_source(dsi->dss, dispc_channel, dsi->module_id == 0 ?
  2667. DSS_CLK_SRC_PLL1_1 :
  2668. DSS_CLK_SRC_PLL2_1);
  2669. if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
  2670. r = dss_mgr_register_framedone_handler(&dsi->output,
  2671. dsi_framedone_irq_callback, dsi);
  2672. if (r) {
  2673. DSSERR("can't register FRAMEDONE handler\n");
  2674. goto err;
  2675. }
  2676. dsi->mgr_config.stallmode = true;
  2677. dsi->mgr_config.fifohandcheck = true;
  2678. } else {
  2679. dsi->mgr_config.stallmode = false;
  2680. dsi->mgr_config.fifohandcheck = false;
  2681. }
  2682. r = dsi_configure_dispc_clocks(dsi);
  2683. if (r)
  2684. goto err1;
  2685. dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
  2686. dsi->mgr_config.video_port_width =
  2687. mipi_dsi_pixel_format_to_bpp(dsi->pix_fmt);
  2688. dsi->mgr_config.lcden_sig_polarity = 0;
  2689. dss_mgr_set_lcd_config(&dsi->output, &dsi->mgr_config);
  2690. return 0;
  2691. err1:
  2692. if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
  2693. dss_mgr_unregister_framedone_handler(&dsi->output,
  2694. dsi_framedone_irq_callback, dsi);
  2695. err:
  2696. dss_select_lcd_clk_source(dsi->dss, dispc_channel, DSS_CLK_SRC_FCK);
  2697. return r;
  2698. }
  2699. static void dsi_uninit_dispc(struct dsi_data *dsi)
  2700. {
  2701. enum omap_channel dispc_channel = dsi->output.dispc_channel;
  2702. if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
  2703. dss_mgr_unregister_framedone_handler(&dsi->output,
  2704. dsi_framedone_irq_callback, dsi);
  2705. dss_select_lcd_clk_source(dsi->dss, dispc_channel, DSS_CLK_SRC_FCK);
  2706. }
  2707. static int dsi_configure_dsi_clocks(struct dsi_data *dsi)
  2708. {
  2709. struct dss_pll_clock_info cinfo;
  2710. int r;
  2711. cinfo = dsi->user_dsi_cinfo;
  2712. r = dss_pll_set_config(&dsi->pll, &cinfo);
  2713. if (r) {
  2714. DSSERR("Failed to set dsi clocks\n");
  2715. return r;
  2716. }
  2717. return 0;
  2718. }
  2719. static void dsi_setup_dsi_vcs(struct dsi_data *dsi)
  2720. {
  2721. /* Setup VC_CMD for LP and cpu transfers */
  2722. REG_FLD_MOD(dsi, DSI_VC_CTRL(VC_CMD), 0, 9, 9); /* LP */
  2723. REG_FLD_MOD(dsi, DSI_VC_CTRL(VC_CMD), 0, 1, 1); /* SOURCE_L4 */
  2724. dsi->vc[VC_CMD].source = DSI_VC_SOURCE_L4;
  2725. /* Setup VC_VIDEO for HS and dispc transfers */
  2726. REG_FLD_MOD(dsi, DSI_VC_CTRL(VC_VIDEO), 1, 9, 9); /* HS */
  2727. REG_FLD_MOD(dsi, DSI_VC_CTRL(VC_VIDEO), 1, 1, 1); /* SOURCE_VP */
  2728. dsi->vc[VC_VIDEO].source = DSI_VC_SOURCE_VP;
  2729. if ((dsi->data->quirks & DSI_QUIRK_DCS_CMD_CONFIG_VC) &&
  2730. !(dsi->dsidev->mode_flags & MIPI_DSI_MODE_VIDEO))
  2731. REG_FLD_MOD(dsi, DSI_VC_CTRL(VC_VIDEO), 1, 30, 30); /* DCS_CMD_ENABLE */
  2732. dsi_vc_enable(dsi, VC_CMD, 1);
  2733. dsi_vc_enable(dsi, VC_VIDEO, 1);
  2734. dsi_if_enable(dsi, 1);
  2735. dsi_force_tx_stop_mode_io(dsi);
  2736. /* start the DDR clock by sending a NULL packet */
  2737. if (!(dsi->dsidev->mode_flags & MIPI_DSI_CLOCK_NON_CONTINUOUS))
  2738. dsi_vc_send_null(dsi, VC_CMD, dsi->dsidev->channel);
  2739. }
  2740. static int dsi_init_dsi(struct dsi_data *dsi)
  2741. {
  2742. int r;
  2743. r = dss_pll_enable(&dsi->pll);
  2744. if (r)
  2745. return r;
  2746. r = dsi_configure_dsi_clocks(dsi);
  2747. if (r)
  2748. goto err0;
  2749. dss_select_dsi_clk_source(dsi->dss, dsi->module_id,
  2750. dsi->module_id == 0 ?
  2751. DSS_CLK_SRC_PLL1_2 : DSS_CLK_SRC_PLL2_2);
  2752. DSSDBG("PLL OK\n");
  2753. if (!dsi->vdds_dsi_enabled) {
  2754. r = regulator_enable(dsi->vdds_dsi_reg);
  2755. if (r)
  2756. goto err1;
  2757. dsi->vdds_dsi_enabled = true;
  2758. }
  2759. r = dsi_cio_init(dsi);
  2760. if (r)
  2761. goto err2;
  2762. _dsi_print_reset_status(dsi);
  2763. dsi_proto_timings(dsi);
  2764. dsi_set_lp_clk_divisor(dsi);
  2765. if (1)
  2766. _dsi_print_reset_status(dsi);
  2767. r = dsi_proto_config(dsi);
  2768. if (r)
  2769. goto err3;
  2770. dsi_setup_dsi_vcs(dsi);
  2771. return 0;
  2772. err3:
  2773. dsi_cio_uninit(dsi);
  2774. err2:
  2775. regulator_disable(dsi->vdds_dsi_reg);
  2776. dsi->vdds_dsi_enabled = false;
  2777. err1:
  2778. dss_select_dsi_clk_source(dsi->dss, dsi->module_id, DSS_CLK_SRC_FCK);
  2779. err0:
  2780. dss_pll_disable(&dsi->pll);
  2781. return r;
  2782. }
  2783. static void dsi_uninit_dsi(struct dsi_data *dsi)
  2784. {
  2785. /* disable interface */
  2786. dsi_if_enable(dsi, 0);
  2787. dsi_vc_enable(dsi, 0, 0);
  2788. dsi_vc_enable(dsi, 1, 0);
  2789. dsi_vc_enable(dsi, 2, 0);
  2790. dsi_vc_enable(dsi, 3, 0);
  2791. dss_select_dsi_clk_source(dsi->dss, dsi->module_id, DSS_CLK_SRC_FCK);
  2792. dsi_cio_uninit(dsi);
  2793. dss_pll_disable(&dsi->pll);
  2794. regulator_disable(dsi->vdds_dsi_reg);
  2795. dsi->vdds_dsi_enabled = false;
  2796. }
  2797. static void dsi_enable(struct dsi_data *dsi)
  2798. {
  2799. int r;
  2800. WARN_ON(!dsi_bus_is_locked(dsi));
  2801. if (WARN_ON(dsi->iface_enabled))
  2802. return;
  2803. mutex_lock(&dsi->lock);
  2804. r = dsi_runtime_get(dsi);
  2805. if (r)
  2806. goto err_get_dsi;
  2807. _dsi_initialize_irq(dsi);
  2808. r = dsi_init_dsi(dsi);
  2809. if (r)
  2810. goto err_init_dsi;
  2811. dsi->iface_enabled = true;
  2812. mutex_unlock(&dsi->lock);
  2813. return;
  2814. err_init_dsi:
  2815. dsi_runtime_put(dsi);
  2816. err_get_dsi:
  2817. mutex_unlock(&dsi->lock);
  2818. DSSDBG("dsi_enable FAILED\n");
  2819. }
  2820. static void dsi_disable(struct dsi_data *dsi)
  2821. {
  2822. WARN_ON(!dsi_bus_is_locked(dsi));
  2823. if (WARN_ON(!dsi->iface_enabled))
  2824. return;
  2825. mutex_lock(&dsi->lock);
  2826. dsi_sync_vc(dsi, 0);
  2827. dsi_sync_vc(dsi, 1);
  2828. dsi_sync_vc(dsi, 2);
  2829. dsi_sync_vc(dsi, 3);
  2830. dsi_uninit_dsi(dsi);
  2831. dsi_runtime_put(dsi);
  2832. dsi->iface_enabled = false;
  2833. mutex_unlock(&dsi->lock);
  2834. }
  2835. static int dsi_enable_te(struct dsi_data *dsi, bool enable)
  2836. {
  2837. dsi->te_enabled = enable;
  2838. if (dsi->te_gpio) {
  2839. if (enable)
  2840. enable_irq(dsi->te_irq);
  2841. else
  2842. disable_irq(dsi->te_irq);
  2843. }
  2844. return 0;
  2845. }
  2846. #ifdef PRINT_VERBOSE_VM_TIMINGS
  2847. static void print_dsi_vm(const char *str,
  2848. const struct omap_dss_dsi_videomode_timings *t)
  2849. {
  2850. unsigned long byteclk = t->hsclk / 4;
  2851. int bl, wc, pps, tot;
  2852. wc = DIV_ROUND_UP(t->hact * t->bitspp, 8);
  2853. pps = DIV_ROUND_UP(wc + 6, t->ndl); /* pixel packet size */
  2854. bl = t->hss + t->hsa + t->hse + t->hbp + t->hfp;
  2855. tot = bl + pps;
  2856. #define TO_DSI_T(x) ((u32)div64_u64((u64)x * 1000000000llu, byteclk))
  2857. pr_debug("%s bck %lu, %u/%u/%u/%u/%u/%u = %u+%u = %u, "
  2858. "%u/%u/%u/%u/%u/%u = %u + %u = %u\n",
  2859. str,
  2860. byteclk,
  2861. t->hss, t->hsa, t->hse, t->hbp, pps, t->hfp,
  2862. bl, pps, tot,
  2863. TO_DSI_T(t->hss),
  2864. TO_DSI_T(t->hsa),
  2865. TO_DSI_T(t->hse),
  2866. TO_DSI_T(t->hbp),
  2867. TO_DSI_T(pps),
  2868. TO_DSI_T(t->hfp),
  2869. TO_DSI_T(bl),
  2870. TO_DSI_T(pps),
  2871. TO_DSI_T(tot));
  2872. #undef TO_DSI_T
  2873. }
  2874. static void print_dispc_vm(const char *str, const struct videomode *vm)
  2875. {
  2876. unsigned long pck = vm->pixelclock;
  2877. int hact, bl, tot;
  2878. hact = vm->hactive;
  2879. bl = vm->hsync_len + vm->hback_porch + vm->hfront_porch;
  2880. tot = hact + bl;
  2881. #define TO_DISPC_T(x) ((u32)div64_u64((u64)x * 1000000000llu, pck))
  2882. pr_debug("%s pck %lu, %u/%u/%u/%u = %u+%u = %u, "
  2883. "%u/%u/%u/%u = %u + %u = %u\n",
  2884. str,
  2885. pck,
  2886. vm->hsync_len, vm->hback_porch, hact, vm->hfront_porch,
  2887. bl, hact, tot,
  2888. TO_DISPC_T(vm->hsync_len),
  2889. TO_DISPC_T(vm->hback_porch),
  2890. TO_DISPC_T(hact),
  2891. TO_DISPC_T(vm->hfront_porch),
  2892. TO_DISPC_T(bl),
  2893. TO_DISPC_T(hact),
  2894. TO_DISPC_T(tot));
  2895. #undef TO_DISPC_T
  2896. }
  2897. /* note: this is not quite accurate */
  2898. static void print_dsi_dispc_vm(const char *str,
  2899. const struct omap_dss_dsi_videomode_timings *t)
  2900. {
  2901. struct videomode vm = { 0 };
  2902. unsigned long byteclk = t->hsclk / 4;
  2903. unsigned long pck;
  2904. u64 dsi_tput;
  2905. int dsi_hact, dsi_htot;
  2906. dsi_tput = (u64)byteclk * t->ndl * 8;
  2907. pck = (u32)div64_u64(dsi_tput, t->bitspp);
  2908. dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(t->hact * t->bitspp, 8) + 6, t->ndl);
  2909. dsi_htot = t->hss + t->hsa + t->hse + t->hbp + dsi_hact + t->hfp;
  2910. vm.pixelclock = pck;
  2911. vm.hsync_len = div64_u64((u64)(t->hsa + t->hse) * pck, byteclk);
  2912. vm.hback_porch = div64_u64((u64)t->hbp * pck, byteclk);
  2913. vm.hfront_porch = div64_u64((u64)t->hfp * pck, byteclk);
  2914. vm.hactive = t->hact;
  2915. print_dispc_vm(str, &vm);
  2916. }
  2917. #endif /* PRINT_VERBOSE_VM_TIMINGS */
  2918. static bool dsi_cm_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
  2919. unsigned long pck, void *data)
  2920. {
  2921. struct dsi_clk_calc_ctx *ctx = data;
  2922. struct videomode *vm = &ctx->vm;
  2923. ctx->dispc_cinfo.lck_div = lckd;
  2924. ctx->dispc_cinfo.pck_div = pckd;
  2925. ctx->dispc_cinfo.lck = lck;
  2926. ctx->dispc_cinfo.pck = pck;
  2927. *vm = *ctx->config->vm;
  2928. vm->pixelclock = pck;
  2929. vm->hactive = ctx->config->vm->hactive;
  2930. vm->vactive = ctx->config->vm->vactive;
  2931. vm->hsync_len = vm->hfront_porch = vm->hback_porch = vm->vsync_len = 1;
  2932. vm->vfront_porch = vm->vback_porch = 0;
  2933. return true;
  2934. }
  2935. static bool dsi_cm_calc_hsdiv_cb(int m_dispc, unsigned long dispc,
  2936. void *data)
  2937. {
  2938. struct dsi_clk_calc_ctx *ctx = data;
  2939. ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc;
  2940. ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc;
  2941. return dispc_div_calc(ctx->dsi->dss->dispc, dispc,
  2942. ctx->req_pck_min, ctx->req_pck_max,
  2943. dsi_cm_calc_dispc_cb, ctx);
  2944. }
  2945. static bool dsi_cm_calc_pll_cb(int n, int m, unsigned long fint,
  2946. unsigned long clkdco, void *data)
  2947. {
  2948. struct dsi_clk_calc_ctx *ctx = data;
  2949. struct dsi_data *dsi = ctx->dsi;
  2950. ctx->dsi_cinfo.n = n;
  2951. ctx->dsi_cinfo.m = m;
  2952. ctx->dsi_cinfo.fint = fint;
  2953. ctx->dsi_cinfo.clkdco = clkdco;
  2954. return dss_pll_hsdiv_calc_a(ctx->pll, clkdco, ctx->req_pck_min,
  2955. dsi->data->max_fck_freq,
  2956. dsi_cm_calc_hsdiv_cb, ctx);
  2957. }
  2958. static bool dsi_cm_calc(struct dsi_data *dsi,
  2959. const struct omap_dss_dsi_config *cfg,
  2960. struct dsi_clk_calc_ctx *ctx)
  2961. {
  2962. unsigned long clkin;
  2963. int bitspp, ndl;
  2964. unsigned long pll_min, pll_max;
  2965. unsigned long pck, txbyteclk;
  2966. clkin = clk_get_rate(dsi->pll.clkin);
  2967. bitspp = mipi_dsi_pixel_format_to_bpp(cfg->pixel_format);
  2968. ndl = dsi->num_lanes_used - 1;
  2969. /*
  2970. * Here we should calculate minimum txbyteclk to be able to send the
  2971. * frame in time, and also to handle TE. That's not very simple, though,
  2972. * especially as we go to LP between each pixel packet due to HW
  2973. * "feature". So let's just estimate very roughly and multiply by 1.5.
  2974. */
  2975. pck = cfg->vm->pixelclock;
  2976. pck = pck * 3 / 2;
  2977. txbyteclk = pck * bitspp / 8 / ndl;
  2978. memset(ctx, 0, sizeof(*ctx));
  2979. ctx->dsi = dsi;
  2980. ctx->pll = &dsi->pll;
  2981. ctx->config = cfg;
  2982. ctx->req_pck_min = pck;
  2983. ctx->req_pck_nom = pck;
  2984. ctx->req_pck_max = pck * 3 / 2;
  2985. pll_min = max(cfg->hs_clk_min * 4, txbyteclk * 4 * 4);
  2986. pll_max = cfg->hs_clk_max * 4;
  2987. return dss_pll_calc_a(ctx->pll, clkin,
  2988. pll_min, pll_max,
  2989. dsi_cm_calc_pll_cb, ctx);
  2990. }
  2991. static bool dsi_vm_calc_blanking(struct dsi_clk_calc_ctx *ctx)
  2992. {
  2993. struct dsi_data *dsi = ctx->dsi;
  2994. const struct omap_dss_dsi_config *cfg = ctx->config;
  2995. int bitspp = mipi_dsi_pixel_format_to_bpp(cfg->pixel_format);
  2996. int ndl = dsi->num_lanes_used - 1;
  2997. unsigned long hsclk = ctx->dsi_cinfo.clkdco / 4;
  2998. unsigned long byteclk = hsclk / 4;
  2999. unsigned long dispc_pck, req_pck_min, req_pck_nom, req_pck_max;
  3000. int xres;
  3001. int panel_htot, panel_hbl; /* pixels */
  3002. int dispc_htot, dispc_hbl; /* pixels */
  3003. int dsi_htot, dsi_hact, dsi_hbl, hss, hse; /* byteclks */
  3004. int hfp, hsa, hbp;
  3005. const struct videomode *req_vm;
  3006. struct videomode *dispc_vm;
  3007. struct omap_dss_dsi_videomode_timings *dsi_vm;
  3008. u64 dsi_tput, dispc_tput;
  3009. dsi_tput = (u64)byteclk * ndl * 8;
  3010. req_vm = cfg->vm;
  3011. req_pck_min = ctx->req_pck_min;
  3012. req_pck_max = ctx->req_pck_max;
  3013. req_pck_nom = ctx->req_pck_nom;
  3014. dispc_pck = ctx->dispc_cinfo.pck;
  3015. dispc_tput = (u64)dispc_pck * bitspp;
  3016. xres = req_vm->hactive;
  3017. panel_hbl = req_vm->hfront_porch + req_vm->hback_porch +
  3018. req_vm->hsync_len;
  3019. panel_htot = xres + panel_hbl;
  3020. dsi_hact = DIV_ROUND_UP(DIV_ROUND_UP(xres * bitspp, 8) + 6, ndl);
  3021. /*
  3022. * When there are no line buffers, DISPC and DSI must have the
  3023. * same tput. Otherwise DISPC tput needs to be higher than DSI's.
  3024. */
  3025. if (dsi->line_buffer_size < xres * bitspp / 8) {
  3026. if (dispc_tput != dsi_tput)
  3027. return false;
  3028. } else {
  3029. if (dispc_tput < dsi_tput)
  3030. return false;
  3031. }
  3032. /* DSI tput must be over the min requirement */
  3033. if (dsi_tput < (u64)bitspp * req_pck_min)
  3034. return false;
  3035. /* When non-burst mode, DSI tput must be below max requirement. */
  3036. if (cfg->trans_mode != OMAP_DSS_DSI_BURST_MODE) {
  3037. if (dsi_tput > (u64)bitspp * req_pck_max)
  3038. return false;
  3039. }
  3040. hss = DIV_ROUND_UP(4, ndl);
  3041. if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) {
  3042. if (ndl == 3 && req_vm->hsync_len == 0)
  3043. hse = 1;
  3044. else
  3045. hse = DIV_ROUND_UP(4, ndl);
  3046. } else {
  3047. hse = 0;
  3048. }
  3049. /* DSI htot to match the panel's nominal pck */
  3050. dsi_htot = div64_u64((u64)panel_htot * byteclk, req_pck_nom);
  3051. /* fail if there would be no time for blanking */
  3052. if (dsi_htot < hss + hse + dsi_hact)
  3053. return false;
  3054. /* total DSI blanking needed to achieve panel's TL */
  3055. dsi_hbl = dsi_htot - dsi_hact;
  3056. /* DISPC htot to match the DSI TL */
  3057. dispc_htot = div64_u64((u64)dsi_htot * dispc_pck, byteclk);
  3058. /* verify that the DSI and DISPC TLs are the same */
  3059. if ((u64)dsi_htot * dispc_pck != (u64)dispc_htot * byteclk)
  3060. return false;
  3061. dispc_hbl = dispc_htot - xres;
  3062. /* setup DSI videomode */
  3063. dsi_vm = &ctx->dsi_vm;
  3064. memset(dsi_vm, 0, sizeof(*dsi_vm));
  3065. dsi_vm->hsclk = hsclk;
  3066. dsi_vm->ndl = ndl;
  3067. dsi_vm->bitspp = bitspp;
  3068. if (cfg->trans_mode != OMAP_DSS_DSI_PULSE_MODE) {
  3069. hsa = 0;
  3070. } else if (ndl == 3 && req_vm->hsync_len == 0) {
  3071. hsa = 0;
  3072. } else {
  3073. hsa = div64_u64((u64)req_vm->hsync_len * byteclk, req_pck_nom);
  3074. hsa = max(hsa - hse, 1);
  3075. }
  3076. hbp = div64_u64((u64)req_vm->hback_porch * byteclk, req_pck_nom);
  3077. hbp = max(hbp, 1);
  3078. hfp = dsi_hbl - (hss + hsa + hse + hbp);
  3079. if (hfp < 1) {
  3080. int t;
  3081. /* we need to take cycles from hbp */
  3082. t = 1 - hfp;
  3083. hbp = max(hbp - t, 1);
  3084. hfp = dsi_hbl - (hss + hsa + hse + hbp);
  3085. if (hfp < 1 && hsa > 0) {
  3086. /* we need to take cycles from hsa */
  3087. t = 1 - hfp;
  3088. hsa = max(hsa - t, 1);
  3089. hfp = dsi_hbl - (hss + hsa + hse + hbp);
  3090. }
  3091. }
  3092. if (hfp < 1)
  3093. return false;
  3094. dsi_vm->hss = hss;
  3095. dsi_vm->hsa = hsa;
  3096. dsi_vm->hse = hse;
  3097. dsi_vm->hbp = hbp;
  3098. dsi_vm->hact = xres;
  3099. dsi_vm->hfp = hfp;
  3100. dsi_vm->vsa = req_vm->vsync_len;
  3101. dsi_vm->vbp = req_vm->vback_porch;
  3102. dsi_vm->vact = req_vm->vactive;
  3103. dsi_vm->vfp = req_vm->vfront_porch;
  3104. dsi_vm->trans_mode = cfg->trans_mode;
  3105. dsi_vm->blanking_mode = 0;
  3106. dsi_vm->hsa_blanking_mode = 1;
  3107. dsi_vm->hfp_blanking_mode = 1;
  3108. dsi_vm->hbp_blanking_mode = 1;
  3109. dsi_vm->window_sync = 4;
  3110. /* setup DISPC videomode */
  3111. dispc_vm = &ctx->vm;
  3112. *dispc_vm = *req_vm;
  3113. dispc_vm->pixelclock = dispc_pck;
  3114. if (cfg->trans_mode == OMAP_DSS_DSI_PULSE_MODE) {
  3115. hsa = div64_u64((u64)req_vm->hsync_len * dispc_pck,
  3116. req_pck_nom);
  3117. hsa = max(hsa, 1);
  3118. } else {
  3119. hsa = 1;
  3120. }
  3121. hbp = div64_u64((u64)req_vm->hback_porch * dispc_pck, req_pck_nom);
  3122. hbp = max(hbp, 1);
  3123. hfp = dispc_hbl - hsa - hbp;
  3124. if (hfp < 1) {
  3125. int t;
  3126. /* we need to take cycles from hbp */
  3127. t = 1 - hfp;
  3128. hbp = max(hbp - t, 1);
  3129. hfp = dispc_hbl - hsa - hbp;
  3130. if (hfp < 1) {
  3131. /* we need to take cycles from hsa */
  3132. t = 1 - hfp;
  3133. hsa = max(hsa - t, 1);
  3134. hfp = dispc_hbl - hsa - hbp;
  3135. }
  3136. }
  3137. if (hfp < 1)
  3138. return false;
  3139. dispc_vm->hfront_porch = hfp;
  3140. dispc_vm->hsync_len = hsa;
  3141. dispc_vm->hback_porch = hbp;
  3142. return true;
  3143. }
  3144. static bool dsi_vm_calc_dispc_cb(int lckd, int pckd, unsigned long lck,
  3145. unsigned long pck, void *data)
  3146. {
  3147. struct dsi_clk_calc_ctx *ctx = data;
  3148. ctx->dispc_cinfo.lck_div = lckd;
  3149. ctx->dispc_cinfo.pck_div = pckd;
  3150. ctx->dispc_cinfo.lck = lck;
  3151. ctx->dispc_cinfo.pck = pck;
  3152. if (dsi_vm_calc_blanking(ctx) == false)
  3153. return false;
  3154. #ifdef PRINT_VERBOSE_VM_TIMINGS
  3155. print_dispc_vm("dispc", &ctx->vm);
  3156. print_dsi_vm("dsi ", &ctx->dsi_vm);
  3157. print_dispc_vm("req ", ctx->config->vm);
  3158. print_dsi_dispc_vm("act ", &ctx->dsi_vm);
  3159. #endif
  3160. return true;
  3161. }
  3162. static bool dsi_vm_calc_hsdiv_cb(int m_dispc, unsigned long dispc,
  3163. void *data)
  3164. {
  3165. struct dsi_clk_calc_ctx *ctx = data;
  3166. unsigned long pck_max;
  3167. ctx->dsi_cinfo.mX[HSDIV_DISPC] = m_dispc;
  3168. ctx->dsi_cinfo.clkout[HSDIV_DISPC] = dispc;
  3169. /*
  3170. * In burst mode we can let the dispc pck be arbitrarily high, but it
  3171. * limits our scaling abilities. So for now, don't aim too high.
  3172. */
  3173. if (ctx->config->trans_mode == OMAP_DSS_DSI_BURST_MODE)
  3174. pck_max = ctx->req_pck_max + 10000000;
  3175. else
  3176. pck_max = ctx->req_pck_max;
  3177. return dispc_div_calc(ctx->dsi->dss->dispc, dispc,
  3178. ctx->req_pck_min, pck_max,
  3179. dsi_vm_calc_dispc_cb, ctx);
  3180. }
  3181. static bool dsi_vm_calc_pll_cb(int n, int m, unsigned long fint,
  3182. unsigned long clkdco, void *data)
  3183. {
  3184. struct dsi_clk_calc_ctx *ctx = data;
  3185. struct dsi_data *dsi = ctx->dsi;
  3186. ctx->dsi_cinfo.n = n;
  3187. ctx->dsi_cinfo.m = m;
  3188. ctx->dsi_cinfo.fint = fint;
  3189. ctx->dsi_cinfo.clkdco = clkdco;
  3190. return dss_pll_hsdiv_calc_a(ctx->pll, clkdco, ctx->req_pck_min,
  3191. dsi->data->max_fck_freq,
  3192. dsi_vm_calc_hsdiv_cb, ctx);
  3193. }
  3194. static bool dsi_vm_calc(struct dsi_data *dsi,
  3195. const struct omap_dss_dsi_config *cfg,
  3196. struct dsi_clk_calc_ctx *ctx)
  3197. {
  3198. const struct videomode *vm = cfg->vm;
  3199. unsigned long clkin;
  3200. unsigned long pll_min;
  3201. unsigned long pll_max;
  3202. int ndl = dsi->num_lanes_used - 1;
  3203. int bitspp = mipi_dsi_pixel_format_to_bpp(cfg->pixel_format);
  3204. unsigned long byteclk_min;
  3205. clkin = clk_get_rate(dsi->pll.clkin);
  3206. memset(ctx, 0, sizeof(*ctx));
  3207. ctx->dsi = dsi;
  3208. ctx->pll = &dsi->pll;
  3209. ctx->config = cfg;
  3210. /* these limits should come from the panel driver */
  3211. ctx->req_pck_min = vm->pixelclock - 1000;
  3212. ctx->req_pck_nom = vm->pixelclock;
  3213. ctx->req_pck_max = vm->pixelclock + 1000;
  3214. byteclk_min = div64_u64((u64)ctx->req_pck_min * bitspp, ndl * 8);
  3215. pll_min = max(cfg->hs_clk_min * 4, byteclk_min * 4 * 4);
  3216. if (cfg->trans_mode == OMAP_DSS_DSI_BURST_MODE) {
  3217. pll_max = cfg->hs_clk_max * 4;
  3218. } else {
  3219. unsigned long byteclk_max;
  3220. byteclk_max = div64_u64((u64)ctx->req_pck_max * bitspp,
  3221. ndl * 8);
  3222. pll_max = byteclk_max * 4 * 4;
  3223. }
  3224. return dss_pll_calc_a(ctx->pll, clkin,
  3225. pll_min, pll_max,
  3226. dsi_vm_calc_pll_cb, ctx);
  3227. }
  3228. static bool dsi_is_video_mode(struct omap_dss_device *dssdev)
  3229. {
  3230. struct dsi_data *dsi = to_dsi_data(dssdev);
  3231. return dsi->mode == OMAP_DSS_DSI_VIDEO_MODE;
  3232. }
  3233. static int __dsi_calc_config(struct dsi_data *dsi,
  3234. const struct drm_display_mode *mode,
  3235. struct dsi_clk_calc_ctx *ctx)
  3236. {
  3237. struct omap_dss_dsi_config cfg = dsi->config;
  3238. struct videomode vm;
  3239. bool ok;
  3240. int r;
  3241. drm_display_mode_to_videomode(mode, &vm);
  3242. cfg.vm = &vm;
  3243. cfg.mode = dsi->mode;
  3244. cfg.pixel_format = dsi->pix_fmt;
  3245. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE)
  3246. ok = dsi_vm_calc(dsi, &cfg, ctx);
  3247. else
  3248. ok = dsi_cm_calc(dsi, &cfg, ctx);
  3249. if (!ok)
  3250. return -EINVAL;
  3251. dsi_pll_calc_dsi_fck(dsi, &ctx->dsi_cinfo);
  3252. r = dsi_lp_clock_calc(ctx->dsi_cinfo.clkout[HSDIV_DSI],
  3253. cfg.lp_clk_min, cfg.lp_clk_max, &ctx->lp_cinfo);
  3254. if (r)
  3255. return r;
  3256. return 0;
  3257. }
  3258. static int dsi_set_config(struct omap_dss_device *dssdev,
  3259. const struct drm_display_mode *mode)
  3260. {
  3261. struct dsi_data *dsi = to_dsi_data(dssdev);
  3262. struct dsi_clk_calc_ctx ctx;
  3263. int r;
  3264. mutex_lock(&dsi->lock);
  3265. r = __dsi_calc_config(dsi, mode, &ctx);
  3266. if (r) {
  3267. DSSERR("failed to find suitable DSI clock settings\n");
  3268. goto err;
  3269. }
  3270. dsi->user_lp_cinfo = ctx.lp_cinfo;
  3271. dsi->user_dsi_cinfo = ctx.dsi_cinfo;
  3272. dsi->user_dispc_cinfo = ctx.dispc_cinfo;
  3273. dsi->vm = ctx.vm;
  3274. /*
  3275. * override interlace, logic level and edge related parameters in
  3276. * videomode with default values
  3277. */
  3278. dsi->vm.flags &= ~DISPLAY_FLAGS_INTERLACED;
  3279. dsi->vm.flags &= ~DISPLAY_FLAGS_HSYNC_LOW;
  3280. dsi->vm.flags |= DISPLAY_FLAGS_HSYNC_HIGH;
  3281. dsi->vm.flags &= ~DISPLAY_FLAGS_VSYNC_LOW;
  3282. dsi->vm.flags |= DISPLAY_FLAGS_VSYNC_HIGH;
  3283. /*
  3284. * HACK: These flags should be handled through the omap_dss_device bus
  3285. * flags, but this will only be possible when the DSI encoder will be
  3286. * converted to the omapdrm-managed encoder model.
  3287. */
  3288. dsi->vm.flags &= ~DISPLAY_FLAGS_PIXDATA_NEGEDGE;
  3289. dsi->vm.flags |= DISPLAY_FLAGS_PIXDATA_POSEDGE;
  3290. dsi->vm.flags &= ~DISPLAY_FLAGS_DE_LOW;
  3291. dsi->vm.flags |= DISPLAY_FLAGS_DE_HIGH;
  3292. dsi->vm.flags &= ~DISPLAY_FLAGS_SYNC_POSEDGE;
  3293. dsi->vm.flags |= DISPLAY_FLAGS_SYNC_NEGEDGE;
  3294. dss_mgr_set_timings(&dsi->output, &dsi->vm);
  3295. dsi->vm_timings = ctx.dsi_vm;
  3296. mutex_unlock(&dsi->lock);
  3297. return 0;
  3298. err:
  3299. mutex_unlock(&dsi->lock);
  3300. return r;
  3301. }
  3302. /*
  3303. * Return a hardcoded dispc channel for the DSI output. This should work for
  3304. * current use cases, but this can be later expanded to either resolve
  3305. * the channel in some more dynamic manner, or get the channel as a user
  3306. * parameter.
  3307. */
  3308. static enum omap_channel dsi_get_dispc_channel(struct dsi_data *dsi)
  3309. {
  3310. switch (dsi->data->model) {
  3311. case DSI_MODEL_OMAP3:
  3312. return OMAP_DSS_CHANNEL_LCD;
  3313. case DSI_MODEL_OMAP4:
  3314. switch (dsi->module_id) {
  3315. case 0:
  3316. return OMAP_DSS_CHANNEL_LCD;
  3317. case 1:
  3318. return OMAP_DSS_CHANNEL_LCD2;
  3319. default:
  3320. DSSWARN("unsupported module id\n");
  3321. return OMAP_DSS_CHANNEL_LCD;
  3322. }
  3323. case DSI_MODEL_OMAP5:
  3324. switch (dsi->module_id) {
  3325. case 0:
  3326. return OMAP_DSS_CHANNEL_LCD;
  3327. case 1:
  3328. return OMAP_DSS_CHANNEL_LCD3;
  3329. default:
  3330. DSSWARN("unsupported module id\n");
  3331. return OMAP_DSS_CHANNEL_LCD;
  3332. }
  3333. default:
  3334. DSSWARN("unsupported DSS version\n");
  3335. return OMAP_DSS_CHANNEL_LCD;
  3336. }
  3337. }
  3338. static ssize_t _omap_dsi_host_transfer(struct dsi_data *dsi, int vc,
  3339. const struct mipi_dsi_msg *msg)
  3340. {
  3341. struct omap_dss_device *dssdev = &dsi->output;
  3342. int r;
  3343. dsi_vc_enable_hs(dssdev, vc, !(msg->flags & MIPI_DSI_MSG_USE_LPM));
  3344. switch (msg->type) {
  3345. case MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM:
  3346. case MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM:
  3347. case MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM:
  3348. case MIPI_DSI_GENERIC_LONG_WRITE:
  3349. case MIPI_DSI_DCS_SHORT_WRITE:
  3350. case MIPI_DSI_DCS_SHORT_WRITE_PARAM:
  3351. case MIPI_DSI_DCS_LONG_WRITE:
  3352. case MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE:
  3353. case MIPI_DSI_NULL_PACKET:
  3354. r = dsi_vc_write_common(dssdev, vc, msg);
  3355. break;
  3356. case MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM:
  3357. case MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM:
  3358. case MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM:
  3359. r = dsi_vc_generic_read(dssdev, vc, msg);
  3360. break;
  3361. case MIPI_DSI_DCS_READ:
  3362. r = dsi_vc_dcs_read(dssdev, vc, msg);
  3363. break;
  3364. default:
  3365. r = -EINVAL;
  3366. break;
  3367. }
  3368. if (r < 0)
  3369. return r;
  3370. if (msg->type == MIPI_DSI_DCS_SHORT_WRITE ||
  3371. msg->type == MIPI_DSI_DCS_SHORT_WRITE_PARAM) {
  3372. u8 cmd = ((u8 *)msg->tx_buf)[0];
  3373. if (cmd == MIPI_DCS_SET_TEAR_OFF)
  3374. dsi_enable_te(dsi, false);
  3375. else if (cmd == MIPI_DCS_SET_TEAR_ON)
  3376. dsi_enable_te(dsi, true);
  3377. }
  3378. return 0;
  3379. }
  3380. static ssize_t omap_dsi_host_transfer(struct mipi_dsi_host *host,
  3381. const struct mipi_dsi_msg *msg)
  3382. {
  3383. struct dsi_data *dsi = host_to_omap(host);
  3384. int r;
  3385. int vc = VC_CMD;
  3386. dsi_bus_lock(dsi);
  3387. if (!dsi->iface_enabled) {
  3388. dsi_enable(dsi);
  3389. schedule_delayed_work(&dsi->dsi_disable_work, msecs_to_jiffies(2000));
  3390. }
  3391. r = _omap_dsi_host_transfer(dsi, vc, msg);
  3392. dsi_bus_unlock(dsi);
  3393. return r;
  3394. }
  3395. static int dsi_get_clocks(struct dsi_data *dsi)
  3396. {
  3397. struct clk *clk;
  3398. clk = devm_clk_get(dsi->dev, "fck");
  3399. if (IS_ERR(clk)) {
  3400. DSSERR("can't get fck\n");
  3401. return PTR_ERR(clk);
  3402. }
  3403. dsi->dss_clk = clk;
  3404. return 0;
  3405. }
  3406. static const struct omapdss_dsi_ops dsi_ops = {
  3407. .update = dsi_update_all,
  3408. .is_video_mode = dsi_is_video_mode,
  3409. };
  3410. static irqreturn_t omap_dsi_te_irq_handler(int irq, void *dev_id)
  3411. {
  3412. struct dsi_data *dsi = (struct dsi_data *)dev_id;
  3413. int old;
  3414. old = atomic_cmpxchg(&dsi->do_ext_te_update, 1, 0);
  3415. if (old) {
  3416. cancel_delayed_work(&dsi->te_timeout_work);
  3417. _dsi_update(dsi);
  3418. }
  3419. return IRQ_HANDLED;
  3420. }
  3421. static void omap_dsi_te_timeout_work_callback(struct work_struct *work)
  3422. {
  3423. struct dsi_data *dsi =
  3424. container_of(work, struct dsi_data, te_timeout_work.work);
  3425. int old;
  3426. old = atomic_cmpxchg(&dsi->do_ext_te_update, 1, 0);
  3427. if (old) {
  3428. dev_err(dsi->dev, "TE not received for 250ms!\n");
  3429. _dsi_update(dsi);
  3430. }
  3431. }
  3432. static int omap_dsi_register_te_irq(struct dsi_data *dsi,
  3433. struct mipi_dsi_device *client)
  3434. {
  3435. int err;
  3436. int te_irq;
  3437. dsi->te_gpio = gpiod_get(&client->dev, "te-gpios", GPIOD_IN);
  3438. if (IS_ERR(dsi->te_gpio)) {
  3439. err = PTR_ERR(dsi->te_gpio);
  3440. if (err == -ENOENT) {
  3441. dsi->te_gpio = NULL;
  3442. return 0;
  3443. }
  3444. dev_err(dsi->dev, "Could not get TE gpio: %d\n", err);
  3445. return err;
  3446. }
  3447. te_irq = gpiod_to_irq(dsi->te_gpio);
  3448. if (te_irq < 0) {
  3449. gpiod_put(dsi->te_gpio);
  3450. dsi->te_gpio = NULL;
  3451. return -EINVAL;
  3452. }
  3453. dsi->te_irq = te_irq;
  3454. irq_set_status_flags(te_irq, IRQ_NOAUTOEN);
  3455. err = request_threaded_irq(te_irq, NULL, omap_dsi_te_irq_handler,
  3456. IRQF_TRIGGER_RISING | IRQF_ONESHOT,
  3457. "TE", dsi);
  3458. if (err) {
  3459. dev_err(dsi->dev, "request irq failed with %d\n", err);
  3460. gpiod_put(dsi->te_gpio);
  3461. dsi->te_gpio = NULL;
  3462. return err;
  3463. }
  3464. INIT_DEFERRABLE_WORK(&dsi->te_timeout_work,
  3465. omap_dsi_te_timeout_work_callback);
  3466. dev_dbg(dsi->dev, "Using GPIO TE\n");
  3467. return 0;
  3468. }
  3469. static void omap_dsi_unregister_te_irq(struct dsi_data *dsi)
  3470. {
  3471. if (dsi->te_gpio) {
  3472. free_irq(dsi->te_irq, dsi);
  3473. cancel_delayed_work(&dsi->te_timeout_work);
  3474. gpiod_put(dsi->te_gpio);
  3475. dsi->te_gpio = NULL;
  3476. }
  3477. }
  3478. static int omap_dsi_host_attach(struct mipi_dsi_host *host,
  3479. struct mipi_dsi_device *client)
  3480. {
  3481. struct dsi_data *dsi = host_to_omap(host);
  3482. int r;
  3483. if (dsi->dsidev) {
  3484. DSSERR("dsi client already attached\n");
  3485. return -EBUSY;
  3486. }
  3487. if (mipi_dsi_pixel_format_to_bpp(client->format) < 0) {
  3488. DSSERR("invalid pixel format\n");
  3489. return -EINVAL;
  3490. }
  3491. atomic_set(&dsi->do_ext_te_update, 0);
  3492. if (client->mode_flags & MIPI_DSI_MODE_VIDEO) {
  3493. dsi->mode = OMAP_DSS_DSI_VIDEO_MODE;
  3494. } else {
  3495. r = omap_dsi_register_te_irq(dsi, client);
  3496. if (r)
  3497. return r;
  3498. dsi->mode = OMAP_DSS_DSI_CMD_MODE;
  3499. }
  3500. dsi->dsidev = client;
  3501. dsi->pix_fmt = client->format;
  3502. dsi->config.hs_clk_min = 150000000; // TODO: get from client?
  3503. dsi->config.hs_clk_max = client->hs_rate;
  3504. dsi->config.lp_clk_min = 7000000; // TODO: get from client?
  3505. dsi->config.lp_clk_max = client->lp_rate;
  3506. if (client->mode_flags & MIPI_DSI_MODE_VIDEO_BURST)
  3507. dsi->config.trans_mode = OMAP_DSS_DSI_BURST_MODE;
  3508. else if (client->mode_flags & MIPI_DSI_MODE_VIDEO_SYNC_PULSE)
  3509. dsi->config.trans_mode = OMAP_DSS_DSI_PULSE_MODE;
  3510. else
  3511. dsi->config.trans_mode = OMAP_DSS_DSI_EVENT_MODE;
  3512. return 0;
  3513. }
  3514. static int omap_dsi_host_detach(struct mipi_dsi_host *host,
  3515. struct mipi_dsi_device *client)
  3516. {
  3517. struct dsi_data *dsi = host_to_omap(host);
  3518. if (WARN_ON(dsi->dsidev != client))
  3519. return -EINVAL;
  3520. cancel_delayed_work_sync(&dsi->dsi_disable_work);
  3521. dsi_bus_lock(dsi);
  3522. if (dsi->iface_enabled)
  3523. dsi_disable(dsi);
  3524. dsi_bus_unlock(dsi);
  3525. omap_dsi_unregister_te_irq(dsi);
  3526. dsi->dsidev = NULL;
  3527. return 0;
  3528. }
  3529. static const struct mipi_dsi_host_ops omap_dsi_host_ops = {
  3530. .attach = omap_dsi_host_attach,
  3531. .detach = omap_dsi_host_detach,
  3532. .transfer = omap_dsi_host_transfer,
  3533. };
  3534. /* -----------------------------------------------------------------------------
  3535. * PLL
  3536. */
  3537. static const struct dss_pll_ops dsi_pll_ops = {
  3538. .enable = dsi_pll_enable,
  3539. .disable = dsi_pll_disable,
  3540. .set_config = dss_pll_write_config_type_a,
  3541. };
  3542. static const struct dss_pll_hw dss_omap3_dsi_pll_hw = {
  3543. .type = DSS_PLL_TYPE_A,
  3544. .n_max = (1 << 7) - 1,
  3545. .m_max = (1 << 11) - 1,
  3546. .mX_max = (1 << 4) - 1,
  3547. .fint_min = 750000,
  3548. .fint_max = 2100000,
  3549. .clkdco_low = 1000000000,
  3550. .clkdco_max = 1800000000,
  3551. .n_msb = 7,
  3552. .n_lsb = 1,
  3553. .m_msb = 18,
  3554. .m_lsb = 8,
  3555. .mX_msb[0] = 22,
  3556. .mX_lsb[0] = 19,
  3557. .mX_msb[1] = 26,
  3558. .mX_lsb[1] = 23,
  3559. .has_stopmode = true,
  3560. .has_freqsel = true,
  3561. .has_selfreqdco = false,
  3562. .has_refsel = false,
  3563. };
  3564. static const struct dss_pll_hw dss_omap4_dsi_pll_hw = {
  3565. .type = DSS_PLL_TYPE_A,
  3566. .n_max = (1 << 8) - 1,
  3567. .m_max = (1 << 12) - 1,
  3568. .mX_max = (1 << 5) - 1,
  3569. .fint_min = 500000,
  3570. .fint_max = 2500000,
  3571. .clkdco_low = 1000000000,
  3572. .clkdco_max = 1800000000,
  3573. .n_msb = 8,
  3574. .n_lsb = 1,
  3575. .m_msb = 20,
  3576. .m_lsb = 9,
  3577. .mX_msb[0] = 25,
  3578. .mX_lsb[0] = 21,
  3579. .mX_msb[1] = 30,
  3580. .mX_lsb[1] = 26,
  3581. .has_stopmode = true,
  3582. .has_freqsel = false,
  3583. .has_selfreqdco = false,
  3584. .has_refsel = false,
  3585. };
  3586. static const struct dss_pll_hw dss_omap5_dsi_pll_hw = {
  3587. .type = DSS_PLL_TYPE_A,
  3588. .n_max = (1 << 8) - 1,
  3589. .m_max = (1 << 12) - 1,
  3590. .mX_max = (1 << 5) - 1,
  3591. .fint_min = 150000,
  3592. .fint_max = 52000000,
  3593. .clkdco_low = 1000000000,
  3594. .clkdco_max = 1800000000,
  3595. .n_msb = 8,
  3596. .n_lsb = 1,
  3597. .m_msb = 20,
  3598. .m_lsb = 9,
  3599. .mX_msb[0] = 25,
  3600. .mX_lsb[0] = 21,
  3601. .mX_msb[1] = 30,
  3602. .mX_lsb[1] = 26,
  3603. .has_stopmode = true,
  3604. .has_freqsel = false,
  3605. .has_selfreqdco = true,
  3606. .has_refsel = true,
  3607. };
  3608. static int dsi_init_pll_data(struct dss_device *dss, struct dsi_data *dsi)
  3609. {
  3610. struct dss_pll *pll = &dsi->pll;
  3611. struct clk *clk;
  3612. int r;
  3613. clk = devm_clk_get(dsi->dev, "sys_clk");
  3614. if (IS_ERR(clk)) {
  3615. DSSERR("can't get sys_clk\n");
  3616. return PTR_ERR(clk);
  3617. }
  3618. pll->name = dsi->module_id == 0 ? "dsi0" : "dsi1";
  3619. pll->id = dsi->module_id == 0 ? DSS_PLL_DSI1 : DSS_PLL_DSI2;
  3620. pll->clkin = clk;
  3621. pll->base = dsi->pll_base;
  3622. pll->hw = dsi->data->pll_hw;
  3623. pll->ops = &dsi_pll_ops;
  3624. r = dss_pll_register(dss, pll);
  3625. if (r)
  3626. return r;
  3627. return 0;
  3628. }
  3629. /* -----------------------------------------------------------------------------
  3630. * Component Bind & Unbind
  3631. */
  3632. static int dsi_bind(struct device *dev, struct device *master, void *data)
  3633. {
  3634. struct dss_device *dss = dss_get_device(master);
  3635. struct dsi_data *dsi = dev_get_drvdata(dev);
  3636. char name[10];
  3637. u32 rev;
  3638. int r;
  3639. dsi->dss = dss;
  3640. dsi_init_pll_data(dss, dsi);
  3641. r = dsi_runtime_get(dsi);
  3642. if (r)
  3643. return r;
  3644. rev = dsi_read_reg(dsi, DSI_REVISION);
  3645. dev_dbg(dev, "OMAP DSI rev %d.%d\n",
  3646. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3647. dsi->line_buffer_size = dsi_get_line_buf_size(dsi);
  3648. dsi_runtime_put(dsi);
  3649. snprintf(name, sizeof(name), "dsi%u_regs", dsi->module_id + 1);
  3650. dsi->debugfs.regs = dss_debugfs_create_file(dss, name,
  3651. dsi_dump_dsi_regs, dsi);
  3652. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3653. snprintf(name, sizeof(name), "dsi%u_irqs", dsi->module_id + 1);
  3654. dsi->debugfs.irqs = dss_debugfs_create_file(dss, name,
  3655. dsi_dump_dsi_irqs, dsi);
  3656. #endif
  3657. snprintf(name, sizeof(name), "dsi%u_clks", dsi->module_id + 1);
  3658. dsi->debugfs.clks = dss_debugfs_create_file(dss, name,
  3659. dsi_dump_dsi_clocks, dsi);
  3660. return 0;
  3661. }
  3662. static void dsi_unbind(struct device *dev, struct device *master, void *data)
  3663. {
  3664. struct dsi_data *dsi = dev_get_drvdata(dev);
  3665. dss_debugfs_remove_file(dsi->debugfs.clks);
  3666. dss_debugfs_remove_file(dsi->debugfs.irqs);
  3667. dss_debugfs_remove_file(dsi->debugfs.regs);
  3668. WARN_ON(dsi->scp_clk_refcount > 0);
  3669. dss_pll_unregister(&dsi->pll);
  3670. }
  3671. static const struct component_ops dsi_component_ops = {
  3672. .bind = dsi_bind,
  3673. .unbind = dsi_unbind,
  3674. };
  3675. /* -----------------------------------------------------------------------------
  3676. * DRM Bridge Operations
  3677. */
  3678. static int dsi_bridge_attach(struct drm_bridge *bridge,
  3679. struct drm_encoder *encoder,
  3680. enum drm_bridge_attach_flags flags)
  3681. {
  3682. struct dsi_data *dsi = drm_bridge_to_dsi(bridge);
  3683. if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
  3684. return -EINVAL;
  3685. return drm_bridge_attach(encoder, dsi->output.next_bridge,
  3686. bridge, flags);
  3687. }
  3688. static enum drm_mode_status
  3689. dsi_bridge_mode_valid(struct drm_bridge *bridge,
  3690. const struct drm_display_info *info,
  3691. const struct drm_display_mode *mode)
  3692. {
  3693. struct dsi_data *dsi = drm_bridge_to_dsi(bridge);
  3694. struct dsi_clk_calc_ctx ctx;
  3695. int r;
  3696. mutex_lock(&dsi->lock);
  3697. r = __dsi_calc_config(dsi, mode, &ctx);
  3698. mutex_unlock(&dsi->lock);
  3699. return r ? MODE_CLOCK_RANGE : MODE_OK;
  3700. }
  3701. static void dsi_bridge_mode_set(struct drm_bridge *bridge,
  3702. const struct drm_display_mode *mode,
  3703. const struct drm_display_mode *adjusted_mode)
  3704. {
  3705. struct dsi_data *dsi = drm_bridge_to_dsi(bridge);
  3706. dsi_set_config(&dsi->output, adjusted_mode);
  3707. }
  3708. static void dsi_bridge_enable(struct drm_bridge *bridge)
  3709. {
  3710. struct dsi_data *dsi = drm_bridge_to_dsi(bridge);
  3711. struct omap_dss_device *dssdev = &dsi->output;
  3712. cancel_delayed_work_sync(&dsi->dsi_disable_work);
  3713. dsi_bus_lock(dsi);
  3714. if (!dsi->iface_enabled)
  3715. dsi_enable(dsi);
  3716. dsi_enable_video_output(dssdev, VC_VIDEO);
  3717. dsi->video_enabled = true;
  3718. dsi_bus_unlock(dsi);
  3719. }
  3720. static void dsi_bridge_disable(struct drm_bridge *bridge)
  3721. {
  3722. struct dsi_data *dsi = drm_bridge_to_dsi(bridge);
  3723. struct omap_dss_device *dssdev = &dsi->output;
  3724. cancel_delayed_work_sync(&dsi->dsi_disable_work);
  3725. dsi_bus_lock(dsi);
  3726. dsi->video_enabled = false;
  3727. dsi_disable_video_output(dssdev, VC_VIDEO);
  3728. dsi_disable(dsi);
  3729. dsi_bus_unlock(dsi);
  3730. }
  3731. static const struct drm_bridge_funcs dsi_bridge_funcs = {
  3732. .attach = dsi_bridge_attach,
  3733. .mode_valid = dsi_bridge_mode_valid,
  3734. .mode_set = dsi_bridge_mode_set,
  3735. .enable = dsi_bridge_enable,
  3736. .disable = dsi_bridge_disable,
  3737. };
  3738. static void dsi_bridge_init(struct dsi_data *dsi)
  3739. {
  3740. dsi->bridge.of_node = dsi->host.dev->of_node;
  3741. dsi->bridge.type = DRM_MODE_CONNECTOR_DSI;
  3742. drm_bridge_add(&dsi->bridge);
  3743. }
  3744. static void dsi_bridge_cleanup(struct dsi_data *dsi)
  3745. {
  3746. drm_bridge_remove(&dsi->bridge);
  3747. }
  3748. /* -----------------------------------------------------------------------------
  3749. * Probe & Remove, Suspend & Resume
  3750. */
  3751. static int dsi_init_output(struct dsi_data *dsi)
  3752. {
  3753. struct omap_dss_device *out = &dsi->output;
  3754. int r;
  3755. dsi_bridge_init(dsi);
  3756. out->dev = dsi->dev;
  3757. out->id = dsi->module_id == 0 ?
  3758. OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
  3759. out->type = OMAP_DISPLAY_TYPE_DSI;
  3760. out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
  3761. out->dispc_channel = dsi_get_dispc_channel(dsi);
  3762. out->dsi_ops = &dsi_ops;
  3763. out->of_port = 0;
  3764. out->bus_flags = DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE
  3765. | DRM_BUS_FLAG_DE_HIGH
  3766. | DRM_BUS_FLAG_SYNC_DRIVE_NEGEDGE;
  3767. r = omapdss_device_init_output(out, &dsi->bridge);
  3768. if (r < 0) {
  3769. dsi_bridge_cleanup(dsi);
  3770. return r;
  3771. }
  3772. omapdss_device_register(out);
  3773. return 0;
  3774. }
  3775. static void dsi_uninit_output(struct dsi_data *dsi)
  3776. {
  3777. struct omap_dss_device *out = &dsi->output;
  3778. omapdss_device_unregister(out);
  3779. omapdss_device_cleanup_output(out);
  3780. dsi_bridge_cleanup(dsi);
  3781. }
  3782. static int dsi_probe_of(struct dsi_data *dsi)
  3783. {
  3784. struct device_node *node = dsi->dev->of_node;
  3785. struct property *prop;
  3786. u32 lane_arr[10];
  3787. int len, num_pins;
  3788. int r;
  3789. struct device_node *ep;
  3790. ep = of_graph_get_endpoint_by_regs(node, 0, 0);
  3791. if (!ep)
  3792. return 0;
  3793. prop = of_find_property(ep, "lanes", &len);
  3794. if (prop == NULL) {
  3795. dev_err(dsi->dev, "failed to find lane data\n");
  3796. r = -EINVAL;
  3797. goto err;
  3798. }
  3799. num_pins = len / sizeof(u32);
  3800. if (num_pins < 4 || num_pins % 2 != 0 ||
  3801. num_pins > dsi->num_lanes_supported * 2) {
  3802. dev_err(dsi->dev, "bad number of lanes\n");
  3803. r = -EINVAL;
  3804. goto err;
  3805. }
  3806. r = of_property_read_u32_array(ep, "lanes", lane_arr, num_pins);
  3807. if (r) {
  3808. dev_err(dsi->dev, "failed to read lane data\n");
  3809. goto err;
  3810. }
  3811. r = dsi_configure_pins(dsi, num_pins, lane_arr);
  3812. if (r) {
  3813. dev_err(dsi->dev, "failed to configure pins");
  3814. goto err;
  3815. }
  3816. of_node_put(ep);
  3817. return 0;
  3818. err:
  3819. of_node_put(ep);
  3820. return r;
  3821. }
  3822. static const struct dsi_of_data dsi_of_data_omap34xx = {
  3823. .model = DSI_MODEL_OMAP3,
  3824. .pll_hw = &dss_omap3_dsi_pll_hw,
  3825. .modules = (const struct dsi_module_id_data[]) {
  3826. { .address = 0x4804fc00, .id = 0, },
  3827. { },
  3828. },
  3829. .max_fck_freq = 173000000,
  3830. .max_pll_lpdiv = (1 << 13) - 1,
  3831. .quirks = DSI_QUIRK_REVERSE_TXCLKESC,
  3832. };
  3833. static const struct dsi_of_data dsi_of_data_omap36xx = {
  3834. .model = DSI_MODEL_OMAP3,
  3835. .pll_hw = &dss_omap3_dsi_pll_hw,
  3836. .modules = (const struct dsi_module_id_data[]) {
  3837. { .address = 0x4804fc00, .id = 0, },
  3838. { },
  3839. },
  3840. .max_fck_freq = 173000000,
  3841. .max_pll_lpdiv = (1 << 13) - 1,
  3842. .quirks = DSI_QUIRK_PLL_PWR_BUG,
  3843. };
  3844. static const struct dsi_of_data dsi_of_data_omap4 = {
  3845. .model = DSI_MODEL_OMAP4,
  3846. .pll_hw = &dss_omap4_dsi_pll_hw,
  3847. .modules = (const struct dsi_module_id_data[]) {
  3848. { .address = 0x58004000, .id = 0, },
  3849. { .address = 0x58005000, .id = 1, },
  3850. { },
  3851. },
  3852. .max_fck_freq = 170000000,
  3853. .max_pll_lpdiv = (1 << 13) - 1,
  3854. .quirks = DSI_QUIRK_DCS_CMD_CONFIG_VC | DSI_QUIRK_VC_OCP_WIDTH
  3855. | DSI_QUIRK_GNQ,
  3856. };
  3857. static const struct dsi_of_data dsi_of_data_omap5 = {
  3858. .model = DSI_MODEL_OMAP5,
  3859. .pll_hw = &dss_omap5_dsi_pll_hw,
  3860. .modules = (const struct dsi_module_id_data[]) {
  3861. { .address = 0x58004000, .id = 0, },
  3862. { .address = 0x58009000, .id = 1, },
  3863. { },
  3864. },
  3865. .max_fck_freq = 209250000,
  3866. .max_pll_lpdiv = (1 << 13) - 1,
  3867. .quirks = DSI_QUIRK_DCS_CMD_CONFIG_VC | DSI_QUIRK_VC_OCP_WIDTH
  3868. | DSI_QUIRK_GNQ | DSI_QUIRK_PHY_DCC,
  3869. };
  3870. static const struct of_device_id dsi_of_match[] = {
  3871. { .compatible = "ti,omap3-dsi", .data = &dsi_of_data_omap36xx, },
  3872. { .compatible = "ti,omap4-dsi", .data = &dsi_of_data_omap4, },
  3873. { .compatible = "ti,omap5-dsi", .data = &dsi_of_data_omap5, },
  3874. {},
  3875. };
  3876. static const struct soc_device_attribute dsi_soc_devices[] = {
  3877. { .machine = "OMAP3[45]*", .data = &dsi_of_data_omap34xx },
  3878. { .machine = "AM35*", .data = &dsi_of_data_omap34xx },
  3879. { /* sentinel */ }
  3880. };
  3881. static void omap_dsi_disable_work_callback(struct work_struct *work)
  3882. {
  3883. struct dsi_data *dsi = container_of(work, struct dsi_data, dsi_disable_work.work);
  3884. dsi_bus_lock(dsi);
  3885. if (dsi->iface_enabled && !dsi->video_enabled)
  3886. dsi_disable(dsi);
  3887. dsi_bus_unlock(dsi);
  3888. }
  3889. static int dsi_probe(struct platform_device *pdev)
  3890. {
  3891. const struct soc_device_attribute *soc;
  3892. const struct dsi_module_id_data *d;
  3893. struct device *dev = &pdev->dev;
  3894. struct dsi_data *dsi;
  3895. struct resource *dsi_mem;
  3896. unsigned int i;
  3897. int r;
  3898. dsi = devm_drm_bridge_alloc(dev, struct dsi_data, bridge, &dsi_bridge_funcs);
  3899. if (IS_ERR(dsi))
  3900. return PTR_ERR(dsi);
  3901. dsi->dev = dev;
  3902. dev_set_drvdata(dev, dsi);
  3903. spin_lock_init(&dsi->irq_lock);
  3904. spin_lock_init(&dsi->errors_lock);
  3905. dsi->errors = 0;
  3906. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3907. spin_lock_init(&dsi->irq_stats_lock);
  3908. dsi->irq_stats.last_reset = jiffies;
  3909. #endif
  3910. mutex_init(&dsi->lock);
  3911. sema_init(&dsi->bus_lock, 1);
  3912. INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work,
  3913. dsi_framedone_timeout_work_callback);
  3914. INIT_DEFERRABLE_WORK(&dsi->dsi_disable_work, omap_dsi_disable_work_callback);
  3915. #ifdef DSI_CATCH_MISSING_TE
  3916. timer_setup(&dsi->te_timer, dsi_te_timeout, 0);
  3917. #endif
  3918. dsi_mem = platform_get_resource_byname(pdev, IORESOURCE_MEM, "proto");
  3919. dsi->proto_base = devm_ioremap_resource(dev, dsi_mem);
  3920. if (IS_ERR(dsi->proto_base))
  3921. return PTR_ERR(dsi->proto_base);
  3922. dsi->phy_base = devm_platform_ioremap_resource_byname(pdev, "phy");
  3923. if (IS_ERR(dsi->phy_base))
  3924. return PTR_ERR(dsi->phy_base);
  3925. dsi->pll_base = devm_platform_ioremap_resource_byname(pdev, "pll");
  3926. if (IS_ERR(dsi->pll_base))
  3927. return PTR_ERR(dsi->pll_base);
  3928. dsi->irq = platform_get_irq(pdev, 0);
  3929. if (dsi->irq < 0) {
  3930. DSSERR("platform_get_irq failed\n");
  3931. return -ENODEV;
  3932. }
  3933. r = devm_request_irq(dev, dsi->irq, omap_dsi_irq_handler,
  3934. IRQF_SHARED, dev_name(dev), dsi);
  3935. if (r < 0) {
  3936. DSSERR("request_irq failed\n");
  3937. return r;
  3938. }
  3939. dsi->vdds_dsi_reg = devm_regulator_get(dev, "vdd");
  3940. if (IS_ERR(dsi->vdds_dsi_reg)) {
  3941. if (PTR_ERR(dsi->vdds_dsi_reg) != -EPROBE_DEFER)
  3942. DSSERR("can't get DSI VDD regulator\n");
  3943. return PTR_ERR(dsi->vdds_dsi_reg);
  3944. }
  3945. soc = soc_device_match(dsi_soc_devices);
  3946. if (soc)
  3947. dsi->data = soc->data;
  3948. else
  3949. dsi->data = of_match_node(dsi_of_match, dev->of_node)->data;
  3950. d = dsi->data->modules;
  3951. while (d->address != 0 && d->address != dsi_mem->start)
  3952. d++;
  3953. if (d->address == 0) {
  3954. DSSERR("unsupported DSI module\n");
  3955. return -ENODEV;
  3956. }
  3957. dsi->module_id = d->id;
  3958. if (dsi->data->model == DSI_MODEL_OMAP4 ||
  3959. dsi->data->model == DSI_MODEL_OMAP5) {
  3960. struct device_node *np;
  3961. /*
  3962. * The OMAP4/5 display DT bindings don't reference the padconf
  3963. * syscon. Our only option to retrieve it is to find it by name.
  3964. */
  3965. np = of_find_node_by_name(NULL,
  3966. dsi->data->model == DSI_MODEL_OMAP4 ?
  3967. "omap4_padconf_global" : "omap5_padconf_global");
  3968. if (!np)
  3969. return -ENODEV;
  3970. dsi->syscon = syscon_node_to_regmap(np);
  3971. of_node_put(np);
  3972. }
  3973. /* DSI VCs initialization */
  3974. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++)
  3975. dsi->vc[i].source = DSI_VC_SOURCE_L4;
  3976. r = dsi_get_clocks(dsi);
  3977. if (r)
  3978. return r;
  3979. pm_runtime_enable(dev);
  3980. /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
  3981. * of data to 3 by default */
  3982. if (dsi->data->quirks & DSI_QUIRK_GNQ) {
  3983. dsi_runtime_get(dsi);
  3984. /* NB_DATA_LANES */
  3985. dsi->num_lanes_supported = 1 + REG_GET(dsi, DSI_GNQ, 11, 9);
  3986. dsi_runtime_put(dsi);
  3987. } else {
  3988. dsi->num_lanes_supported = 3;
  3989. }
  3990. dsi->host.ops = &omap_dsi_host_ops;
  3991. dsi->host.dev = &pdev->dev;
  3992. r = dsi_probe_of(dsi);
  3993. if (r) {
  3994. DSSERR("Invalid DSI DT data\n");
  3995. goto err_pm_disable;
  3996. }
  3997. r = mipi_dsi_host_register(&dsi->host);
  3998. if (r < 0) {
  3999. dev_err(&pdev->dev, "failed to register DSI host: %d\n", r);
  4000. goto err_pm_disable;
  4001. }
  4002. r = dsi_init_output(dsi);
  4003. if (r)
  4004. goto err_dsi_host_unregister;
  4005. r = component_add(&pdev->dev, &dsi_component_ops);
  4006. if (r)
  4007. goto err_uninit_output;
  4008. return 0;
  4009. err_uninit_output:
  4010. dsi_uninit_output(dsi);
  4011. err_dsi_host_unregister:
  4012. mipi_dsi_host_unregister(&dsi->host);
  4013. err_pm_disable:
  4014. pm_runtime_disable(dev);
  4015. return r;
  4016. }
  4017. static void dsi_remove(struct platform_device *pdev)
  4018. {
  4019. struct dsi_data *dsi = platform_get_drvdata(pdev);
  4020. component_del(&pdev->dev, &dsi_component_ops);
  4021. dsi_uninit_output(dsi);
  4022. mipi_dsi_host_unregister(&dsi->host);
  4023. pm_runtime_disable(&pdev->dev);
  4024. if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) {
  4025. regulator_disable(dsi->vdds_dsi_reg);
  4026. dsi->vdds_dsi_enabled = false;
  4027. }
  4028. }
  4029. static __maybe_unused int dsi_runtime_suspend(struct device *dev)
  4030. {
  4031. struct dsi_data *dsi = dev_get_drvdata(dev);
  4032. dsi->is_enabled = false;
  4033. /* ensure the irq handler sees the is_enabled value */
  4034. smp_wmb();
  4035. /* wait for current handler to finish before turning the DSI off */
  4036. synchronize_irq(dsi->irq);
  4037. return 0;
  4038. }
  4039. static __maybe_unused int dsi_runtime_resume(struct device *dev)
  4040. {
  4041. struct dsi_data *dsi = dev_get_drvdata(dev);
  4042. dsi->is_enabled = true;
  4043. /* ensure the irq handler sees the is_enabled value */
  4044. smp_wmb();
  4045. return 0;
  4046. }
  4047. static const struct dev_pm_ops dsi_pm_ops = {
  4048. SET_RUNTIME_PM_OPS(dsi_runtime_suspend, dsi_runtime_resume, NULL)
  4049. SET_LATE_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, pm_runtime_force_resume)
  4050. };
  4051. struct platform_driver omap_dsihw_driver = {
  4052. .probe = dsi_probe,
  4053. .remove = dsi_remove,
  4054. .driver = {
  4055. .name = "omapdss_dsi",
  4056. .pm = &dsi_pm_ops,
  4057. .of_match_table = dsi_of_match,
  4058. .suppress_bind_attrs = true,
  4059. },
  4060. };