dsi.c 135 KB

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