dsi.c 129 KB

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