dsi.c 143 KB

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