dsi.c 142 KB

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