dsi.c 120 KB

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