dsi.c 123 KB

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