dsi.c 136 KB

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