dsi.c 141 KB

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