dsi.c 127 KB

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