dsi.c 127 KB

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