dsi.c 144 KB

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