dsi.c 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627
  1. /*
  2. * linux/drivers/video/omap2/dss/dsi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "DSI"
  20. #include <linux/kernel.h>
  21. #include <linux/io.h>
  22. #include <linux/clk.h>
  23. #include <linux/device.h>
  24. #include <linux/err.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/mutex.h>
  28. #include <linux/module.h>
  29. #include <linux/semaphore.h>
  30. #include <linux/seq_file.h>
  31. #include <linux/platform_device.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <linux/wait.h>
  34. #include <linux/workqueue.h>
  35. #include <linux/sched.h>
  36. #include <linux/slab.h>
  37. #include <linux/debugfs.h>
  38. #include <linux/pm_runtime.h>
  39. #include <video/omapdss.h>
  40. #include <video/mipi_display.h>
  41. #include "dss.h"
  42. #include "dss_features.h"
  43. #define DSI_CATCH_MISSING_TE
  44. struct dsi_reg { u16 idx; };
  45. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  46. #define DSI_SZ_REGS SZ_1K
  47. /* DSI Protocol Engine */
  48. #define DSI_REVISION DSI_REG(0x0000)
  49. #define DSI_SYSCONFIG DSI_REG(0x0010)
  50. #define DSI_SYSSTATUS DSI_REG(0x0014)
  51. #define DSI_IRQSTATUS DSI_REG(0x0018)
  52. #define DSI_IRQENABLE DSI_REG(0x001C)
  53. #define DSI_CTRL DSI_REG(0x0040)
  54. #define DSI_GNQ DSI_REG(0x0044)
  55. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  56. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  57. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  58. #define DSI_CLK_CTRL DSI_REG(0x0054)
  59. #define DSI_TIMING1 DSI_REG(0x0058)
  60. #define DSI_TIMING2 DSI_REG(0x005C)
  61. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  62. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  63. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  64. #define DSI_CLK_TIMING DSI_REG(0x006C)
  65. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  66. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  67. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  68. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  69. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  70. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  71. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  72. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  73. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  74. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  75. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  76. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  77. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  78. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  79. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  80. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  81. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  82. /* DSIPHY_SCP */
  83. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  84. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  85. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  86. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  87. #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
  88. /* DSI_PLL_CTRL_SCP */
  89. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  90. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  91. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  92. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  93. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  94. #define REG_GET(dsidev, idx, start, end) \
  95. FLD_GET(dsi_read_reg(dsidev, idx), start, end)
  96. #define REG_FLD_MOD(dsidev, idx, val, start, end) \
  97. dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
  98. /* Global interrupts */
  99. #define DSI_IRQ_VC0 (1 << 0)
  100. #define DSI_IRQ_VC1 (1 << 1)
  101. #define DSI_IRQ_VC2 (1 << 2)
  102. #define DSI_IRQ_VC3 (1 << 3)
  103. #define DSI_IRQ_WAKEUP (1 << 4)
  104. #define DSI_IRQ_RESYNC (1 << 5)
  105. #define DSI_IRQ_PLL_LOCK (1 << 7)
  106. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  107. #define DSI_IRQ_PLL_RECALL (1 << 9)
  108. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  109. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  110. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  111. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  112. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  113. #define DSI_IRQ_SYNC_LOST (1 << 18)
  114. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  115. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  116. #define DSI_IRQ_ERROR_MASK \
  117. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  118. DSI_IRQ_TA_TIMEOUT | DSI_IRQ_SYNC_LOST)
  119. #define DSI_IRQ_CHANNEL_MASK 0xf
  120. /* Virtual channel interrupts */
  121. #define DSI_VC_IRQ_CS (1 << 0)
  122. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  123. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  124. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  125. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  126. #define DSI_VC_IRQ_BTA (1 << 5)
  127. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  128. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  129. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  130. #define DSI_VC_IRQ_ERROR_MASK \
  131. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  132. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  133. DSI_VC_IRQ_FIFO_TX_UDF)
  134. /* ComplexIO interrupts */
  135. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  136. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  137. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  138. #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
  139. #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
  140. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  141. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  142. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  143. #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
  144. #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
  145. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  146. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  147. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  148. #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
  149. #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
  150. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  151. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  152. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  153. #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
  154. #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
  155. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  156. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  157. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  158. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  159. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  160. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  161. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
  162. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
  163. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
  164. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
  165. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  166. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  167. #define DSI_CIO_IRQ_ERROR_MASK \
  168. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  169. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
  170. DSI_CIO_IRQ_ERRSYNCESC5 | \
  171. DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  172. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
  173. DSI_CIO_IRQ_ERRESC5 | \
  174. DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
  175. DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
  176. DSI_CIO_IRQ_ERRCONTROL5 | \
  177. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  178. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  179. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
  180. DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
  181. DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
  182. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  183. static int dsi_display_init_dispc(struct platform_device *dsidev,
  184. struct omap_overlay_manager *mgr);
  185. static void dsi_display_uninit_dispc(struct platform_device *dsidev,
  186. struct omap_overlay_manager *mgr);
  187. #define DSI_MAX_NR_ISRS 2
  188. #define DSI_MAX_NR_LANES 5
  189. enum dsi_lane_function {
  190. DSI_LANE_UNUSED = 0,
  191. DSI_LANE_CLK,
  192. DSI_LANE_DATA1,
  193. DSI_LANE_DATA2,
  194. DSI_LANE_DATA3,
  195. DSI_LANE_DATA4,
  196. };
  197. struct dsi_lane_config {
  198. enum dsi_lane_function function;
  199. u8 polarity;
  200. };
  201. struct dsi_isr_data {
  202. omap_dsi_isr_t isr;
  203. void *arg;
  204. u32 mask;
  205. };
  206. enum fifo_size {
  207. DSI_FIFO_SIZE_0 = 0,
  208. DSI_FIFO_SIZE_32 = 1,
  209. DSI_FIFO_SIZE_64 = 2,
  210. DSI_FIFO_SIZE_96 = 3,
  211. DSI_FIFO_SIZE_128 = 4,
  212. };
  213. enum dsi_vc_source {
  214. DSI_VC_SOURCE_L4 = 0,
  215. DSI_VC_SOURCE_VP,
  216. };
  217. struct dsi_irq_stats {
  218. unsigned long last_reset;
  219. unsigned irq_count;
  220. unsigned dsi_irqs[32];
  221. unsigned vc_irqs[4][32];
  222. unsigned cio_irqs[32];
  223. };
  224. struct dsi_isr_tables {
  225. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  226. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  227. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  228. };
  229. struct dsi_clk_calc_ctx {
  230. struct platform_device *dsidev;
  231. /* inputs */
  232. const struct omap_dss_dsi_config *config;
  233. unsigned long req_pck_min, req_pck_nom, req_pck_max;
  234. /* outputs */
  235. struct dsi_clock_info dsi_cinfo;
  236. struct dispc_clock_info dispc_cinfo;
  237. struct omap_video_timings dispc_vm;
  238. struct omap_dss_dsi_videomode_timings dsi_vm;
  239. };
  240. struct dsi_data {
  241. struct platform_device *pdev;
  242. void __iomem *base;
  243. int module_id;
  244. int irq;
  245. struct clk *dss_clk;
  246. struct clk *sys_clk;
  247. struct dispc_clock_info user_dispc_cinfo;
  248. struct dsi_clock_info user_dsi_cinfo;
  249. struct dsi_clock_info current_cinfo;
  250. bool vdds_dsi_enabled;
  251. struct regulator *vdds_dsi_reg;
  252. struct {
  253. enum dsi_vc_source source;
  254. struct omap_dss_device *dssdev;
  255. enum fifo_size fifo_size;
  256. int vc_id;
  257. } vc[4];
  258. struct mutex lock;
  259. struct semaphore bus_lock;
  260. unsigned pll_locked;
  261. spinlock_t irq_lock;
  262. struct dsi_isr_tables isr_tables;
  263. /* space for a copy used by the interrupt handler */
  264. struct dsi_isr_tables isr_tables_copy;
  265. int update_channel;
  266. #ifdef DEBUG
  267. unsigned update_bytes;
  268. #endif
  269. bool te_enabled;
  270. bool ulps_enabled;
  271. void (*framedone_callback)(int, void *);
  272. void *framedone_data;
  273. struct delayed_work framedone_timeout_work;
  274. #ifdef DSI_CATCH_MISSING_TE
  275. struct timer_list te_timer;
  276. #endif
  277. unsigned long cache_req_pck;
  278. unsigned long cache_clk_freq;
  279. struct dsi_clock_info cache_cinfo;
  280. u32 errors;
  281. spinlock_t errors_lock;
  282. #ifdef DEBUG
  283. ktime_t perf_setup_time;
  284. ktime_t perf_start_time;
  285. #endif
  286. int debug_read;
  287. int debug_write;
  288. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  289. spinlock_t irq_stats_lock;
  290. struct dsi_irq_stats irq_stats;
  291. #endif
  292. /* DSI PLL Parameter Ranges */
  293. unsigned long regm_max, regn_max;
  294. unsigned long regm_dispc_max, regm_dsi_max;
  295. unsigned long fint_min, fint_max;
  296. unsigned long lpdiv_max;
  297. unsigned num_lanes_supported;
  298. unsigned line_buffer_size;
  299. struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
  300. unsigned num_lanes_used;
  301. unsigned scp_clk_refcount;
  302. struct dss_lcd_mgr_config mgr_config;
  303. struct omap_video_timings timings;
  304. enum omap_dss_dsi_pixel_format pix_fmt;
  305. enum omap_dss_dsi_mode mode;
  306. struct omap_dss_dsi_videomode_timings vm_timings;
  307. struct omap_dss_device output;
  308. };
  309. struct dsi_packet_sent_handler_data {
  310. struct platform_device *dsidev;
  311. struct completion *completion;
  312. };
  313. #ifdef DEBUG
  314. static bool dsi_perf;
  315. module_param(dsi_perf, bool, 0644);
  316. #endif
  317. static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
  318. {
  319. return dev_get_drvdata(&dsidev->dev);
  320. }
  321. static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
  322. {
  323. return to_platform_device(dssdev->output->dev);
  324. }
  325. struct platform_device *dsi_get_dsidev_from_id(int module)
  326. {
  327. struct omap_dss_device *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 ? to_platform_device(out->dev) : 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. static int dsi_regulator_init(struct platform_device *dsidev)
  901. {
  902. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  903. struct regulator *vdds_dsi;
  904. if (dsi->vdds_dsi_reg != NULL)
  905. return 0;
  906. vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "vdds_dsi");
  907. /* DT HACK: try VCXIO to make omapdss work for o4 sdp/panda */
  908. if (IS_ERR(vdds_dsi))
  909. vdds_dsi = devm_regulator_get(&dsi->pdev->dev, "VCXIO");
  910. if (IS_ERR(vdds_dsi)) {
  911. DSSERR("can't get VDDS_DSI regulator\n");
  912. return PTR_ERR(vdds_dsi);
  913. }
  914. dsi->vdds_dsi_reg = vdds_dsi;
  915. return 0;
  916. }
  917. /* source clock for DSI PLL. this could also be PCLKFREE */
  918. static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
  919. bool enable)
  920. {
  921. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  922. if (enable)
  923. clk_prepare_enable(dsi->sys_clk);
  924. else
  925. clk_disable_unprepare(dsi->sys_clk);
  926. if (enable && dsi->pll_locked) {
  927. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
  928. DSSERR("cannot lock PLL when enabling clocks\n");
  929. }
  930. }
  931. static void _dsi_print_reset_status(struct platform_device *dsidev)
  932. {
  933. u32 l;
  934. int b0, b1, b2;
  935. /* A dummy read using the SCP interface to any DSIPHY register is
  936. * required after DSIPHY reset to complete the reset of the DSI complex
  937. * I/O. */
  938. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  939. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  940. b0 = 28;
  941. b1 = 27;
  942. b2 = 26;
  943. } else {
  944. b0 = 24;
  945. b1 = 25;
  946. b2 = 26;
  947. }
  948. #define DSI_FLD_GET(fld, start, end)\
  949. FLD_GET(dsi_read_reg(dsidev, DSI_##fld), start, end)
  950. pr_debug("DSI resets: PLL (%d) CIO (%d) PHY (%x%x%x, %d, %d, %d)\n",
  951. DSI_FLD_GET(PLL_STATUS, 0, 0),
  952. DSI_FLD_GET(COMPLEXIO_CFG1, 29, 29),
  953. DSI_FLD_GET(DSIPHY_CFG5, b0, b0),
  954. DSI_FLD_GET(DSIPHY_CFG5, b1, b1),
  955. DSI_FLD_GET(DSIPHY_CFG5, b2, b2),
  956. DSI_FLD_GET(DSIPHY_CFG5, 29, 29),
  957. DSI_FLD_GET(DSIPHY_CFG5, 30, 30),
  958. DSI_FLD_GET(DSIPHY_CFG5, 31, 31));
  959. #undef DSI_FLD_GET
  960. }
  961. static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
  962. {
  963. DSSDBG("dsi_if_enable(%d)\n", enable);
  964. enable = enable ? 1 : 0;
  965. REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
  966. if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
  967. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  968. return -EIO;
  969. }
  970. return 0;
  971. }
  972. unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
  973. {
  974. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  975. return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
  976. }
  977. static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
  978. {
  979. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  980. return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
  981. }
  982. static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
  983. {
  984. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  985. return dsi->current_cinfo.clkin4ddr / 16;
  986. }
  987. static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
  988. {
  989. unsigned long r;
  990. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  991. if (dss_get_dsi_clk_source(dsi->module_id) == OMAP_DSS_CLK_SRC_FCK) {
  992. /* DSI FCLK source is DSS_CLK_FCK */
  993. r = clk_get_rate(dsi->dss_clk);
  994. } else {
  995. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  996. r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
  997. }
  998. return r;
  999. }
  1000. static int dsi_lp_clock_calc(struct dsi_clock_info *cinfo,
  1001. unsigned long lp_clk_min, unsigned long lp_clk_max)
  1002. {
  1003. unsigned long dsi_fclk = cinfo->dsi_pll_hsdiv_dsi_clk;
  1004. unsigned lp_clk_div;
  1005. unsigned long lp_clk;
  1006. lp_clk_div = DIV_ROUND_UP(dsi_fclk, lp_clk_max * 2);
  1007. lp_clk = dsi_fclk / 2 / lp_clk_div;
  1008. if (lp_clk < lp_clk_min || lp_clk > lp_clk_max)
  1009. return -EINVAL;
  1010. cinfo->lp_clk_div = lp_clk_div;
  1011. cinfo->lp_clk = lp_clk;
  1012. return 0;
  1013. }
  1014. static int dsi_set_lp_clk_divisor(struct platform_device *dsidev)
  1015. {
  1016. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1017. unsigned long dsi_fclk;
  1018. unsigned lp_clk_div;
  1019. unsigned long lp_clk;
  1020. lp_clk_div = dsi->user_dsi_cinfo.lp_clk_div;
  1021. if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
  1022. return -EINVAL;
  1023. dsi_fclk = dsi_fclk_rate(dsidev);
  1024. lp_clk = dsi_fclk / 2 / lp_clk_div;
  1025. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  1026. dsi->current_cinfo.lp_clk = lp_clk;
  1027. dsi->current_cinfo.lp_clk_div = lp_clk_div;
  1028. /* LP_CLK_DIVISOR */
  1029. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
  1030. /* LP_RX_SYNCHRO_ENABLE */
  1031. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
  1032. return 0;
  1033. }
  1034. static void dsi_enable_scp_clk(struct platform_device *dsidev)
  1035. {
  1036. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1037. if (dsi->scp_clk_refcount++ == 0)
  1038. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
  1039. }
  1040. static void dsi_disable_scp_clk(struct platform_device *dsidev)
  1041. {
  1042. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1043. WARN_ON(dsi->scp_clk_refcount == 0);
  1044. if (--dsi->scp_clk_refcount == 0)
  1045. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
  1046. }
  1047. enum dsi_pll_power_state {
  1048. DSI_PLL_POWER_OFF = 0x0,
  1049. DSI_PLL_POWER_ON_HSCLK = 0x1,
  1050. DSI_PLL_POWER_ON_ALL = 0x2,
  1051. DSI_PLL_POWER_ON_DIV = 0x3,
  1052. };
  1053. static int dsi_pll_power(struct platform_device *dsidev,
  1054. enum dsi_pll_power_state state)
  1055. {
  1056. int t = 0;
  1057. /* DSI-PLL power command 0x3 is not working */
  1058. if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
  1059. state == DSI_PLL_POWER_ON_DIV)
  1060. state = DSI_PLL_POWER_ON_ALL;
  1061. /* PLL_PWR_CMD */
  1062. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
  1063. /* PLL_PWR_STATUS */
  1064. while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
  1065. if (++t > 1000) {
  1066. DSSERR("Failed to set DSI PLL power mode to %d\n",
  1067. state);
  1068. return -ENODEV;
  1069. }
  1070. udelay(1);
  1071. }
  1072. return 0;
  1073. }
  1074. unsigned long dsi_get_pll_clkin(struct platform_device *dsidev)
  1075. {
  1076. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1077. return clk_get_rate(dsi->sys_clk);
  1078. }
  1079. bool dsi_hsdiv_calc(struct platform_device *dsidev, unsigned long pll,
  1080. unsigned long out_min, dsi_hsdiv_calc_func func, void *data)
  1081. {
  1082. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1083. int regm, regm_start, regm_stop;
  1084. unsigned long out_max;
  1085. unsigned long out;
  1086. out_min = out_min ? out_min : 1;
  1087. out_max = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  1088. regm_start = max(DIV_ROUND_UP(pll, out_max), 1ul);
  1089. regm_stop = min(pll / out_min, dsi->regm_dispc_max);
  1090. for (regm = regm_start; regm <= regm_stop; ++regm) {
  1091. out = pll / regm;
  1092. if (func(regm, out, data))
  1093. return true;
  1094. }
  1095. return false;
  1096. }
  1097. bool dsi_pll_calc(struct platform_device *dsidev, unsigned long clkin,
  1098. unsigned long pll_min, unsigned long pll_max,
  1099. dsi_pll_calc_func func, void *data)
  1100. {
  1101. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1102. int regn, regn_start, regn_stop;
  1103. int regm, regm_start, regm_stop;
  1104. unsigned long fint, pll;
  1105. const unsigned long pll_hw_max = 1800000000;
  1106. unsigned long fint_hw_min, fint_hw_max;
  1107. fint_hw_min = dsi->fint_min;
  1108. fint_hw_max = dsi->fint_max;
  1109. regn_start = max(DIV_ROUND_UP(clkin, fint_hw_max), 1ul);
  1110. regn_stop = min(clkin / fint_hw_min, dsi->regn_max);
  1111. pll_max = pll_max ? pll_max : ULONG_MAX;
  1112. for (regn = regn_start; regn <= regn_stop; ++regn) {
  1113. fint = clkin / regn;
  1114. regm_start = max(DIV_ROUND_UP(DIV_ROUND_UP(pll_min, fint), 2),
  1115. 1ul);
  1116. regm_stop = min3(pll_max / fint / 2,
  1117. pll_hw_max / fint / 2,
  1118. dsi->regm_max);
  1119. for (regm = regm_start; regm <= regm_stop; ++regm) {
  1120. pll = 2 * regm * fint;
  1121. if (func(regn, regm, fint, pll, data))
  1122. return true;
  1123. }
  1124. }
  1125. return false;
  1126. }
  1127. /* calculate clock rates using dividers in cinfo */
  1128. static int dsi_calc_clock_rates(struct platform_device *dsidev,
  1129. struct dsi_clock_info *cinfo)
  1130. {
  1131. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1132. if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
  1133. return -EINVAL;
  1134. if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
  1135. return -EINVAL;
  1136. if (cinfo->regm_dispc > dsi->regm_dispc_max)
  1137. return -EINVAL;
  1138. if (cinfo->regm_dsi > dsi->regm_dsi_max)
  1139. return -EINVAL;
  1140. cinfo->clkin = clk_get_rate(dsi->sys_clk);
  1141. cinfo->fint = cinfo->clkin / cinfo->regn;
  1142. if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
  1143. return -EINVAL;
  1144. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  1145. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  1146. return -EINVAL;
  1147. if (cinfo->regm_dispc > 0)
  1148. cinfo->dsi_pll_hsdiv_dispc_clk =
  1149. cinfo->clkin4ddr / cinfo->regm_dispc;
  1150. else
  1151. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  1152. if (cinfo->regm_dsi > 0)
  1153. cinfo->dsi_pll_hsdiv_dsi_clk =
  1154. cinfo->clkin4ddr / cinfo->regm_dsi;
  1155. else
  1156. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  1157. return 0;
  1158. }
  1159. static void dsi_pll_calc_dsi_fck(struct dsi_clock_info *cinfo)
  1160. {
  1161. unsigned long max_dsi_fck;
  1162. max_dsi_fck = dss_feat_get_param_max(FEAT_PARAM_DSI_FCK);
  1163. cinfo->regm_dsi = DIV_ROUND_UP(cinfo->clkin4ddr, max_dsi_fck);
  1164. cinfo->dsi_pll_hsdiv_dsi_clk = cinfo->clkin4ddr / cinfo->regm_dsi;
  1165. }
  1166. int dsi_pll_set_clock_div(struct platform_device *dsidev,
  1167. struct dsi_clock_info *cinfo)
  1168. {
  1169. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1170. int r = 0;
  1171. u32 l;
  1172. int f = 0;
  1173. u8 regn_start, regn_end, regm_start, regm_end;
  1174. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1175. DSSDBG("DSI PLL clock config starts");
  1176. dsi->current_cinfo.clkin = cinfo->clkin;
  1177. dsi->current_cinfo.fint = cinfo->fint;
  1178. dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1179. dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1180. cinfo->dsi_pll_hsdiv_dispc_clk;
  1181. dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1182. cinfo->dsi_pll_hsdiv_dsi_clk;
  1183. dsi->current_cinfo.regn = cinfo->regn;
  1184. dsi->current_cinfo.regm = cinfo->regm;
  1185. dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
  1186. dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
  1187. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1188. DSSDBG("clkin rate %ld\n", cinfo->clkin);
  1189. /* DSIPHY == CLKIN4DDR */
  1190. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu = %lu\n",
  1191. cinfo->regm,
  1192. cinfo->regn,
  1193. cinfo->clkin,
  1194. cinfo->clkin4ddr);
  1195. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1196. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1197. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1198. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1199. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1200. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1201. cinfo->dsi_pll_hsdiv_dispc_clk);
  1202. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1203. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1204. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1205. cinfo->dsi_pll_hsdiv_dsi_clk);
  1206. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1207. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1208. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1209. &regm_dispc_end);
  1210. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1211. &regm_dsi_end);
  1212. /* DSI_PLL_AUTOMODE = manual */
  1213. REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
  1214. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
  1215. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1216. /* DSI_PLL_REGN */
  1217. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1218. /* DSI_PLL_REGM */
  1219. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1220. /* DSI_CLOCK_DIV */
  1221. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1222. regm_dispc_start, regm_dispc_end);
  1223. /* DSIPROTO_CLOCK_DIV */
  1224. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1225. regm_dsi_start, regm_dsi_end);
  1226. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
  1227. BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
  1228. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1229. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
  1230. f = cinfo->fint < 1000000 ? 0x3 :
  1231. cinfo->fint < 1250000 ? 0x4 :
  1232. cinfo->fint < 1500000 ? 0x5 :
  1233. cinfo->fint < 1750000 ? 0x6 :
  1234. 0x7;
  1235. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1236. } else if (dss_has_feature(FEAT_DSI_PLL_SELFREQDCO)) {
  1237. f = cinfo->clkin4ddr < 1000000000 ? 0x2 : 0x4;
  1238. l = FLD_MOD(l, f, 4, 1); /* PLL_SELFREQDCO */
  1239. }
  1240. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1241. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1242. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1243. if (dss_has_feature(FEAT_DSI_PLL_REFSEL))
  1244. l = FLD_MOD(l, 3, 22, 21); /* REF_SYSCLK = sysclk */
  1245. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1246. REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1247. if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
  1248. DSSERR("dsi pll go bit not going down.\n");
  1249. r = -EIO;
  1250. goto err;
  1251. }
  1252. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
  1253. DSSERR("cannot lock PLL\n");
  1254. r = -EIO;
  1255. goto err;
  1256. }
  1257. dsi->pll_locked = 1;
  1258. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1259. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1260. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1261. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1262. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1263. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1264. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1265. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1266. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1267. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1268. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1269. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1270. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1271. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1272. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1273. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1274. DSSDBG("PLL config done\n");
  1275. err:
  1276. return r;
  1277. }
  1278. int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
  1279. bool enable_hsdiv)
  1280. {
  1281. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1282. int r = 0;
  1283. enum dsi_pll_power_state pwstate;
  1284. DSSDBG("PLL init\n");
  1285. /*
  1286. * It seems that on many OMAPs we need to enable both to have a
  1287. * functional HSDivider.
  1288. */
  1289. enable_hsclk = enable_hsdiv = true;
  1290. r = dsi_regulator_init(dsidev);
  1291. if (r)
  1292. return r;
  1293. dsi_enable_pll_clock(dsidev, 1);
  1294. /*
  1295. * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
  1296. */
  1297. dsi_enable_scp_clk(dsidev);
  1298. if (!dsi->vdds_dsi_enabled) {
  1299. r = regulator_enable(dsi->vdds_dsi_reg);
  1300. if (r)
  1301. goto err0;
  1302. dsi->vdds_dsi_enabled = true;
  1303. }
  1304. /* XXX PLL does not come out of reset without this... */
  1305. dispc_pck_free_enable(1);
  1306. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
  1307. DSSERR("PLL not coming out of reset.\n");
  1308. r = -ENODEV;
  1309. dispc_pck_free_enable(0);
  1310. goto err1;
  1311. }
  1312. /* XXX ... but if left on, we get problems when planes do not
  1313. * fill the whole display. No idea about this */
  1314. dispc_pck_free_enable(0);
  1315. if (enable_hsclk && enable_hsdiv)
  1316. pwstate = DSI_PLL_POWER_ON_ALL;
  1317. else if (enable_hsclk)
  1318. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1319. else if (enable_hsdiv)
  1320. pwstate = DSI_PLL_POWER_ON_DIV;
  1321. else
  1322. pwstate = DSI_PLL_POWER_OFF;
  1323. r = dsi_pll_power(dsidev, pwstate);
  1324. if (r)
  1325. goto err1;
  1326. DSSDBG("PLL init done\n");
  1327. return 0;
  1328. err1:
  1329. if (dsi->vdds_dsi_enabled) {
  1330. regulator_disable(dsi->vdds_dsi_reg);
  1331. dsi->vdds_dsi_enabled = false;
  1332. }
  1333. err0:
  1334. dsi_disable_scp_clk(dsidev);
  1335. dsi_enable_pll_clock(dsidev, 0);
  1336. return r;
  1337. }
  1338. void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
  1339. {
  1340. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1341. dsi->pll_locked = 0;
  1342. dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
  1343. if (disconnect_lanes) {
  1344. WARN_ON(!dsi->vdds_dsi_enabled);
  1345. regulator_disable(dsi->vdds_dsi_reg);
  1346. dsi->vdds_dsi_enabled = false;
  1347. }
  1348. dsi_disable_scp_clk(dsidev);
  1349. dsi_enable_pll_clock(dsidev, 0);
  1350. DSSDBG("PLL uninit done\n");
  1351. }
  1352. static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
  1353. struct seq_file *s)
  1354. {
  1355. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1356. struct dsi_clock_info *cinfo = &dsi->current_cinfo;
  1357. enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
  1358. int dsi_module = dsi->module_id;
  1359. dispc_clk_src = dss_get_dispc_clk_source();
  1360. dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
  1361. if (dsi_runtime_get(dsidev))
  1362. return;
  1363. seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
  1364. seq_printf(s, "dsi pll clkin\t%lu\n", cinfo->clkin);
  1365. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1366. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1367. cinfo->clkin4ddr, cinfo->regm);
  1368. seq_printf(s, "DSI_PLL_HSDIV_DISPC (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1369. dss_feat_get_clk_source_name(dsi_module == 0 ?
  1370. OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
  1371. OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC),
  1372. cinfo->dsi_pll_hsdiv_dispc_clk,
  1373. cinfo->regm_dispc,
  1374. dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1375. "off" : "on");
  1376. seq_printf(s, "DSI_PLL_HSDIV_DSI (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1377. dss_feat_get_clk_source_name(dsi_module == 0 ?
  1378. OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
  1379. OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI),
  1380. cinfo->dsi_pll_hsdiv_dsi_clk,
  1381. cinfo->regm_dsi,
  1382. dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1383. "off" : "on");
  1384. seq_printf(s, "- DSI%d -\n", dsi_module + 1);
  1385. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1386. dss_get_generic_clk_source_name(dsi_clk_src),
  1387. dss_feat_get_clk_source_name(dsi_clk_src));
  1388. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
  1389. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1390. cinfo->clkin4ddr / 4);
  1391. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
  1392. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1393. dsi_runtime_put(dsidev);
  1394. }
  1395. void dsi_dump_clocks(struct seq_file *s)
  1396. {
  1397. struct platform_device *dsidev;
  1398. int i;
  1399. for (i = 0; i < MAX_NUM_DSI; i++) {
  1400. dsidev = dsi_get_dsidev_from_id(i);
  1401. if (dsidev)
  1402. dsi_dump_dsidev_clocks(dsidev, s);
  1403. }
  1404. }
  1405. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1406. static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
  1407. struct seq_file *s)
  1408. {
  1409. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1410. unsigned long flags;
  1411. struct dsi_irq_stats stats;
  1412. spin_lock_irqsave(&dsi->irq_stats_lock, flags);
  1413. stats = dsi->irq_stats;
  1414. memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
  1415. dsi->irq_stats.last_reset = jiffies;
  1416. spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
  1417. seq_printf(s, "period %u ms\n",
  1418. jiffies_to_msecs(jiffies - stats.last_reset));
  1419. seq_printf(s, "irqs %d\n", stats.irq_count);
  1420. #define PIS(x) \
  1421. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1422. seq_printf(s, "-- DSI%d interrupts --\n", dsi->module_id + 1);
  1423. PIS(VC0);
  1424. PIS(VC1);
  1425. PIS(VC2);
  1426. PIS(VC3);
  1427. PIS(WAKEUP);
  1428. PIS(RESYNC);
  1429. PIS(PLL_LOCK);
  1430. PIS(PLL_UNLOCK);
  1431. PIS(PLL_RECALL);
  1432. PIS(COMPLEXIO_ERR);
  1433. PIS(HS_TX_TIMEOUT);
  1434. PIS(LP_RX_TIMEOUT);
  1435. PIS(TE_TRIGGER);
  1436. PIS(ACK_TRIGGER);
  1437. PIS(SYNC_LOST);
  1438. PIS(LDO_POWER_GOOD);
  1439. PIS(TA_TIMEOUT);
  1440. #undef PIS
  1441. #define PIS(x) \
  1442. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1443. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1444. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1445. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1446. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1447. seq_printf(s, "-- VC interrupts --\n");
  1448. PIS(CS);
  1449. PIS(ECC_CORR);
  1450. PIS(PACKET_SENT);
  1451. PIS(FIFO_TX_OVF);
  1452. PIS(FIFO_RX_OVF);
  1453. PIS(BTA);
  1454. PIS(ECC_NO_CORR);
  1455. PIS(FIFO_TX_UDF);
  1456. PIS(PP_BUSY_CHANGE);
  1457. #undef PIS
  1458. #define PIS(x) \
  1459. seq_printf(s, "%-20s %10d\n", #x, \
  1460. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1461. seq_printf(s, "-- CIO interrupts --\n");
  1462. PIS(ERRSYNCESC1);
  1463. PIS(ERRSYNCESC2);
  1464. PIS(ERRSYNCESC3);
  1465. PIS(ERRESC1);
  1466. PIS(ERRESC2);
  1467. PIS(ERRESC3);
  1468. PIS(ERRCONTROL1);
  1469. PIS(ERRCONTROL2);
  1470. PIS(ERRCONTROL3);
  1471. PIS(STATEULPS1);
  1472. PIS(STATEULPS2);
  1473. PIS(STATEULPS3);
  1474. PIS(ERRCONTENTIONLP0_1);
  1475. PIS(ERRCONTENTIONLP1_1);
  1476. PIS(ERRCONTENTIONLP0_2);
  1477. PIS(ERRCONTENTIONLP1_2);
  1478. PIS(ERRCONTENTIONLP0_3);
  1479. PIS(ERRCONTENTIONLP1_3);
  1480. PIS(ULPSACTIVENOT_ALL0);
  1481. PIS(ULPSACTIVENOT_ALL1);
  1482. #undef PIS
  1483. }
  1484. static void dsi1_dump_irqs(struct seq_file *s)
  1485. {
  1486. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1487. dsi_dump_dsidev_irqs(dsidev, s);
  1488. }
  1489. static void dsi2_dump_irqs(struct seq_file *s)
  1490. {
  1491. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1492. dsi_dump_dsidev_irqs(dsidev, s);
  1493. }
  1494. #endif
  1495. static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
  1496. struct seq_file *s)
  1497. {
  1498. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
  1499. if (dsi_runtime_get(dsidev))
  1500. return;
  1501. dsi_enable_scp_clk(dsidev);
  1502. DUMPREG(DSI_REVISION);
  1503. DUMPREG(DSI_SYSCONFIG);
  1504. DUMPREG(DSI_SYSSTATUS);
  1505. DUMPREG(DSI_IRQSTATUS);
  1506. DUMPREG(DSI_IRQENABLE);
  1507. DUMPREG(DSI_CTRL);
  1508. DUMPREG(DSI_COMPLEXIO_CFG1);
  1509. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1510. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1511. DUMPREG(DSI_CLK_CTRL);
  1512. DUMPREG(DSI_TIMING1);
  1513. DUMPREG(DSI_TIMING2);
  1514. DUMPREG(DSI_VM_TIMING1);
  1515. DUMPREG(DSI_VM_TIMING2);
  1516. DUMPREG(DSI_VM_TIMING3);
  1517. DUMPREG(DSI_CLK_TIMING);
  1518. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1519. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1520. DUMPREG(DSI_COMPLEXIO_CFG2);
  1521. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1522. DUMPREG(DSI_VM_TIMING4);
  1523. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1524. DUMPREG(DSI_VM_TIMING5);
  1525. DUMPREG(DSI_VM_TIMING6);
  1526. DUMPREG(DSI_VM_TIMING7);
  1527. DUMPREG(DSI_STOPCLK_TIMING);
  1528. DUMPREG(DSI_VC_CTRL(0));
  1529. DUMPREG(DSI_VC_TE(0));
  1530. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1531. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1532. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1533. DUMPREG(DSI_VC_IRQSTATUS(0));
  1534. DUMPREG(DSI_VC_IRQENABLE(0));
  1535. DUMPREG(DSI_VC_CTRL(1));
  1536. DUMPREG(DSI_VC_TE(1));
  1537. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1538. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1539. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1540. DUMPREG(DSI_VC_IRQSTATUS(1));
  1541. DUMPREG(DSI_VC_IRQENABLE(1));
  1542. DUMPREG(DSI_VC_CTRL(2));
  1543. DUMPREG(DSI_VC_TE(2));
  1544. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1545. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1546. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1547. DUMPREG(DSI_VC_IRQSTATUS(2));
  1548. DUMPREG(DSI_VC_IRQENABLE(2));
  1549. DUMPREG(DSI_VC_CTRL(3));
  1550. DUMPREG(DSI_VC_TE(3));
  1551. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1552. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1553. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1554. DUMPREG(DSI_VC_IRQSTATUS(3));
  1555. DUMPREG(DSI_VC_IRQENABLE(3));
  1556. DUMPREG(DSI_DSIPHY_CFG0);
  1557. DUMPREG(DSI_DSIPHY_CFG1);
  1558. DUMPREG(DSI_DSIPHY_CFG2);
  1559. DUMPREG(DSI_DSIPHY_CFG5);
  1560. DUMPREG(DSI_PLL_CONTROL);
  1561. DUMPREG(DSI_PLL_STATUS);
  1562. DUMPREG(DSI_PLL_GO);
  1563. DUMPREG(DSI_PLL_CONFIGURATION1);
  1564. DUMPREG(DSI_PLL_CONFIGURATION2);
  1565. dsi_disable_scp_clk(dsidev);
  1566. dsi_runtime_put(dsidev);
  1567. #undef DUMPREG
  1568. }
  1569. static void dsi1_dump_regs(struct seq_file *s)
  1570. {
  1571. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1572. dsi_dump_dsidev_regs(dsidev, s);
  1573. }
  1574. static void dsi2_dump_regs(struct seq_file *s)
  1575. {
  1576. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1577. dsi_dump_dsidev_regs(dsidev, s);
  1578. }
  1579. enum dsi_cio_power_state {
  1580. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1581. DSI_COMPLEXIO_POWER_ON = 0x1,
  1582. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1583. };
  1584. static int dsi_cio_power(struct platform_device *dsidev,
  1585. enum dsi_cio_power_state state)
  1586. {
  1587. int t = 0;
  1588. /* PWR_CMD */
  1589. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
  1590. /* PWR_STATUS */
  1591. while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
  1592. 26, 25) != state) {
  1593. if (++t > 1000) {
  1594. DSSERR("failed to set complexio power state to "
  1595. "%d\n", state);
  1596. return -ENODEV;
  1597. }
  1598. udelay(1);
  1599. }
  1600. return 0;
  1601. }
  1602. static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
  1603. {
  1604. int val;
  1605. /* line buffer on OMAP3 is 1024 x 24bits */
  1606. /* XXX: for some reason using full buffer size causes
  1607. * considerable TX slowdown with update sizes that fill the
  1608. * whole buffer */
  1609. if (!dss_has_feature(FEAT_DSI_GNQ))
  1610. return 1023 * 3;
  1611. val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
  1612. switch (val) {
  1613. case 1:
  1614. return 512 * 3; /* 512x24 bits */
  1615. case 2:
  1616. return 682 * 3; /* 682x24 bits */
  1617. case 3:
  1618. return 853 * 3; /* 853x24 bits */
  1619. case 4:
  1620. return 1024 * 3; /* 1024x24 bits */
  1621. case 5:
  1622. return 1194 * 3; /* 1194x24 bits */
  1623. case 6:
  1624. return 1365 * 3; /* 1365x24 bits */
  1625. case 7:
  1626. return 1920 * 3; /* 1920x24 bits */
  1627. default:
  1628. BUG();
  1629. return 0;
  1630. }
  1631. }
  1632. static int dsi_set_lane_config(struct platform_device *dsidev)
  1633. {
  1634. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1635. static const u8 offsets[] = { 0, 4, 8, 12, 16 };
  1636. static const enum dsi_lane_function functions[] = {
  1637. DSI_LANE_CLK,
  1638. DSI_LANE_DATA1,
  1639. DSI_LANE_DATA2,
  1640. DSI_LANE_DATA3,
  1641. DSI_LANE_DATA4,
  1642. };
  1643. u32 r;
  1644. int i;
  1645. r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  1646. for (i = 0; i < dsi->num_lanes_used; ++i) {
  1647. unsigned offset = offsets[i];
  1648. unsigned polarity, lane_number;
  1649. unsigned t;
  1650. for (t = 0; t < dsi->num_lanes_supported; ++t)
  1651. if (dsi->lanes[t].function == functions[i])
  1652. break;
  1653. if (t == dsi->num_lanes_supported)
  1654. return -EINVAL;
  1655. lane_number = t;
  1656. polarity = dsi->lanes[t].polarity;
  1657. r = FLD_MOD(r, lane_number + 1, offset + 2, offset);
  1658. r = FLD_MOD(r, polarity, offset + 3, offset + 3);
  1659. }
  1660. /* clear the unused lanes */
  1661. for (; i < dsi->num_lanes_supported; ++i) {
  1662. unsigned offset = offsets[i];
  1663. r = FLD_MOD(r, 0, offset + 2, offset);
  1664. r = FLD_MOD(r, 0, offset + 3, offset + 3);
  1665. }
  1666. dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
  1667. return 0;
  1668. }
  1669. static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
  1670. {
  1671. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1672. /* convert time in ns to ddr ticks, rounding up */
  1673. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1674. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1675. }
  1676. static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
  1677. {
  1678. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1679. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1680. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1681. }
  1682. static void dsi_cio_timings(struct platform_device *dsidev)
  1683. {
  1684. u32 r;
  1685. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1686. u32 tlpx_half, tclk_trail, tclk_zero;
  1687. u32 tclk_prepare;
  1688. /* calculate timings */
  1689. /* 1 * DDR_CLK = 2 * UI */
  1690. /* min 40ns + 4*UI max 85ns + 6*UI */
  1691. ths_prepare = ns2ddr(dsidev, 70) + 2;
  1692. /* min 145ns + 10*UI */
  1693. ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
  1694. /* min max(8*UI, 60ns+4*UI) */
  1695. ths_trail = ns2ddr(dsidev, 60) + 5;
  1696. /* min 100ns */
  1697. ths_exit = ns2ddr(dsidev, 145);
  1698. /* tlpx min 50n */
  1699. tlpx_half = ns2ddr(dsidev, 25);
  1700. /* min 60ns */
  1701. tclk_trail = ns2ddr(dsidev, 60) + 2;
  1702. /* min 38ns, max 95ns */
  1703. tclk_prepare = ns2ddr(dsidev, 65);
  1704. /* min tclk-prepare + tclk-zero = 300ns */
  1705. tclk_zero = ns2ddr(dsidev, 260);
  1706. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1707. ths_prepare, ddr2ns(dsidev, ths_prepare),
  1708. ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
  1709. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1710. ths_trail, ddr2ns(dsidev, ths_trail),
  1711. ths_exit, ddr2ns(dsidev, ths_exit));
  1712. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1713. "tclk_zero %u (%uns)\n",
  1714. tlpx_half, ddr2ns(dsidev, tlpx_half),
  1715. tclk_trail, ddr2ns(dsidev, tclk_trail),
  1716. tclk_zero, ddr2ns(dsidev, tclk_zero));
  1717. DSSDBG("tclk_prepare %u (%uns)\n",
  1718. tclk_prepare, ddr2ns(dsidev, tclk_prepare));
  1719. /* program timings */
  1720. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  1721. r = FLD_MOD(r, ths_prepare, 31, 24);
  1722. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1723. r = FLD_MOD(r, ths_trail, 15, 8);
  1724. r = FLD_MOD(r, ths_exit, 7, 0);
  1725. dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
  1726. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  1727. r = FLD_MOD(r, tlpx_half, 20, 16);
  1728. r = FLD_MOD(r, tclk_trail, 15, 8);
  1729. r = FLD_MOD(r, tclk_zero, 7, 0);
  1730. if (dss_has_feature(FEAT_DSI_PHY_DCC)) {
  1731. r = FLD_MOD(r, 0, 21, 21); /* DCCEN = disable */
  1732. r = FLD_MOD(r, 1, 22, 22); /* CLKINP_DIVBY2EN = enable */
  1733. r = FLD_MOD(r, 1, 23, 23); /* CLKINP_SEL = enable */
  1734. }
  1735. dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
  1736. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  1737. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1738. dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
  1739. }
  1740. /* lane masks have lane 0 at lsb. mask_p for positive lines, n for negative */
  1741. static void dsi_cio_enable_lane_override(struct platform_device *dsidev,
  1742. unsigned mask_p, unsigned mask_n)
  1743. {
  1744. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1745. int i;
  1746. u32 l;
  1747. u8 lptxscp_start = dsi->num_lanes_supported == 3 ? 22 : 26;
  1748. l = 0;
  1749. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1750. unsigned p = dsi->lanes[i].polarity;
  1751. if (mask_p & (1 << i))
  1752. l |= 1 << (i * 2 + (p ? 0 : 1));
  1753. if (mask_n & (1 << i))
  1754. l |= 1 << (i * 2 + (p ? 1 : 0));
  1755. }
  1756. /*
  1757. * Bits in REGLPTXSCPDAT4TO0DXDY:
  1758. * 17: DY0 18: DX0
  1759. * 19: DY1 20: DX1
  1760. * 21: DY2 22: DX2
  1761. * 23: DY3 24: DX3
  1762. * 25: DY4 26: DX4
  1763. */
  1764. /* Set the lane override configuration */
  1765. /* REGLPTXSCPDAT4TO0DXDY */
  1766. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
  1767. /* Enable lane override */
  1768. /* ENLPTXSCPDAT */
  1769. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
  1770. }
  1771. static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
  1772. {
  1773. /* Disable lane override */
  1774. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
  1775. /* Reset the lane override configuration */
  1776. /* REGLPTXSCPDAT4TO0DXDY */
  1777. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
  1778. }
  1779. static int dsi_cio_wait_tx_clk_esc_reset(struct platform_device *dsidev)
  1780. {
  1781. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1782. int t, i;
  1783. bool in_use[DSI_MAX_NR_LANES];
  1784. static const u8 offsets_old[] = { 28, 27, 26 };
  1785. static const u8 offsets_new[] = { 24, 25, 26, 27, 28 };
  1786. const u8 *offsets;
  1787. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC))
  1788. offsets = offsets_old;
  1789. else
  1790. offsets = offsets_new;
  1791. for (i = 0; i < dsi->num_lanes_supported; ++i)
  1792. in_use[i] = dsi->lanes[i].function != DSI_LANE_UNUSED;
  1793. t = 100000;
  1794. while (true) {
  1795. u32 l;
  1796. int ok;
  1797. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1798. ok = 0;
  1799. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1800. if (!in_use[i] || (l & (1 << offsets[i])))
  1801. ok++;
  1802. }
  1803. if (ok == dsi->num_lanes_supported)
  1804. break;
  1805. if (--t == 0) {
  1806. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1807. if (!in_use[i] || (l & (1 << offsets[i])))
  1808. continue;
  1809. DSSERR("CIO TXCLKESC%d domain not coming " \
  1810. "out of reset\n", i);
  1811. }
  1812. return -EIO;
  1813. }
  1814. }
  1815. return 0;
  1816. }
  1817. /* return bitmask of enabled lanes, lane0 being the lsb */
  1818. static unsigned dsi_get_lane_mask(struct platform_device *dsidev)
  1819. {
  1820. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1821. unsigned mask = 0;
  1822. int i;
  1823. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1824. if (dsi->lanes[i].function != DSI_LANE_UNUSED)
  1825. mask |= 1 << i;
  1826. }
  1827. return mask;
  1828. }
  1829. static int dsi_cio_init(struct platform_device *dsidev)
  1830. {
  1831. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1832. int r;
  1833. u32 l;
  1834. DSSDBG("DSI CIO init starts");
  1835. r = dss_dsi_enable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
  1836. if (r)
  1837. return r;
  1838. dsi_enable_scp_clk(dsidev);
  1839. /* A dummy read using the SCP interface to any DSIPHY register is
  1840. * required after DSIPHY reset to complete the reset of the DSI complex
  1841. * I/O. */
  1842. dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1843. if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1844. DSSERR("CIO SCP Clock domain not coming out of reset.\n");
  1845. r = -EIO;
  1846. goto err_scp_clk_dom;
  1847. }
  1848. r = dsi_set_lane_config(dsidev);
  1849. if (r)
  1850. goto err_scp_clk_dom;
  1851. /* set TX STOP MODE timer to maximum for this operation */
  1852. l = dsi_read_reg(dsidev, DSI_TIMING1);
  1853. l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1854. l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
  1855. l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
  1856. l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
  1857. dsi_write_reg(dsidev, DSI_TIMING1, l);
  1858. if (dsi->ulps_enabled) {
  1859. unsigned mask_p;
  1860. int i;
  1861. DSSDBG("manual ulps exit\n");
  1862. /* ULPS is exited by Mark-1 state for 1ms, followed by
  1863. * stop state. DSS HW cannot do this via the normal
  1864. * ULPS exit sequence, as after reset the DSS HW thinks
  1865. * that we are not in ULPS mode, and refuses to send the
  1866. * sequence. So we need to send the ULPS exit sequence
  1867. * manually by setting positive lines high and negative lines
  1868. * low for 1ms.
  1869. */
  1870. mask_p = 0;
  1871. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  1872. if (dsi->lanes[i].function == DSI_LANE_UNUSED)
  1873. continue;
  1874. mask_p |= 1 << i;
  1875. }
  1876. dsi_cio_enable_lane_override(dsidev, mask_p, 0);
  1877. }
  1878. r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
  1879. if (r)
  1880. goto err_cio_pwr;
  1881. if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1882. DSSERR("CIO PWR clock domain not coming out of reset.\n");
  1883. r = -ENODEV;
  1884. goto err_cio_pwr_dom;
  1885. }
  1886. dsi_if_enable(dsidev, true);
  1887. dsi_if_enable(dsidev, false);
  1888. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1889. r = dsi_cio_wait_tx_clk_esc_reset(dsidev);
  1890. if (r)
  1891. goto err_tx_clk_esc_rst;
  1892. if (dsi->ulps_enabled) {
  1893. /* Keep Mark-1 state for 1ms (as per DSI spec) */
  1894. ktime_t wait = ns_to_ktime(1000 * 1000);
  1895. set_current_state(TASK_UNINTERRUPTIBLE);
  1896. schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
  1897. /* Disable the override. The lanes should be set to Mark-11
  1898. * state by the HW */
  1899. dsi_cio_disable_lane_override(dsidev);
  1900. }
  1901. /* FORCE_TX_STOP_MODE_IO */
  1902. REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
  1903. dsi_cio_timings(dsidev);
  1904. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  1905. /* DDR_CLK_ALWAYS_ON */
  1906. REG_FLD_MOD(dsidev, DSI_CLK_CTRL,
  1907. dsi->vm_timings.ddr_clk_always_on, 13, 13);
  1908. }
  1909. dsi->ulps_enabled = false;
  1910. DSSDBG("CIO init done\n");
  1911. return 0;
  1912. err_tx_clk_esc_rst:
  1913. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
  1914. err_cio_pwr_dom:
  1915. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  1916. err_cio_pwr:
  1917. if (dsi->ulps_enabled)
  1918. dsi_cio_disable_lane_override(dsidev);
  1919. err_scp_clk_dom:
  1920. dsi_disable_scp_clk(dsidev);
  1921. dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
  1922. return r;
  1923. }
  1924. static void dsi_cio_uninit(struct platform_device *dsidev)
  1925. {
  1926. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1927. /* DDR_CLK_ALWAYS_ON */
  1928. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
  1929. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  1930. dsi_disable_scp_clk(dsidev);
  1931. dss_dsi_disable_pads(dsi->module_id, dsi_get_lane_mask(dsidev));
  1932. }
  1933. static void dsi_config_tx_fifo(struct platform_device *dsidev,
  1934. enum fifo_size size1, enum fifo_size size2,
  1935. enum fifo_size size3, enum fifo_size size4)
  1936. {
  1937. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1938. u32 r = 0;
  1939. int add = 0;
  1940. int i;
  1941. dsi->vc[0].fifo_size = size1;
  1942. dsi->vc[1].fifo_size = size2;
  1943. dsi->vc[2].fifo_size = size3;
  1944. dsi->vc[3].fifo_size = size4;
  1945. for (i = 0; i < 4; i++) {
  1946. u8 v;
  1947. int size = dsi->vc[i].fifo_size;
  1948. if (add + size > 4) {
  1949. DSSERR("Illegal FIFO configuration\n");
  1950. BUG();
  1951. return;
  1952. }
  1953. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1954. r |= v << (8 * i);
  1955. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1956. add += size;
  1957. }
  1958. dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
  1959. }
  1960. static void dsi_config_rx_fifo(struct platform_device *dsidev,
  1961. enum fifo_size size1, enum fifo_size size2,
  1962. enum fifo_size size3, enum fifo_size size4)
  1963. {
  1964. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1965. u32 r = 0;
  1966. int add = 0;
  1967. int i;
  1968. dsi->vc[0].fifo_size = size1;
  1969. dsi->vc[1].fifo_size = size2;
  1970. dsi->vc[2].fifo_size = size3;
  1971. dsi->vc[3].fifo_size = size4;
  1972. for (i = 0; i < 4; i++) {
  1973. u8 v;
  1974. int size = dsi->vc[i].fifo_size;
  1975. if (add + size > 4) {
  1976. DSSERR("Illegal FIFO configuration\n");
  1977. BUG();
  1978. return;
  1979. }
  1980. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1981. r |= v << (8 * i);
  1982. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1983. add += size;
  1984. }
  1985. dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
  1986. }
  1987. static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
  1988. {
  1989. u32 r;
  1990. r = dsi_read_reg(dsidev, DSI_TIMING1);
  1991. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1992. dsi_write_reg(dsidev, DSI_TIMING1, r);
  1993. if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
  1994. DSSERR("TX_STOP bit not going down\n");
  1995. return -EIO;
  1996. }
  1997. return 0;
  1998. }
  1999. static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
  2000. {
  2001. return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
  2002. }
  2003. static void dsi_packet_sent_handler_vp(void *data, u32 mask)
  2004. {
  2005. struct dsi_packet_sent_handler_data *vp_data =
  2006. (struct dsi_packet_sent_handler_data *) data;
  2007. struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
  2008. const int channel = dsi->update_channel;
  2009. u8 bit = dsi->te_enabled ? 30 : 31;
  2010. if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
  2011. complete(vp_data->completion);
  2012. }
  2013. static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
  2014. {
  2015. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2016. DECLARE_COMPLETION_ONSTACK(completion);
  2017. struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
  2018. int r = 0;
  2019. u8 bit;
  2020. bit = dsi->te_enabled ? 30 : 31;
  2021. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2022. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2023. if (r)
  2024. goto err0;
  2025. /* Wait for completion only if TE_EN/TE_START is still set */
  2026. if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
  2027. if (wait_for_completion_timeout(&completion,
  2028. msecs_to_jiffies(10)) == 0) {
  2029. DSSERR("Failed to complete previous frame transfer\n");
  2030. r = -EIO;
  2031. goto err1;
  2032. }
  2033. }
  2034. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2035. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2036. return 0;
  2037. err1:
  2038. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2039. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2040. err0:
  2041. return r;
  2042. }
  2043. static void dsi_packet_sent_handler_l4(void *data, u32 mask)
  2044. {
  2045. struct dsi_packet_sent_handler_data *l4_data =
  2046. (struct dsi_packet_sent_handler_data *) data;
  2047. struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
  2048. const int channel = dsi->update_channel;
  2049. if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
  2050. complete(l4_data->completion);
  2051. }
  2052. static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
  2053. {
  2054. DECLARE_COMPLETION_ONSTACK(completion);
  2055. struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
  2056. int r = 0;
  2057. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2058. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2059. if (r)
  2060. goto err0;
  2061. /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
  2062. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
  2063. if (wait_for_completion_timeout(&completion,
  2064. msecs_to_jiffies(10)) == 0) {
  2065. DSSERR("Failed to complete previous l4 transfer\n");
  2066. r = -EIO;
  2067. goto err1;
  2068. }
  2069. }
  2070. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2071. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2072. return 0;
  2073. err1:
  2074. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2075. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2076. err0:
  2077. return r;
  2078. }
  2079. static int dsi_sync_vc(struct platform_device *dsidev, int channel)
  2080. {
  2081. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2082. WARN_ON(!dsi_bus_is_locked(dsidev));
  2083. WARN_ON(in_interrupt());
  2084. if (!dsi_vc_is_enabled(dsidev, channel))
  2085. return 0;
  2086. switch (dsi->vc[channel].source) {
  2087. case DSI_VC_SOURCE_VP:
  2088. return dsi_sync_vc_vp(dsidev, channel);
  2089. case DSI_VC_SOURCE_L4:
  2090. return dsi_sync_vc_l4(dsidev, channel);
  2091. default:
  2092. BUG();
  2093. return -EINVAL;
  2094. }
  2095. }
  2096. static int dsi_vc_enable(struct platform_device *dsidev, int channel,
  2097. bool enable)
  2098. {
  2099. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  2100. channel, enable);
  2101. enable = enable ? 1 : 0;
  2102. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
  2103. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
  2104. 0, enable) != enable) {
  2105. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  2106. return -EIO;
  2107. }
  2108. return 0;
  2109. }
  2110. static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
  2111. {
  2112. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2113. u32 r;
  2114. DSSDBG("Initial config of virtual channel %d", channel);
  2115. r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
  2116. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  2117. DSSERR("VC(%d) busy when trying to configure it!\n",
  2118. channel);
  2119. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  2120. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  2121. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  2122. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  2123. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  2124. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  2125. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  2126. if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
  2127. r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
  2128. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  2129. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  2130. dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
  2131. dsi->vc[channel].source = DSI_VC_SOURCE_L4;
  2132. }
  2133. static int dsi_vc_config_source(struct platform_device *dsidev, int channel,
  2134. enum dsi_vc_source source)
  2135. {
  2136. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2137. if (dsi->vc[channel].source == source)
  2138. return 0;
  2139. DSSDBG("Source config of virtual channel %d", channel);
  2140. dsi_sync_vc(dsidev, channel);
  2141. dsi_vc_enable(dsidev, channel, 0);
  2142. /* VC_BUSY */
  2143. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
  2144. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  2145. return -EIO;
  2146. }
  2147. /* SOURCE, 0 = L4, 1 = video port */
  2148. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), source, 1, 1);
  2149. /* DCS_CMD_ENABLE */
  2150. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  2151. bool enable = source == DSI_VC_SOURCE_VP;
  2152. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 30, 30);
  2153. }
  2154. dsi_vc_enable(dsidev, channel, 1);
  2155. dsi->vc[channel].source = source;
  2156. return 0;
  2157. }
  2158. void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
  2159. bool enable)
  2160. {
  2161. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2162. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2163. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  2164. WARN_ON(!dsi_bus_is_locked(dsidev));
  2165. dsi_vc_enable(dsidev, channel, 0);
  2166. dsi_if_enable(dsidev, 0);
  2167. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
  2168. dsi_vc_enable(dsidev, channel, 1);
  2169. dsi_if_enable(dsidev, 1);
  2170. dsi_force_tx_stop_mode_io(dsidev);
  2171. /* start the DDR clock by sending a NULL packet */
  2172. if (dsi->vm_timings.ddr_clk_always_on && enable)
  2173. dsi_vc_send_null(dssdev, channel);
  2174. }
  2175. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  2176. static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
  2177. {
  2178. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2179. u32 val;
  2180. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2181. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  2182. (val >> 0) & 0xff,
  2183. (val >> 8) & 0xff,
  2184. (val >> 16) & 0xff,
  2185. (val >> 24) & 0xff);
  2186. }
  2187. }
  2188. static void dsi_show_rx_ack_with_err(u16 err)
  2189. {
  2190. DSSERR("\tACK with ERROR (%#x):\n", err);
  2191. if (err & (1 << 0))
  2192. DSSERR("\t\tSoT Error\n");
  2193. if (err & (1 << 1))
  2194. DSSERR("\t\tSoT Sync Error\n");
  2195. if (err & (1 << 2))
  2196. DSSERR("\t\tEoT Sync Error\n");
  2197. if (err & (1 << 3))
  2198. DSSERR("\t\tEscape Mode Entry Command Error\n");
  2199. if (err & (1 << 4))
  2200. DSSERR("\t\tLP Transmit Sync Error\n");
  2201. if (err & (1 << 5))
  2202. DSSERR("\t\tHS Receive Timeout Error\n");
  2203. if (err & (1 << 6))
  2204. DSSERR("\t\tFalse Control Error\n");
  2205. if (err & (1 << 7))
  2206. DSSERR("\t\t(reserved7)\n");
  2207. if (err & (1 << 8))
  2208. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  2209. if (err & (1 << 9))
  2210. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  2211. if (err & (1 << 10))
  2212. DSSERR("\t\tChecksum Error\n");
  2213. if (err & (1 << 11))
  2214. DSSERR("\t\tData type not recognized\n");
  2215. if (err & (1 << 12))
  2216. DSSERR("\t\tInvalid VC ID\n");
  2217. if (err & (1 << 13))
  2218. DSSERR("\t\tInvalid Transmission Length\n");
  2219. if (err & (1 << 14))
  2220. DSSERR("\t\t(reserved14)\n");
  2221. if (err & (1 << 15))
  2222. DSSERR("\t\tDSI Protocol Violation\n");
  2223. }
  2224. static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
  2225. int channel)
  2226. {
  2227. /* RX_FIFO_NOT_EMPTY */
  2228. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2229. u32 val;
  2230. u8 dt;
  2231. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2232. DSSERR("\trawval %#08x\n", val);
  2233. dt = FLD_GET(val, 5, 0);
  2234. if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
  2235. u16 err = FLD_GET(val, 23, 8);
  2236. dsi_show_rx_ack_with_err(err);
  2237. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE) {
  2238. DSSERR("\tDCS short response, 1 byte: %#x\n",
  2239. FLD_GET(val, 23, 8));
  2240. } else if (dt == MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE) {
  2241. DSSERR("\tDCS short response, 2 byte: %#x\n",
  2242. FLD_GET(val, 23, 8));
  2243. } else if (dt == MIPI_DSI_RX_DCS_LONG_READ_RESPONSE) {
  2244. DSSERR("\tDCS long response, len %d\n",
  2245. FLD_GET(val, 23, 8));
  2246. dsi_vc_flush_long_data(dsidev, channel);
  2247. } else {
  2248. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2249. }
  2250. }
  2251. return 0;
  2252. }
  2253. static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
  2254. {
  2255. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2256. if (dsi->debug_write || dsi->debug_read)
  2257. DSSDBG("dsi_vc_send_bta %d\n", channel);
  2258. WARN_ON(!dsi_bus_is_locked(dsidev));
  2259. /* RX_FIFO_NOT_EMPTY */
  2260. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2261. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  2262. dsi_vc_flush_receive_data(dsidev, channel);
  2263. }
  2264. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  2265. /* flush posted write */
  2266. dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
  2267. return 0;
  2268. }
  2269. int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
  2270. {
  2271. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2272. DECLARE_COMPLETION_ONSTACK(completion);
  2273. int r = 0;
  2274. u32 err;
  2275. r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
  2276. &completion, DSI_VC_IRQ_BTA);
  2277. if (r)
  2278. goto err0;
  2279. r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
  2280. DSI_IRQ_ERROR_MASK);
  2281. if (r)
  2282. goto err1;
  2283. r = dsi_vc_send_bta(dsidev, channel);
  2284. if (r)
  2285. goto err2;
  2286. if (wait_for_completion_timeout(&completion,
  2287. msecs_to_jiffies(500)) == 0) {
  2288. DSSERR("Failed to receive BTA\n");
  2289. r = -EIO;
  2290. goto err2;
  2291. }
  2292. err = dsi_get_errors(dsidev);
  2293. if (err) {
  2294. DSSERR("Error while sending BTA: %x\n", err);
  2295. r = -EIO;
  2296. goto err2;
  2297. }
  2298. err2:
  2299. dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
  2300. DSI_IRQ_ERROR_MASK);
  2301. err1:
  2302. dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
  2303. &completion, DSI_VC_IRQ_BTA);
  2304. err0:
  2305. return r;
  2306. }
  2307. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  2308. static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
  2309. int channel, u8 data_type, u16 len, u8 ecc)
  2310. {
  2311. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2312. u32 val;
  2313. u8 data_id;
  2314. WARN_ON(!dsi_bus_is_locked(dsidev));
  2315. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2316. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  2317. FLD_VAL(ecc, 31, 24);
  2318. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
  2319. }
  2320. static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
  2321. int channel, u8 b1, u8 b2, u8 b3, u8 b4)
  2322. {
  2323. u32 val;
  2324. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  2325. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  2326. b1, b2, b3, b4, val); */
  2327. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  2328. }
  2329. static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
  2330. u8 data_type, u8 *data, u16 len, u8 ecc)
  2331. {
  2332. /*u32 val; */
  2333. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2334. int i;
  2335. u8 *p;
  2336. int r = 0;
  2337. u8 b1, b2, b3, b4;
  2338. if (dsi->debug_write)
  2339. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  2340. /* len + header */
  2341. if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
  2342. DSSERR("unable to send long packet: packet too long.\n");
  2343. return -EINVAL;
  2344. }
  2345. dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
  2346. dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
  2347. p = data;
  2348. for (i = 0; i < len >> 2; i++) {
  2349. if (dsi->debug_write)
  2350. DSSDBG("\tsending full packet %d\n", i);
  2351. b1 = *p++;
  2352. b2 = *p++;
  2353. b3 = *p++;
  2354. b4 = *p++;
  2355. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
  2356. }
  2357. i = len % 4;
  2358. if (i) {
  2359. b1 = 0; b2 = 0; b3 = 0;
  2360. if (dsi->debug_write)
  2361. DSSDBG("\tsending remainder bytes %d\n", i);
  2362. switch (i) {
  2363. case 3:
  2364. b1 = *p++;
  2365. b2 = *p++;
  2366. b3 = *p++;
  2367. break;
  2368. case 2:
  2369. b1 = *p++;
  2370. b2 = *p++;
  2371. break;
  2372. case 1:
  2373. b1 = *p++;
  2374. break;
  2375. }
  2376. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
  2377. }
  2378. return r;
  2379. }
  2380. static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
  2381. u8 data_type, u16 data, u8 ecc)
  2382. {
  2383. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2384. u32 r;
  2385. u8 data_id;
  2386. WARN_ON(!dsi_bus_is_locked(dsidev));
  2387. if (dsi->debug_write)
  2388. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  2389. channel,
  2390. data_type, data & 0xff, (data >> 8) & 0xff);
  2391. dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_L4);
  2392. if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
  2393. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  2394. return -EINVAL;
  2395. }
  2396. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2397. r = (data_id << 0) | (data << 8) | (ecc << 24);
  2398. dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
  2399. return 0;
  2400. }
  2401. int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
  2402. {
  2403. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2404. return dsi_vc_send_long(dsidev, channel, MIPI_DSI_NULL_PACKET, NULL,
  2405. 0, 0);
  2406. }
  2407. EXPORT_SYMBOL(dsi_vc_send_null);
  2408. static int dsi_vc_write_nosync_common(struct platform_device *dsidev,
  2409. int channel, u8 *data, int len, enum dss_dsi_content_type type)
  2410. {
  2411. int r;
  2412. if (len == 0) {
  2413. BUG_ON(type == DSS_DSI_CONTENT_DCS);
  2414. r = dsi_vc_send_short(dsidev, channel,
  2415. MIPI_DSI_GENERIC_SHORT_WRITE_0_PARAM, 0, 0);
  2416. } else if (len == 1) {
  2417. r = dsi_vc_send_short(dsidev, channel,
  2418. type == DSS_DSI_CONTENT_GENERIC ?
  2419. MIPI_DSI_GENERIC_SHORT_WRITE_1_PARAM :
  2420. MIPI_DSI_DCS_SHORT_WRITE, data[0], 0);
  2421. } else if (len == 2) {
  2422. r = dsi_vc_send_short(dsidev, channel,
  2423. type == DSS_DSI_CONTENT_GENERIC ?
  2424. MIPI_DSI_GENERIC_SHORT_WRITE_2_PARAM :
  2425. MIPI_DSI_DCS_SHORT_WRITE_PARAM,
  2426. data[0] | (data[1] << 8), 0);
  2427. } else {
  2428. r = dsi_vc_send_long(dsidev, channel,
  2429. type == DSS_DSI_CONTENT_GENERIC ?
  2430. MIPI_DSI_GENERIC_LONG_WRITE :
  2431. MIPI_DSI_DCS_LONG_WRITE, data, len, 0);
  2432. }
  2433. return r;
  2434. }
  2435. int dsi_vc_dcs_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_DCS);
  2441. }
  2442. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  2443. int dsi_vc_generic_write_nosync(struct omap_dss_device *dssdev, int channel,
  2444. u8 *data, int len)
  2445. {
  2446. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2447. return dsi_vc_write_nosync_common(dsidev, channel, data, len,
  2448. DSS_DSI_CONTENT_GENERIC);
  2449. }
  2450. EXPORT_SYMBOL(dsi_vc_generic_write_nosync);
  2451. static int dsi_vc_write_common(struct omap_dss_device *dssdev, int channel,
  2452. u8 *data, int len, enum dss_dsi_content_type type)
  2453. {
  2454. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2455. int r;
  2456. r = dsi_vc_write_nosync_common(dsidev, channel, data, len, type);
  2457. if (r)
  2458. goto err;
  2459. r = dsi_vc_send_bta_sync(dssdev, channel);
  2460. if (r)
  2461. goto err;
  2462. /* RX_FIFO_NOT_EMPTY */
  2463. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2464. DSSERR("rx fifo not empty after write, dumping data:\n");
  2465. dsi_vc_flush_receive_data(dsidev, channel);
  2466. r = -EIO;
  2467. goto err;
  2468. }
  2469. return 0;
  2470. err:
  2471. DSSERR("dsi_vc_write_common(ch %d, cmd 0x%02x, len %d) failed\n",
  2472. channel, data[0], len);
  2473. return r;
  2474. }
  2475. int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
  2476. int len)
  2477. {
  2478. return dsi_vc_write_common(dssdev, channel, data, len,
  2479. DSS_DSI_CONTENT_DCS);
  2480. }
  2481. EXPORT_SYMBOL(dsi_vc_dcs_write);
  2482. int dsi_vc_generic_write(struct omap_dss_device *dssdev, int channel, u8 *data,
  2483. int len)
  2484. {
  2485. return dsi_vc_write_common(dssdev, channel, data, len,
  2486. DSS_DSI_CONTENT_GENERIC);
  2487. }
  2488. EXPORT_SYMBOL(dsi_vc_generic_write);
  2489. int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
  2490. {
  2491. return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
  2492. }
  2493. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  2494. int dsi_vc_generic_write_0(struct omap_dss_device *dssdev, int channel)
  2495. {
  2496. return dsi_vc_generic_write(dssdev, channel, NULL, 0);
  2497. }
  2498. EXPORT_SYMBOL(dsi_vc_generic_write_0);
  2499. int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2500. u8 param)
  2501. {
  2502. u8 buf[2];
  2503. buf[0] = dcs_cmd;
  2504. buf[1] = param;
  2505. return dsi_vc_dcs_write(dssdev, channel, buf, 2);
  2506. }
  2507. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  2508. int dsi_vc_generic_write_1(struct omap_dss_device *dssdev, int channel,
  2509. u8 param)
  2510. {
  2511. return dsi_vc_generic_write(dssdev, channel, &param, 1);
  2512. }
  2513. EXPORT_SYMBOL(dsi_vc_generic_write_1);
  2514. int dsi_vc_generic_write_2(struct omap_dss_device *dssdev, int channel,
  2515. u8 param1, u8 param2)
  2516. {
  2517. u8 buf[2];
  2518. buf[0] = param1;
  2519. buf[1] = param2;
  2520. return dsi_vc_generic_write(dssdev, channel, buf, 2);
  2521. }
  2522. EXPORT_SYMBOL(dsi_vc_generic_write_2);
  2523. static int dsi_vc_dcs_send_read_request(struct platform_device *dsidev,
  2524. int channel, u8 dcs_cmd)
  2525. {
  2526. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2527. int r;
  2528. if (dsi->debug_read)
  2529. DSSDBG("dsi_vc_dcs_send_read_request(ch%d, dcs_cmd %x)\n",
  2530. channel, dcs_cmd);
  2531. r = dsi_vc_send_short(dsidev, channel, MIPI_DSI_DCS_READ, dcs_cmd, 0);
  2532. if (r) {
  2533. DSSERR("dsi_vc_dcs_send_read_request(ch %d, cmd 0x%02x)"
  2534. " failed\n", channel, dcs_cmd);
  2535. return r;
  2536. }
  2537. return 0;
  2538. }
  2539. static int dsi_vc_generic_send_read_request(struct platform_device *dsidev,
  2540. int channel, u8 *reqdata, int reqlen)
  2541. {
  2542. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2543. u16 data;
  2544. u8 data_type;
  2545. int r;
  2546. if (dsi->debug_read)
  2547. DSSDBG("dsi_vc_generic_send_read_request(ch %d, reqlen %d)\n",
  2548. channel, reqlen);
  2549. if (reqlen == 0) {
  2550. data_type = MIPI_DSI_GENERIC_READ_REQUEST_0_PARAM;
  2551. data = 0;
  2552. } else if (reqlen == 1) {
  2553. data_type = MIPI_DSI_GENERIC_READ_REQUEST_1_PARAM;
  2554. data = reqdata[0];
  2555. } else if (reqlen == 2) {
  2556. data_type = MIPI_DSI_GENERIC_READ_REQUEST_2_PARAM;
  2557. data = reqdata[0] | (reqdata[1] << 8);
  2558. } else {
  2559. BUG();
  2560. return -EINVAL;
  2561. }
  2562. r = dsi_vc_send_short(dsidev, channel, data_type, data, 0);
  2563. if (r) {
  2564. DSSERR("dsi_vc_generic_send_read_request(ch %d, reqlen %d)"
  2565. " failed\n", channel, reqlen);
  2566. return r;
  2567. }
  2568. return 0;
  2569. }
  2570. static int dsi_vc_read_rx_fifo(struct platform_device *dsidev, int channel,
  2571. u8 *buf, int buflen, enum dss_dsi_content_type type)
  2572. {
  2573. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2574. u32 val;
  2575. u8 dt;
  2576. int r;
  2577. /* RX_FIFO_NOT_EMPTY */
  2578. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
  2579. DSSERR("RX fifo empty when trying to read.\n");
  2580. r = -EIO;
  2581. goto err;
  2582. }
  2583. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2584. if (dsi->debug_read)
  2585. DSSDBG("\theader: %08x\n", val);
  2586. dt = FLD_GET(val, 5, 0);
  2587. if (dt == MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT) {
  2588. u16 err = FLD_GET(val, 23, 8);
  2589. dsi_show_rx_ack_with_err(err);
  2590. r = -EIO;
  2591. goto err;
  2592. } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
  2593. MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_1BYTE :
  2594. MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_1BYTE)) {
  2595. u8 data = FLD_GET(val, 15, 8);
  2596. if (dsi->debug_read)
  2597. DSSDBG("\t%s short response, 1 byte: %02x\n",
  2598. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
  2599. "DCS", data);
  2600. if (buflen < 1) {
  2601. r = -EIO;
  2602. goto err;
  2603. }
  2604. buf[0] = data;
  2605. return 1;
  2606. } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
  2607. MIPI_DSI_RX_GENERIC_SHORT_READ_RESPONSE_2BYTE :
  2608. MIPI_DSI_RX_DCS_SHORT_READ_RESPONSE_2BYTE)) {
  2609. u16 data = FLD_GET(val, 23, 8);
  2610. if (dsi->debug_read)
  2611. DSSDBG("\t%s short response, 2 byte: %04x\n",
  2612. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
  2613. "DCS", data);
  2614. if (buflen < 2) {
  2615. r = -EIO;
  2616. goto err;
  2617. }
  2618. buf[0] = data & 0xff;
  2619. buf[1] = (data >> 8) & 0xff;
  2620. return 2;
  2621. } else if (dt == (type == DSS_DSI_CONTENT_GENERIC ?
  2622. MIPI_DSI_RX_GENERIC_LONG_READ_RESPONSE :
  2623. MIPI_DSI_RX_DCS_LONG_READ_RESPONSE)) {
  2624. int w;
  2625. int len = FLD_GET(val, 23, 8);
  2626. if (dsi->debug_read)
  2627. DSSDBG("\t%s long response, len %d\n",
  2628. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" :
  2629. "DCS", len);
  2630. if (len > buflen) {
  2631. r = -EIO;
  2632. goto err;
  2633. }
  2634. /* two byte checksum ends the packet, not included in len */
  2635. for (w = 0; w < len + 2;) {
  2636. int b;
  2637. val = dsi_read_reg(dsidev,
  2638. DSI_VC_SHORT_PACKET_HEADER(channel));
  2639. if (dsi->debug_read)
  2640. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2641. (val >> 0) & 0xff,
  2642. (val >> 8) & 0xff,
  2643. (val >> 16) & 0xff,
  2644. (val >> 24) & 0xff);
  2645. for (b = 0; b < 4; ++b) {
  2646. if (w < len)
  2647. buf[w] = (val >> (b * 8)) & 0xff;
  2648. /* we discard the 2 byte checksum */
  2649. ++w;
  2650. }
  2651. }
  2652. return len;
  2653. } else {
  2654. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2655. r = -EIO;
  2656. goto err;
  2657. }
  2658. err:
  2659. DSSERR("dsi_vc_read_rx_fifo(ch %d type %s) failed\n", channel,
  2660. type == DSS_DSI_CONTENT_GENERIC ? "GENERIC" : "DCS");
  2661. return r;
  2662. }
  2663. int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2664. u8 *buf, int buflen)
  2665. {
  2666. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2667. int r;
  2668. r = dsi_vc_dcs_send_read_request(dsidev, channel, dcs_cmd);
  2669. if (r)
  2670. goto err;
  2671. r = dsi_vc_send_bta_sync(dssdev, channel);
  2672. if (r)
  2673. goto err;
  2674. r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
  2675. DSS_DSI_CONTENT_DCS);
  2676. if (r < 0)
  2677. goto err;
  2678. if (r != buflen) {
  2679. r = -EIO;
  2680. goto err;
  2681. }
  2682. return 0;
  2683. err:
  2684. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n", channel, dcs_cmd);
  2685. return r;
  2686. }
  2687. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2688. static int dsi_vc_generic_read(struct omap_dss_device *dssdev, int channel,
  2689. u8 *reqdata, int reqlen, u8 *buf, int buflen)
  2690. {
  2691. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2692. int r;
  2693. r = dsi_vc_generic_send_read_request(dsidev, channel, reqdata, reqlen);
  2694. if (r)
  2695. return r;
  2696. r = dsi_vc_send_bta_sync(dssdev, channel);
  2697. if (r)
  2698. return r;
  2699. r = dsi_vc_read_rx_fifo(dsidev, channel, buf, buflen,
  2700. DSS_DSI_CONTENT_GENERIC);
  2701. if (r < 0)
  2702. return r;
  2703. if (r != buflen) {
  2704. r = -EIO;
  2705. return r;
  2706. }
  2707. return 0;
  2708. }
  2709. int dsi_vc_generic_read_0(struct omap_dss_device *dssdev, int channel, u8 *buf,
  2710. int buflen)
  2711. {
  2712. int r;
  2713. r = dsi_vc_generic_read(dssdev, channel, NULL, 0, buf, buflen);
  2714. if (r) {
  2715. DSSERR("dsi_vc_generic_read_0(ch %d) failed\n", channel);
  2716. return r;
  2717. }
  2718. return 0;
  2719. }
  2720. EXPORT_SYMBOL(dsi_vc_generic_read_0);
  2721. int dsi_vc_generic_read_1(struct omap_dss_device *dssdev, int channel, u8 param,
  2722. u8 *buf, int buflen)
  2723. {
  2724. int r;
  2725. r = dsi_vc_generic_read(dssdev, channel, &param, 1, buf, buflen);
  2726. if (r) {
  2727. DSSERR("dsi_vc_generic_read_1(ch %d) failed\n", channel);
  2728. return r;
  2729. }
  2730. return 0;
  2731. }
  2732. EXPORT_SYMBOL(dsi_vc_generic_read_1);
  2733. int dsi_vc_generic_read_2(struct omap_dss_device *dssdev, int channel,
  2734. u8 param1, u8 param2, u8 *buf, int buflen)
  2735. {
  2736. int r;
  2737. u8 reqdata[2];
  2738. reqdata[0] = param1;
  2739. reqdata[1] = param2;
  2740. r = dsi_vc_generic_read(dssdev, channel, reqdata, 2, buf, buflen);
  2741. if (r) {
  2742. DSSERR("dsi_vc_generic_read_2(ch %d) failed\n", channel);
  2743. return r;
  2744. }
  2745. return 0;
  2746. }
  2747. EXPORT_SYMBOL(dsi_vc_generic_read_2);
  2748. int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
  2749. u16 len)
  2750. {
  2751. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2752. return dsi_vc_send_short(dsidev, channel,
  2753. MIPI_DSI_SET_MAXIMUM_RETURN_PACKET_SIZE, len, 0);
  2754. }
  2755. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2756. static int dsi_enter_ulps(struct platform_device *dsidev)
  2757. {
  2758. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2759. DECLARE_COMPLETION_ONSTACK(completion);
  2760. int r, i;
  2761. unsigned mask;
  2762. DSSDBG("Entering ULPS");
  2763. WARN_ON(!dsi_bus_is_locked(dsidev));
  2764. WARN_ON(dsi->ulps_enabled);
  2765. if (dsi->ulps_enabled)
  2766. return 0;
  2767. /* DDR_CLK_ALWAYS_ON */
  2768. if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
  2769. dsi_if_enable(dsidev, 0);
  2770. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 13, 13);
  2771. dsi_if_enable(dsidev, 1);
  2772. }
  2773. dsi_sync_vc(dsidev, 0);
  2774. dsi_sync_vc(dsidev, 1);
  2775. dsi_sync_vc(dsidev, 2);
  2776. dsi_sync_vc(dsidev, 3);
  2777. dsi_force_tx_stop_mode_io(dsidev);
  2778. dsi_vc_enable(dsidev, 0, false);
  2779. dsi_vc_enable(dsidev, 1, false);
  2780. dsi_vc_enable(dsidev, 2, false);
  2781. dsi_vc_enable(dsidev, 3, false);
  2782. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
  2783. DSSERR("HS busy when enabling ULPS\n");
  2784. return -EIO;
  2785. }
  2786. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
  2787. DSSERR("LP busy when enabling ULPS\n");
  2788. return -EIO;
  2789. }
  2790. r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
  2791. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2792. if (r)
  2793. return r;
  2794. mask = 0;
  2795. for (i = 0; i < dsi->num_lanes_supported; ++i) {
  2796. if (dsi->lanes[i].function == DSI_LANE_UNUSED)
  2797. continue;
  2798. mask |= 1 << i;
  2799. }
  2800. /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
  2801. /* LANEx_ULPS_SIG2 */
  2802. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, mask, 9, 5);
  2803. /* flush posted write and wait for SCP interface to finish the write */
  2804. dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
  2805. if (wait_for_completion_timeout(&completion,
  2806. msecs_to_jiffies(1000)) == 0) {
  2807. DSSERR("ULPS enable timeout\n");
  2808. r = -EIO;
  2809. goto err;
  2810. }
  2811. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2812. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2813. /* Reset LANEx_ULPS_SIG2 */
  2814. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, 0, 9, 5);
  2815. /* flush posted write and wait for SCP interface to finish the write */
  2816. dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG2);
  2817. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
  2818. dsi_if_enable(dsidev, false);
  2819. dsi->ulps_enabled = true;
  2820. return 0;
  2821. err:
  2822. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2823. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2824. return r;
  2825. }
  2826. static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
  2827. unsigned ticks, bool x4, bool x16)
  2828. {
  2829. unsigned long fck;
  2830. unsigned long total_ticks;
  2831. u32 r;
  2832. BUG_ON(ticks > 0x1fff);
  2833. /* ticks in DSI_FCK */
  2834. fck = dsi_fclk_rate(dsidev);
  2835. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2836. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  2837. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2838. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2839. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2840. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2841. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2842. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2843. total_ticks,
  2844. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2845. (total_ticks * 1000) / (fck / 1000 / 1000));
  2846. }
  2847. static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
  2848. bool x8, bool x16)
  2849. {
  2850. unsigned long fck;
  2851. unsigned long total_ticks;
  2852. u32 r;
  2853. BUG_ON(ticks > 0x1fff);
  2854. /* ticks in DSI_FCK */
  2855. fck = dsi_fclk_rate(dsidev);
  2856. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2857. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  2858. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2859. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2860. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2861. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2862. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2863. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2864. total_ticks,
  2865. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2866. (total_ticks * 1000) / (fck / 1000 / 1000));
  2867. }
  2868. static void dsi_set_stop_state_counter(struct platform_device *dsidev,
  2869. unsigned ticks, bool x4, bool x16)
  2870. {
  2871. unsigned long fck;
  2872. unsigned long total_ticks;
  2873. u32 r;
  2874. BUG_ON(ticks > 0x1fff);
  2875. /* ticks in DSI_FCK */
  2876. fck = dsi_fclk_rate(dsidev);
  2877. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2878. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2879. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2880. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2881. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2882. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2883. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2884. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2885. total_ticks,
  2886. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2887. (total_ticks * 1000) / (fck / 1000 / 1000));
  2888. }
  2889. static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
  2890. unsigned ticks, bool x4, bool x16)
  2891. {
  2892. unsigned long fck;
  2893. unsigned long total_ticks;
  2894. u32 r;
  2895. BUG_ON(ticks > 0x1fff);
  2896. /* ticks in TxByteClkHS */
  2897. fck = dsi_get_txbyteclkhs(dsidev);
  2898. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2899. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  2900. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2901. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2902. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2903. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2904. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2905. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2906. total_ticks,
  2907. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2908. (total_ticks * 1000) / (fck / 1000 / 1000));
  2909. }
  2910. static void dsi_config_vp_num_line_buffers(struct platform_device *dsidev)
  2911. {
  2912. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2913. int num_line_buffers;
  2914. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  2915. int bpp = dsi_get_pixel_size(dsi->pix_fmt);
  2916. struct omap_video_timings *timings = &dsi->timings;
  2917. /*
  2918. * Don't use line buffers if width is greater than the video
  2919. * port's line buffer size
  2920. */
  2921. if (dsi->line_buffer_size <= timings->x_res * bpp / 8)
  2922. num_line_buffers = 0;
  2923. else
  2924. num_line_buffers = 2;
  2925. } else {
  2926. /* Use maximum number of line buffers in command mode */
  2927. num_line_buffers = 2;
  2928. }
  2929. /* LINE_BUFFER */
  2930. REG_FLD_MOD(dsidev, DSI_CTRL, num_line_buffers, 13, 12);
  2931. }
  2932. static void dsi_config_vp_sync_events(struct platform_device *dsidev)
  2933. {
  2934. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2935. bool sync_end;
  2936. u32 r;
  2937. if (dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE)
  2938. sync_end = true;
  2939. else
  2940. sync_end = false;
  2941. r = dsi_read_reg(dsidev, DSI_CTRL);
  2942. r = FLD_MOD(r, 1, 9, 9); /* VP_DE_POL */
  2943. r = FLD_MOD(r, 1, 10, 10); /* VP_HSYNC_POL */
  2944. r = FLD_MOD(r, 1, 11, 11); /* VP_VSYNC_POL */
  2945. r = FLD_MOD(r, 1, 15, 15); /* VP_VSYNC_START */
  2946. r = FLD_MOD(r, sync_end, 16, 16); /* VP_VSYNC_END */
  2947. r = FLD_MOD(r, 1, 17, 17); /* VP_HSYNC_START */
  2948. r = FLD_MOD(r, sync_end, 18, 18); /* VP_HSYNC_END */
  2949. dsi_write_reg(dsidev, DSI_CTRL, r);
  2950. }
  2951. static void dsi_config_blanking_modes(struct platform_device *dsidev)
  2952. {
  2953. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2954. int blanking_mode = dsi->vm_timings.blanking_mode;
  2955. int hfp_blanking_mode = dsi->vm_timings.hfp_blanking_mode;
  2956. int hbp_blanking_mode = dsi->vm_timings.hbp_blanking_mode;
  2957. int hsa_blanking_mode = dsi->vm_timings.hsa_blanking_mode;
  2958. u32 r;
  2959. /*
  2960. * 0 = TX FIFO packets sent or LPS in corresponding blanking periods
  2961. * 1 = Long blanking packets are sent in corresponding blanking periods
  2962. */
  2963. r = dsi_read_reg(dsidev, DSI_CTRL);
  2964. r = FLD_MOD(r, blanking_mode, 20, 20); /* BLANKING_MODE */
  2965. r = FLD_MOD(r, hfp_blanking_mode, 21, 21); /* HFP_BLANKING */
  2966. r = FLD_MOD(r, hbp_blanking_mode, 22, 22); /* HBP_BLANKING */
  2967. r = FLD_MOD(r, hsa_blanking_mode, 23, 23); /* HSA_BLANKING */
  2968. dsi_write_reg(dsidev, DSI_CTRL, r);
  2969. }
  2970. /*
  2971. * According to section 'HS Command Mode Interleaving' in OMAP TRM, Scenario 3
  2972. * results in maximum transition time for data and clock lanes to enter and
  2973. * exit HS mode. Hence, this is the scenario where the least amount of command
  2974. * mode data can be interleaved. We program the minimum amount of TXBYTECLKHS
  2975. * clock cycles that can be used to interleave command mode data in HS so that
  2976. * all scenarios are satisfied.
  2977. */
  2978. static int dsi_compute_interleave_hs(int blank, bool ddr_alwon, int enter_hs,
  2979. int exit_hs, int exiths_clk, int ddr_pre, int ddr_post)
  2980. {
  2981. int transition;
  2982. /*
  2983. * If DDR_CLK_ALWAYS_ON is set, we need to consider HS mode transition
  2984. * time of data lanes only, if it isn't set, we need to consider HS
  2985. * transition time of both data and clock lanes. HS transition time
  2986. * of Scenario 3 is considered.
  2987. */
  2988. if (ddr_alwon) {
  2989. transition = enter_hs + exit_hs + max(enter_hs, 2) + 1;
  2990. } else {
  2991. int trans1, trans2;
  2992. trans1 = ddr_pre + enter_hs + exit_hs + max(enter_hs, 2) + 1;
  2993. trans2 = ddr_pre + enter_hs + exiths_clk + ddr_post + ddr_pre +
  2994. enter_hs + 1;
  2995. transition = max(trans1, trans2);
  2996. }
  2997. return blank > transition ? blank - transition : 0;
  2998. }
  2999. /*
  3000. * According to section 'LP Command Mode Interleaving' in OMAP TRM, Scenario 1
  3001. * results in maximum transition time for data lanes to enter and exit LP mode.
  3002. * Hence, this is the scenario where the least amount of command mode data can
  3003. * be interleaved. We program the minimum amount of bytes that can be
  3004. * interleaved in LP so that all scenarios are satisfied.
  3005. */
  3006. static int dsi_compute_interleave_lp(int blank, int enter_hs, int exit_hs,
  3007. int lp_clk_div, int tdsi_fclk)
  3008. {
  3009. int trans_lp; /* time required for a LP transition, in TXBYTECLKHS */
  3010. int tlp_avail; /* time left for interleaving commands, in CLKIN4DDR */
  3011. int ttxclkesc; /* period of LP transmit escape clock, in CLKIN4DDR */
  3012. int thsbyte_clk = 16; /* Period of TXBYTECLKHS clock, in CLKIN4DDR */
  3013. int lp_inter; /* cmd mode data that can be interleaved, in bytes */
  3014. /* maximum LP transition time according to Scenario 1 */
  3015. trans_lp = exit_hs + max(enter_hs, 2) + 1;
  3016. /* CLKIN4DDR = 16 * TXBYTECLKHS */
  3017. tlp_avail = thsbyte_clk * (blank - trans_lp);
  3018. ttxclkesc = tdsi_fclk * lp_clk_div;
  3019. lp_inter = ((tlp_avail - 8 * thsbyte_clk - 5 * tdsi_fclk) / ttxclkesc -
  3020. 26) / 16;
  3021. return max(lp_inter, 0);
  3022. }
  3023. static void dsi_config_cmd_mode_interleaving(struct platform_device *dsidev)
  3024. {
  3025. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3026. int blanking_mode;
  3027. int hfp_blanking_mode, hbp_blanking_mode, hsa_blanking_mode;
  3028. int hsa, hfp, hbp, width_bytes, bllp, lp_clk_div;
  3029. int ddr_clk_pre, ddr_clk_post, enter_hs_mode_lat, exit_hs_mode_lat;
  3030. int tclk_trail, ths_exit, exiths_clk;
  3031. bool ddr_alwon;
  3032. struct omap_video_timings *timings = &dsi->timings;
  3033. int bpp = dsi_get_pixel_size(dsi->pix_fmt);
  3034. int ndl = dsi->num_lanes_used - 1;
  3035. int dsi_fclk_hsdiv = dsi->user_dsi_cinfo.regm_dsi + 1;
  3036. int hsa_interleave_hs = 0, hsa_interleave_lp = 0;
  3037. int hfp_interleave_hs = 0, hfp_interleave_lp = 0;
  3038. int hbp_interleave_hs = 0, hbp_interleave_lp = 0;
  3039. int bl_interleave_hs = 0, bl_interleave_lp = 0;
  3040. u32 r;
  3041. r = dsi_read_reg(dsidev, DSI_CTRL);
  3042. blanking_mode = FLD_GET(r, 20, 20);
  3043. hfp_blanking_mode = FLD_GET(r, 21, 21);
  3044. hbp_blanking_mode = FLD_GET(r, 22, 22);
  3045. hsa_blanking_mode = FLD_GET(r, 23, 23);
  3046. r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
  3047. hbp = FLD_GET(r, 11, 0);
  3048. hfp = FLD_GET(r, 23, 12);
  3049. hsa = FLD_GET(r, 31, 24);
  3050. r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
  3051. ddr_clk_post = FLD_GET(r, 7, 0);
  3052. ddr_clk_pre = FLD_GET(r, 15, 8);
  3053. r = dsi_read_reg(dsidev, DSI_VM_TIMING7);
  3054. exit_hs_mode_lat = FLD_GET(r, 15, 0);
  3055. enter_hs_mode_lat = FLD_GET(r, 31, 16);
  3056. r = dsi_read_reg(dsidev, DSI_CLK_CTRL);
  3057. lp_clk_div = FLD_GET(r, 12, 0);
  3058. ddr_alwon = FLD_GET(r, 13, 13);
  3059. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  3060. ths_exit = FLD_GET(r, 7, 0);
  3061. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  3062. tclk_trail = FLD_GET(r, 15, 8);
  3063. exiths_clk = ths_exit + tclk_trail;
  3064. width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
  3065. bllp = hbp + hfp + hsa + DIV_ROUND_UP(width_bytes + 6, ndl);
  3066. if (!hsa_blanking_mode) {
  3067. hsa_interleave_hs = dsi_compute_interleave_hs(hsa, ddr_alwon,
  3068. enter_hs_mode_lat, exit_hs_mode_lat,
  3069. exiths_clk, ddr_clk_pre, ddr_clk_post);
  3070. hsa_interleave_lp = dsi_compute_interleave_lp(hsa,
  3071. enter_hs_mode_lat, exit_hs_mode_lat,
  3072. lp_clk_div, dsi_fclk_hsdiv);
  3073. }
  3074. if (!hfp_blanking_mode) {
  3075. hfp_interleave_hs = dsi_compute_interleave_hs(hfp, ddr_alwon,
  3076. enter_hs_mode_lat, exit_hs_mode_lat,
  3077. exiths_clk, ddr_clk_pre, ddr_clk_post);
  3078. hfp_interleave_lp = dsi_compute_interleave_lp(hfp,
  3079. enter_hs_mode_lat, exit_hs_mode_lat,
  3080. lp_clk_div, dsi_fclk_hsdiv);
  3081. }
  3082. if (!hbp_blanking_mode) {
  3083. hbp_interleave_hs = dsi_compute_interleave_hs(hbp, ddr_alwon,
  3084. enter_hs_mode_lat, exit_hs_mode_lat,
  3085. exiths_clk, ddr_clk_pre, ddr_clk_post);
  3086. hbp_interleave_lp = dsi_compute_interleave_lp(hbp,
  3087. enter_hs_mode_lat, exit_hs_mode_lat,
  3088. lp_clk_div, dsi_fclk_hsdiv);
  3089. }
  3090. if (!blanking_mode) {
  3091. bl_interleave_hs = dsi_compute_interleave_hs(bllp, ddr_alwon,
  3092. enter_hs_mode_lat, exit_hs_mode_lat,
  3093. exiths_clk, ddr_clk_pre, ddr_clk_post);
  3094. bl_interleave_lp = dsi_compute_interleave_lp(bllp,
  3095. enter_hs_mode_lat, exit_hs_mode_lat,
  3096. lp_clk_div, dsi_fclk_hsdiv);
  3097. }
  3098. DSSDBG("DSI HS interleaving(TXBYTECLKHS) HSA %d, HFP %d, HBP %d, BLLP %d\n",
  3099. hsa_interleave_hs, hfp_interleave_hs, hbp_interleave_hs,
  3100. bl_interleave_hs);
  3101. DSSDBG("DSI LP interleaving(bytes) HSA %d, HFP %d, HBP %d, BLLP %d\n",
  3102. hsa_interleave_lp, hfp_interleave_lp, hbp_interleave_lp,
  3103. bl_interleave_lp);
  3104. r = dsi_read_reg(dsidev, DSI_VM_TIMING4);
  3105. r = FLD_MOD(r, hsa_interleave_hs, 23, 16);
  3106. r = FLD_MOD(r, hfp_interleave_hs, 15, 8);
  3107. r = FLD_MOD(r, hbp_interleave_hs, 7, 0);
  3108. dsi_write_reg(dsidev, DSI_VM_TIMING4, r);
  3109. r = dsi_read_reg(dsidev, DSI_VM_TIMING5);
  3110. r = FLD_MOD(r, hsa_interleave_lp, 23, 16);
  3111. r = FLD_MOD(r, hfp_interleave_lp, 15, 8);
  3112. r = FLD_MOD(r, hbp_interleave_lp, 7, 0);
  3113. dsi_write_reg(dsidev, DSI_VM_TIMING5, r);
  3114. r = dsi_read_reg(dsidev, DSI_VM_TIMING6);
  3115. r = FLD_MOD(r, bl_interleave_hs, 31, 15);
  3116. r = FLD_MOD(r, bl_interleave_lp, 16, 0);
  3117. dsi_write_reg(dsidev, DSI_VM_TIMING6, r);
  3118. }
  3119. static int dsi_proto_config(struct platform_device *dsidev)
  3120. {
  3121. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3122. u32 r;
  3123. int buswidth = 0;
  3124. dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
  3125. DSI_FIFO_SIZE_32,
  3126. DSI_FIFO_SIZE_32,
  3127. DSI_FIFO_SIZE_32);
  3128. dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
  3129. DSI_FIFO_SIZE_32,
  3130. DSI_FIFO_SIZE_32,
  3131. DSI_FIFO_SIZE_32);
  3132. /* XXX what values for the timeouts? */
  3133. dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
  3134. dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
  3135. dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
  3136. dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
  3137. switch (dsi_get_pixel_size(dsi->pix_fmt)) {
  3138. case 16:
  3139. buswidth = 0;
  3140. break;
  3141. case 18:
  3142. buswidth = 1;
  3143. break;
  3144. case 24:
  3145. buswidth = 2;
  3146. break;
  3147. default:
  3148. BUG();
  3149. return -EINVAL;
  3150. }
  3151. r = dsi_read_reg(dsidev, DSI_CTRL);
  3152. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  3153. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  3154. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  3155. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  3156. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  3157. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  3158. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  3159. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  3160. if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  3161. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  3162. /* DCS_CMD_CODE, 1=start, 0=continue */
  3163. r = FLD_MOD(r, 0, 25, 25);
  3164. }
  3165. dsi_write_reg(dsidev, DSI_CTRL, r);
  3166. dsi_config_vp_num_line_buffers(dsidev);
  3167. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  3168. dsi_config_vp_sync_events(dsidev);
  3169. dsi_config_blanking_modes(dsidev);
  3170. dsi_config_cmd_mode_interleaving(dsidev);
  3171. }
  3172. dsi_vc_initial_config(dsidev, 0);
  3173. dsi_vc_initial_config(dsidev, 1);
  3174. dsi_vc_initial_config(dsidev, 2);
  3175. dsi_vc_initial_config(dsidev, 3);
  3176. return 0;
  3177. }
  3178. static void dsi_proto_timings(struct platform_device *dsidev)
  3179. {
  3180. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3181. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  3182. unsigned tclk_pre, tclk_post;
  3183. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  3184. unsigned ths_trail, ths_exit;
  3185. unsigned ddr_clk_pre, ddr_clk_post;
  3186. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  3187. unsigned ths_eot;
  3188. int ndl = dsi->num_lanes_used - 1;
  3189. u32 r;
  3190. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  3191. ths_prepare = FLD_GET(r, 31, 24);
  3192. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  3193. ths_zero = ths_prepare_ths_zero - ths_prepare;
  3194. ths_trail = FLD_GET(r, 15, 8);
  3195. ths_exit = FLD_GET(r, 7, 0);
  3196. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  3197. tlpx = FLD_GET(r, 20, 16) * 2;
  3198. tclk_trail = FLD_GET(r, 15, 8);
  3199. tclk_zero = FLD_GET(r, 7, 0);
  3200. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  3201. tclk_prepare = FLD_GET(r, 7, 0);
  3202. /* min 8*UI */
  3203. tclk_pre = 20;
  3204. /* min 60ns + 52*UI */
  3205. tclk_post = ns2ddr(dsidev, 60) + 26;
  3206. ths_eot = DIV_ROUND_UP(4, ndl);
  3207. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  3208. 4);
  3209. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  3210. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  3211. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  3212. r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
  3213. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  3214. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  3215. dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
  3216. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  3217. ddr_clk_pre,
  3218. ddr_clk_post);
  3219. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  3220. DIV_ROUND_UP(ths_prepare, 4) +
  3221. DIV_ROUND_UP(ths_zero + 3, 4);
  3222. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  3223. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  3224. FLD_VAL(exit_hs_mode_lat, 15, 0);
  3225. dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
  3226. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  3227. enter_hs_mode_lat, exit_hs_mode_lat);
  3228. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  3229. /* TODO: Implement a video mode check_timings function */
  3230. int hsa = dsi->vm_timings.hsa;
  3231. int hfp = dsi->vm_timings.hfp;
  3232. int hbp = dsi->vm_timings.hbp;
  3233. int vsa = dsi->vm_timings.vsa;
  3234. int vfp = dsi->vm_timings.vfp;
  3235. int vbp = dsi->vm_timings.vbp;
  3236. int window_sync = dsi->vm_timings.window_sync;
  3237. bool hsync_end;
  3238. struct omap_video_timings *timings = &dsi->timings;
  3239. int bpp = dsi_get_pixel_size(dsi->pix_fmt);
  3240. int tl, t_he, width_bytes;
  3241. hsync_end = dsi->vm_timings.trans_mode == OMAP_DSS_DSI_PULSE_MODE;
  3242. t_he = hsync_end ?
  3243. ((hsa == 0 && ndl == 3) ? 1 : DIV_ROUND_UP(4, ndl)) : 0;
  3244. width_bytes = DIV_ROUND_UP(timings->x_res * bpp, 8);
  3245. /* TL = t_HS + HSA + t_HE + HFP + ceil((WC + 6) / NDL) + HBP */
  3246. tl = DIV_ROUND_UP(4, ndl) + (hsync_end ? hsa : 0) + t_he + hfp +
  3247. DIV_ROUND_UP(width_bytes + 6, ndl) + hbp;
  3248. DSSDBG("HBP: %d, HFP: %d, HSA: %d, TL: %d TXBYTECLKHS\n", hbp,
  3249. hfp, hsync_end ? hsa : 0, tl);
  3250. DSSDBG("VBP: %d, VFP: %d, VSA: %d, VACT: %d lines\n", vbp, vfp,
  3251. vsa, timings->y_res);
  3252. r = dsi_read_reg(dsidev, DSI_VM_TIMING1);
  3253. r = FLD_MOD(r, hbp, 11, 0); /* HBP */
  3254. r = FLD_MOD(r, hfp, 23, 12); /* HFP */
  3255. r = FLD_MOD(r, hsync_end ? hsa : 0, 31, 24); /* HSA */
  3256. dsi_write_reg(dsidev, DSI_VM_TIMING1, r);
  3257. r = dsi_read_reg(dsidev, DSI_VM_TIMING2);
  3258. r = FLD_MOD(r, vbp, 7, 0); /* VBP */
  3259. r = FLD_MOD(r, vfp, 15, 8); /* VFP */
  3260. r = FLD_MOD(r, vsa, 23, 16); /* VSA */
  3261. r = FLD_MOD(r, window_sync, 27, 24); /* WINDOW_SYNC */
  3262. dsi_write_reg(dsidev, DSI_VM_TIMING2, r);
  3263. r = dsi_read_reg(dsidev, DSI_VM_TIMING3);
  3264. r = FLD_MOD(r, timings->y_res, 14, 0); /* VACT */
  3265. r = FLD_MOD(r, tl, 31, 16); /* TL */
  3266. dsi_write_reg(dsidev, DSI_VM_TIMING3, r);
  3267. }
  3268. }
  3269. int omapdss_dsi_configure_pins(struct omap_dss_device *dssdev,
  3270. const struct omap_dsi_pin_config *pin_cfg)
  3271. {
  3272. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3273. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3274. int num_pins;
  3275. const int *pins;
  3276. struct dsi_lane_config lanes[DSI_MAX_NR_LANES];
  3277. int num_lanes;
  3278. int i;
  3279. static const enum dsi_lane_function functions[] = {
  3280. DSI_LANE_CLK,
  3281. DSI_LANE_DATA1,
  3282. DSI_LANE_DATA2,
  3283. DSI_LANE_DATA3,
  3284. DSI_LANE_DATA4,
  3285. };
  3286. num_pins = pin_cfg->num_pins;
  3287. pins = pin_cfg->pins;
  3288. if (num_pins < 4 || num_pins > dsi->num_lanes_supported * 2
  3289. || num_pins % 2 != 0)
  3290. return -EINVAL;
  3291. for (i = 0; i < DSI_MAX_NR_LANES; ++i)
  3292. lanes[i].function = DSI_LANE_UNUSED;
  3293. num_lanes = 0;
  3294. for (i = 0; i < num_pins; i += 2) {
  3295. u8 lane, pol;
  3296. int dx, dy;
  3297. dx = pins[i];
  3298. dy = pins[i + 1];
  3299. if (dx < 0 || dx >= dsi->num_lanes_supported * 2)
  3300. return -EINVAL;
  3301. if (dy < 0 || dy >= dsi->num_lanes_supported * 2)
  3302. return -EINVAL;
  3303. if (dx & 1) {
  3304. if (dy != dx - 1)
  3305. return -EINVAL;
  3306. pol = 1;
  3307. } else {
  3308. if (dy != dx + 1)
  3309. return -EINVAL;
  3310. pol = 0;
  3311. }
  3312. lane = dx / 2;
  3313. lanes[lane].function = functions[i / 2];
  3314. lanes[lane].polarity = pol;
  3315. num_lanes++;
  3316. }
  3317. memcpy(dsi->lanes, lanes, sizeof(dsi->lanes));
  3318. dsi->num_lanes_used = num_lanes;
  3319. return 0;
  3320. }
  3321. EXPORT_SYMBOL(omapdss_dsi_configure_pins);
  3322. int dsi_enable_video_output(struct omap_dss_device *dssdev, int channel)
  3323. {
  3324. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3325. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3326. struct omap_overlay_manager *mgr = dsi->output.manager;
  3327. int bpp = dsi_get_pixel_size(dsi->pix_fmt);
  3328. struct omap_dss_device *out = &dsi->output;
  3329. u8 data_type;
  3330. u16 word_count;
  3331. int r;
  3332. if (out == NULL || out->manager == NULL) {
  3333. DSSERR("failed to enable display: no output/manager\n");
  3334. return -ENODEV;
  3335. }
  3336. r = dsi_display_init_dispc(dsidev, mgr);
  3337. if (r)
  3338. goto err_init_dispc;
  3339. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  3340. switch (dsi->pix_fmt) {
  3341. case OMAP_DSS_DSI_FMT_RGB888:
  3342. data_type = MIPI_DSI_PACKED_PIXEL_STREAM_24;
  3343. break;
  3344. case OMAP_DSS_DSI_FMT_RGB666:
  3345. data_type = MIPI_DSI_PIXEL_STREAM_3BYTE_18;
  3346. break;
  3347. case OMAP_DSS_DSI_FMT_RGB666_PACKED:
  3348. data_type = MIPI_DSI_PACKED_PIXEL_STREAM_18;
  3349. break;
  3350. case OMAP_DSS_DSI_FMT_RGB565:
  3351. data_type = MIPI_DSI_PACKED_PIXEL_STREAM_16;
  3352. break;
  3353. default:
  3354. r = -EINVAL;
  3355. goto err_pix_fmt;
  3356. };
  3357. dsi_if_enable(dsidev, false);
  3358. dsi_vc_enable(dsidev, channel, false);
  3359. /* MODE, 1 = video mode */
  3360. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 4, 4);
  3361. word_count = DIV_ROUND_UP(dsi->timings.x_res * bpp, 8);
  3362. dsi_vc_write_long_header(dsidev, channel, data_type,
  3363. word_count, 0);
  3364. dsi_vc_enable(dsidev, channel, true);
  3365. dsi_if_enable(dsidev, true);
  3366. }
  3367. r = dss_mgr_enable(mgr);
  3368. if (r)
  3369. goto err_mgr_enable;
  3370. return 0;
  3371. err_mgr_enable:
  3372. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  3373. dsi_if_enable(dsidev, false);
  3374. dsi_vc_enable(dsidev, channel, false);
  3375. }
  3376. err_pix_fmt:
  3377. dsi_display_uninit_dispc(dsidev, mgr);
  3378. err_init_dispc:
  3379. return r;
  3380. }
  3381. EXPORT_SYMBOL(dsi_enable_video_output);
  3382. void dsi_disable_video_output(struct omap_dss_device *dssdev, int channel)
  3383. {
  3384. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3385. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3386. struct omap_overlay_manager *mgr = dsi->output.manager;
  3387. if (dsi->mode == OMAP_DSS_DSI_VIDEO_MODE) {
  3388. dsi_if_enable(dsidev, false);
  3389. dsi_vc_enable(dsidev, channel, false);
  3390. /* MODE, 0 = command mode */
  3391. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 4, 4);
  3392. dsi_vc_enable(dsidev, channel, true);
  3393. dsi_if_enable(dsidev, true);
  3394. }
  3395. dss_mgr_disable(mgr);
  3396. dsi_display_uninit_dispc(dsidev, mgr);
  3397. }
  3398. EXPORT_SYMBOL(dsi_disable_video_output);
  3399. static void dsi_update_screen_dispc(struct platform_device *dsidev)
  3400. {
  3401. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3402. struct omap_overlay_manager *mgr = dsi->output.manager;
  3403. unsigned bytespp;
  3404. unsigned bytespl;
  3405. unsigned bytespf;
  3406. unsigned total_len;
  3407. unsigned packet_payload;
  3408. unsigned packet_len;
  3409. u32 l;
  3410. int r;
  3411. const unsigned channel = dsi->update_channel;
  3412. const unsigned line_buf_size = dsi->line_buffer_size;
  3413. u16 w = dsi->timings.x_res;
  3414. u16 h = dsi->timings.y_res;
  3415. DSSDBG("dsi_update_screen_dispc(%dx%d)\n", w, h);
  3416. dsi_vc_config_source(dsidev, channel, DSI_VC_SOURCE_VP);
  3417. bytespp = dsi_get_pixel_size(dsi->pix_fmt) / 8;
  3418. bytespl = w * bytespp;
  3419. bytespf = bytespl * h;
  3420. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  3421. * number of lines in a packet. See errata about VP_CLK_RATIO */
  3422. if (bytespf < line_buf_size)
  3423. packet_payload = bytespf;
  3424. else
  3425. packet_payload = (line_buf_size) / bytespl * bytespl;
  3426. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  3427. total_len = (bytespf / packet_payload) * packet_len;
  3428. if (bytespf % packet_payload)
  3429. total_len += (bytespf % packet_payload) + 1;
  3430. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  3431. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  3432. dsi_vc_write_long_header(dsidev, channel, MIPI_DSI_DCS_LONG_WRITE,
  3433. packet_len, 0);
  3434. if (dsi->te_enabled)
  3435. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  3436. else
  3437. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  3438. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  3439. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  3440. * because DSS interrupts are not capable of waking up the CPU and the
  3441. * framedone interrupt could be delayed for quite a long time. I think
  3442. * the same goes for any DSS interrupts, but for some reason I have not
  3443. * seen the problem anywhere else than here.
  3444. */
  3445. dispc_disable_sidle();
  3446. dsi_perf_mark_start(dsidev);
  3447. r = schedule_delayed_work(&dsi->framedone_timeout_work,
  3448. msecs_to_jiffies(250));
  3449. BUG_ON(r == 0);
  3450. dss_mgr_set_timings(mgr, &dsi->timings);
  3451. dss_mgr_start_update(mgr);
  3452. if (dsi->te_enabled) {
  3453. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  3454. * for TE is longer than the timer allows */
  3455. REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  3456. dsi_vc_send_bta(dsidev, channel);
  3457. #ifdef DSI_CATCH_MISSING_TE
  3458. mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
  3459. #endif
  3460. }
  3461. }
  3462. #ifdef DSI_CATCH_MISSING_TE
  3463. static void dsi_te_timeout(unsigned long arg)
  3464. {
  3465. DSSERR("TE not received for 250ms!\n");
  3466. }
  3467. #endif
  3468. static void dsi_handle_framedone(struct platform_device *dsidev, int error)
  3469. {
  3470. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3471. /* SIDLEMODE back to smart-idle */
  3472. dispc_enable_sidle();
  3473. if (dsi->te_enabled) {
  3474. /* enable LP_RX_TO again after the TE */
  3475. REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  3476. }
  3477. dsi->framedone_callback(error, dsi->framedone_data);
  3478. if (!error)
  3479. dsi_perf_show(dsidev, "DISPC");
  3480. }
  3481. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  3482. {
  3483. struct dsi_data *dsi = container_of(work, struct dsi_data,
  3484. framedone_timeout_work.work);
  3485. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  3486. * 250ms which would conflict with this timeout work. What should be
  3487. * done is first cancel the transfer on the HW, and then cancel the
  3488. * possibly scheduled framedone work. However, cancelling the transfer
  3489. * on the HW is buggy, and would probably require resetting the whole
  3490. * DSI */
  3491. DSSERR("Framedone not received for 250ms!\n");
  3492. dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
  3493. }
  3494. static void dsi_framedone_irq_callback(void *data)
  3495. {
  3496. struct platform_device *dsidev = (struct platform_device *) data;
  3497. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3498. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  3499. * turns itself off. However, DSI still has the pixels in its buffers,
  3500. * and is sending the data.
  3501. */
  3502. cancel_delayed_work(&dsi->framedone_timeout_work);
  3503. dsi_handle_framedone(dsidev, 0);
  3504. }
  3505. int omap_dsi_update(struct omap_dss_device *dssdev, int channel,
  3506. void (*callback)(int, void *), void *data)
  3507. {
  3508. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3509. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3510. u16 dw, dh;
  3511. dsi_perf_mark_setup(dsidev);
  3512. dsi->update_channel = channel;
  3513. dsi->framedone_callback = callback;
  3514. dsi->framedone_data = data;
  3515. dw = dsi->timings.x_res;
  3516. dh = dsi->timings.y_res;
  3517. #ifdef DEBUG
  3518. dsi->update_bytes = dw * dh *
  3519. dsi_get_pixel_size(dsi->pix_fmt) / 8;
  3520. #endif
  3521. dsi_update_screen_dispc(dsidev);
  3522. return 0;
  3523. }
  3524. EXPORT_SYMBOL(omap_dsi_update);
  3525. /* Display funcs */
  3526. static int dsi_configure_dispc_clocks(struct platform_device *dsidev)
  3527. {
  3528. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3529. struct dispc_clock_info dispc_cinfo;
  3530. int r;
  3531. unsigned long fck;
  3532. fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  3533. dispc_cinfo.lck_div = dsi->user_dispc_cinfo.lck_div;
  3534. dispc_cinfo.pck_div = dsi->user_dispc_cinfo.pck_div;
  3535. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  3536. if (r) {
  3537. DSSERR("Failed to calc dispc clocks\n");
  3538. return r;
  3539. }
  3540. dsi->mgr_config.clock_info = dispc_cinfo;
  3541. return 0;
  3542. }
  3543. static int dsi_display_init_dispc(struct platform_device *dsidev,
  3544. struct omap_overlay_manager *mgr)
  3545. {
  3546. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3547. int r;
  3548. dss_select_lcd_clk_source(mgr->id, dsi->module_id == 0 ?
  3549. OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC :
  3550. OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC);
  3551. if (dsi->mode == OMAP_DSS_DSI_CMD_MODE) {
  3552. r = dss_mgr_register_framedone_handler(mgr,
  3553. dsi_framedone_irq_callback, dsidev);
  3554. if (r) {
  3555. DSSERR("can't register FRAMEDONE handler\n");
  3556. goto err;
  3557. }
  3558. dsi->mgr_config.stallmode = true;
  3559. dsi->mgr_config.fifohandcheck = true;
  3560. } else {
  3561. dsi->mgr_config.stallmode = false;
  3562. dsi->mgr_config.fifohandcheck = false;
  3563. }
  3564. /*
  3565. * override interlace, logic level and edge related parameters in
  3566. * omap_video_timings with default values
  3567. */
  3568. dsi->timings.interlace = false;
  3569. dsi->timings.hsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
  3570. dsi->timings.vsync_level = OMAPDSS_SIG_ACTIVE_HIGH;
  3571. dsi->timings.data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE;
  3572. dsi->timings.de_level = OMAPDSS_SIG_ACTIVE_HIGH;
  3573. dsi->timings.sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES;
  3574. dss_mgr_set_timings(mgr, &dsi->timings);
  3575. r = dsi_configure_dispc_clocks(dsidev);
  3576. if (r)
  3577. goto err1;
  3578. dsi->mgr_config.io_pad_mode = DSS_IO_PAD_MODE_BYPASS;
  3579. dsi->mgr_config.video_port_width =
  3580. dsi_get_pixel_size(dsi->pix_fmt);
  3581. dsi->mgr_config.lcden_sig_polarity = 0;
  3582. dss_mgr_set_lcd_config(mgr, &dsi->mgr_config);
  3583. return 0;
  3584. err1:
  3585. if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
  3586. dss_mgr_unregister_framedone_handler(mgr,
  3587. dsi_framedone_irq_callback, dsidev);
  3588. err:
  3589. dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
  3590. return r;
  3591. }
  3592. static void dsi_display_uninit_dispc(struct platform_device *dsidev,
  3593. struct omap_overlay_manager *mgr)
  3594. {
  3595. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3596. if (dsi->mode == OMAP_DSS_DSI_CMD_MODE)
  3597. dss_mgr_unregister_framedone_handler(mgr,
  3598. dsi_framedone_irq_callback, dsidev);
  3599. dss_select_lcd_clk_source(mgr->id, OMAP_DSS_CLK_SRC_FCK);
  3600. }
  3601. static int dsi_configure_dsi_clocks(struct platform_device *dsidev)
  3602. {
  3603. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3604. struct dsi_clock_info cinfo;
  3605. int r;
  3606. cinfo = dsi->user_dsi_cinfo;
  3607. r = dsi_calc_clock_rates(dsidev, &cinfo);
  3608. if (r) {
  3609. DSSERR("Failed to calc dsi clocks\n");
  3610. return r;
  3611. }
  3612. r = dsi_pll_set_clock_div(dsidev, &cinfo);
  3613. if (r) {
  3614. DSSERR("Failed to set dsi clocks\n");
  3615. return r;
  3616. }
  3617. return 0;
  3618. }
  3619. static int dsi_display_init_dsi(struct platform_device *dsidev)
  3620. {
  3621. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3622. int r;
  3623. r = dsi_pll_init(dsidev, true, true);
  3624. if (r)
  3625. goto err0;
  3626. r = dsi_configure_dsi_clocks(dsidev);
  3627. if (r)
  3628. goto err1;
  3629. dss_select_dsi_clk_source(dsi->module_id, dsi->module_id == 0 ?
  3630. OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI :
  3631. OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DSI);
  3632. DSSDBG("PLL OK\n");
  3633. r = dsi_cio_init(dsidev);
  3634. if (r)
  3635. goto err2;
  3636. _dsi_print_reset_status(dsidev);
  3637. dsi_proto_timings(dsidev);
  3638. dsi_set_lp_clk_divisor(dsidev);
  3639. if (1)
  3640. _dsi_print_reset_status(dsidev);
  3641. r = dsi_proto_config(dsidev);
  3642. if (r)
  3643. goto err3;
  3644. /* enable interface */
  3645. dsi_vc_enable(dsidev, 0, 1);
  3646. dsi_vc_enable(dsidev, 1, 1);
  3647. dsi_vc_enable(dsidev, 2, 1);
  3648. dsi_vc_enable(dsidev, 3, 1);
  3649. dsi_if_enable(dsidev, 1);
  3650. dsi_force_tx_stop_mode_io(dsidev);
  3651. return 0;
  3652. err3:
  3653. dsi_cio_uninit(dsidev);
  3654. err2:
  3655. dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
  3656. err1:
  3657. dsi_pll_uninit(dsidev, true);
  3658. err0:
  3659. return r;
  3660. }
  3661. static void dsi_display_uninit_dsi(struct platform_device *dsidev,
  3662. bool disconnect_lanes, bool enter_ulps)
  3663. {
  3664. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3665. if (enter_ulps && !dsi->ulps_enabled)
  3666. dsi_enter_ulps(dsidev);
  3667. /* disable interface */
  3668. dsi_if_enable(dsidev, 0);
  3669. dsi_vc_enable(dsidev, 0, 0);
  3670. dsi_vc_enable(dsidev, 1, 0);
  3671. dsi_vc_enable(dsidev, 2, 0);
  3672. dsi_vc_enable(dsidev, 3, 0);
  3673. dss_select_dsi_clk_source(dsi->module_id, OMAP_DSS_CLK_SRC_FCK);
  3674. dsi_cio_uninit(dsidev);
  3675. dsi_pll_uninit(dsidev, disconnect_lanes);
  3676. }
  3677. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  3678. {
  3679. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3680. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3681. int r = 0;
  3682. DSSDBG("dsi_display_enable\n");
  3683. WARN_ON(!dsi_bus_is_locked(dsidev));
  3684. mutex_lock(&dsi->lock);
  3685. r = dsi_runtime_get(dsidev);
  3686. if (r)
  3687. goto err_get_dsi;
  3688. dsi_enable_pll_clock(dsidev, 1);
  3689. _dsi_initialize_irq(dsidev);
  3690. r = dsi_display_init_dsi(dsidev);
  3691. if (r)
  3692. goto err_init_dsi;
  3693. mutex_unlock(&dsi->lock);
  3694. return 0;
  3695. err_init_dsi:
  3696. dsi_enable_pll_clock(dsidev, 0);
  3697. dsi_runtime_put(dsidev);
  3698. err_get_dsi:
  3699. mutex_unlock(&dsi->lock);
  3700. DSSDBG("dsi_display_enable FAILED\n");
  3701. return r;
  3702. }
  3703. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  3704. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
  3705. bool disconnect_lanes, bool enter_ulps)
  3706. {
  3707. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3708. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3709. DSSDBG("dsi_display_disable\n");
  3710. WARN_ON(!dsi_bus_is_locked(dsidev));
  3711. mutex_lock(&dsi->lock);
  3712. dsi_sync_vc(dsidev, 0);
  3713. dsi_sync_vc(dsidev, 1);
  3714. dsi_sync_vc(dsidev, 2);
  3715. dsi_sync_vc(dsidev, 3);
  3716. dsi_display_uninit_dsi(dsidev, disconnect_lanes, enter_ulps);
  3717. dsi_runtime_put(dsidev);
  3718. dsi_enable_pll_clock(dsidev, 0);
  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. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  4189. {
  4190. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  4191. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4192. int i;
  4193. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  4194. if (!dsi->vc[i].dssdev) {
  4195. dsi->vc[i].dssdev = dssdev;
  4196. *channel = i;
  4197. return 0;
  4198. }
  4199. }
  4200. DSSERR("cannot get VC for display %s", dssdev->name);
  4201. return -ENOSPC;
  4202. }
  4203. EXPORT_SYMBOL(omap_dsi_request_vc);
  4204. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  4205. {
  4206. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  4207. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4208. if (vc_id < 0 || vc_id > 3) {
  4209. DSSERR("VC ID out of range\n");
  4210. return -EINVAL;
  4211. }
  4212. if (channel < 0 || channel > 3) {
  4213. DSSERR("Virtual Channel out of range\n");
  4214. return -EINVAL;
  4215. }
  4216. if (dsi->vc[channel].dssdev != dssdev) {
  4217. DSSERR("Virtual Channel not allocated to display %s\n",
  4218. dssdev->name);
  4219. return -EINVAL;
  4220. }
  4221. dsi->vc[channel].vc_id = vc_id;
  4222. return 0;
  4223. }
  4224. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  4225. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  4226. {
  4227. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  4228. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4229. if ((channel >= 0 && channel <= 3) &&
  4230. dsi->vc[channel].dssdev == dssdev) {
  4231. dsi->vc[channel].dssdev = NULL;
  4232. dsi->vc[channel].vc_id = 0;
  4233. }
  4234. }
  4235. EXPORT_SYMBOL(omap_dsi_release_vc);
  4236. void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
  4237. {
  4238. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
  4239. DSSERR("%s (%s) not active\n",
  4240. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  4241. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  4242. }
  4243. void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
  4244. {
  4245. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
  4246. DSSERR("%s (%s) not active\n",
  4247. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  4248. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  4249. }
  4250. static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
  4251. {
  4252. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4253. dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  4254. dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  4255. dsi->regm_dispc_max =
  4256. dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  4257. dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  4258. dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  4259. dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  4260. dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  4261. }
  4262. static int dsi_get_clocks(struct platform_device *dsidev)
  4263. {
  4264. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4265. struct clk *clk;
  4266. clk = devm_clk_get(&dsidev->dev, "fck");
  4267. if (IS_ERR(clk)) {
  4268. DSSERR("can't get fck\n");
  4269. return PTR_ERR(clk);
  4270. }
  4271. dsi->dss_clk = clk;
  4272. clk = devm_clk_get(&dsidev->dev, "sys_clk");
  4273. if (IS_ERR(clk)) {
  4274. DSSERR("can't get sys_clk\n");
  4275. return PTR_ERR(clk);
  4276. }
  4277. dsi->sys_clk = clk;
  4278. return 0;
  4279. }
  4280. static struct omap_dss_device *dsi_find_dssdev(struct platform_device *pdev)
  4281. {
  4282. struct omap_dss_board_info *pdata = pdev->dev.platform_data;
  4283. struct dsi_data *dsi = dsi_get_dsidrv_data(pdev);
  4284. const char *def_disp_name = omapdss_get_default_display_name();
  4285. struct omap_dss_device *def_dssdev;
  4286. int i;
  4287. def_dssdev = NULL;
  4288. for (i = 0; i < pdata->num_devices; ++i) {
  4289. struct omap_dss_device *dssdev = pdata->devices[i];
  4290. if (dssdev->type != OMAP_DISPLAY_TYPE_DSI)
  4291. continue;
  4292. if (dssdev->phy.dsi.module != dsi->module_id)
  4293. continue;
  4294. if (def_dssdev == NULL)
  4295. def_dssdev = dssdev;
  4296. if (def_disp_name != NULL &&
  4297. strcmp(dssdev->name, def_disp_name) == 0) {
  4298. def_dssdev = dssdev;
  4299. break;
  4300. }
  4301. }
  4302. return def_dssdev;
  4303. }
  4304. static int dsi_probe_pdata(struct platform_device *dsidev)
  4305. {
  4306. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4307. struct omap_dss_device *plat_dssdev;
  4308. struct omap_dss_device *dssdev;
  4309. int r;
  4310. plat_dssdev = dsi_find_dssdev(dsidev);
  4311. if (!plat_dssdev)
  4312. return 0;
  4313. r = dsi_regulator_init(dsidev);
  4314. if (r)
  4315. return r;
  4316. dssdev = dss_alloc_and_init_device(&dsidev->dev);
  4317. if (!dssdev)
  4318. return -ENOMEM;
  4319. dss_copy_device_pdata(dssdev, plat_dssdev);
  4320. r = omapdss_output_set_device(&dsi->output, dssdev);
  4321. if (r) {
  4322. DSSERR("failed to connect output to new device: %s\n",
  4323. dssdev->name);
  4324. dss_put_device(dssdev);
  4325. return r;
  4326. }
  4327. r = dss_add_device(dssdev);
  4328. if (r) {
  4329. DSSERR("device %s register failed: %d\n", dssdev->name, r);
  4330. omapdss_output_unset_device(&dsi->output);
  4331. dss_put_device(dssdev);
  4332. return r;
  4333. }
  4334. return 0;
  4335. }
  4336. static void dsi_init_output(struct platform_device *dsidev)
  4337. {
  4338. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4339. struct omap_dss_device *out = &dsi->output;
  4340. out->dev = &dsidev->dev;
  4341. out->id = dsi->module_id == 0 ?
  4342. OMAP_DSS_OUTPUT_DSI1 : OMAP_DSS_OUTPUT_DSI2;
  4343. out->output_type = OMAP_DISPLAY_TYPE_DSI;
  4344. out->name = dsi->module_id == 0 ? "dsi.0" : "dsi.1";
  4345. out->dispc_channel = dsi_get_channel(dsi->module_id);
  4346. out->owner = THIS_MODULE;
  4347. omapdss_register_output(out);
  4348. }
  4349. static void dsi_uninit_output(struct platform_device *dsidev)
  4350. {
  4351. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4352. struct omap_dss_device *out = &dsi->output;
  4353. omapdss_unregister_output(out);
  4354. }
  4355. /* DSI1 HW IP initialisation */
  4356. static int omap_dsihw_probe(struct platform_device *dsidev)
  4357. {
  4358. u32 rev;
  4359. int r, i;
  4360. struct resource *dsi_mem;
  4361. struct dsi_data *dsi;
  4362. dsi = devm_kzalloc(&dsidev->dev, sizeof(*dsi), GFP_KERNEL);
  4363. if (!dsi)
  4364. return -ENOMEM;
  4365. dsi->module_id = dsidev->id;
  4366. dsi->pdev = dsidev;
  4367. dev_set_drvdata(&dsidev->dev, dsi);
  4368. spin_lock_init(&dsi->irq_lock);
  4369. spin_lock_init(&dsi->errors_lock);
  4370. dsi->errors = 0;
  4371. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  4372. spin_lock_init(&dsi->irq_stats_lock);
  4373. dsi->irq_stats.last_reset = jiffies;
  4374. #endif
  4375. mutex_init(&dsi->lock);
  4376. sema_init(&dsi->bus_lock, 1);
  4377. INIT_DEFERRABLE_WORK(&dsi->framedone_timeout_work,
  4378. dsi_framedone_timeout_work_callback);
  4379. #ifdef DSI_CATCH_MISSING_TE
  4380. init_timer(&dsi->te_timer);
  4381. dsi->te_timer.function = dsi_te_timeout;
  4382. dsi->te_timer.data = 0;
  4383. #endif
  4384. dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
  4385. if (!dsi_mem) {
  4386. DSSERR("can't get IORESOURCE_MEM DSI\n");
  4387. return -EINVAL;
  4388. }
  4389. dsi->base = devm_ioremap(&dsidev->dev, dsi_mem->start,
  4390. resource_size(dsi_mem));
  4391. if (!dsi->base) {
  4392. DSSERR("can't ioremap DSI\n");
  4393. return -ENOMEM;
  4394. }
  4395. dsi->irq = platform_get_irq(dsi->pdev, 0);
  4396. if (dsi->irq < 0) {
  4397. DSSERR("platform_get_irq failed\n");
  4398. return -ENODEV;
  4399. }
  4400. r = devm_request_irq(&dsidev->dev, dsi->irq, omap_dsi_irq_handler,
  4401. IRQF_SHARED, dev_name(&dsidev->dev), dsi->pdev);
  4402. if (r < 0) {
  4403. DSSERR("request_irq failed\n");
  4404. return r;
  4405. }
  4406. /* DSI VCs initialization */
  4407. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  4408. dsi->vc[i].source = DSI_VC_SOURCE_L4;
  4409. dsi->vc[i].dssdev = NULL;
  4410. dsi->vc[i].vc_id = 0;
  4411. }
  4412. dsi_calc_clock_param_ranges(dsidev);
  4413. r = dsi_get_clocks(dsidev);
  4414. if (r)
  4415. return r;
  4416. pm_runtime_enable(&dsidev->dev);
  4417. r = dsi_runtime_get(dsidev);
  4418. if (r)
  4419. goto err_runtime_get;
  4420. rev = dsi_read_reg(dsidev, DSI_REVISION);
  4421. dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
  4422. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  4423. /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
  4424. * of data to 3 by default */
  4425. if (dss_has_feature(FEAT_DSI_GNQ))
  4426. /* NB_DATA_LANES */
  4427. dsi->num_lanes_supported = 1 + REG_GET(dsidev, DSI_GNQ, 11, 9);
  4428. else
  4429. dsi->num_lanes_supported = 3;
  4430. dsi->line_buffer_size = dsi_get_line_buf_size(dsidev);
  4431. dsi_init_output(dsidev);
  4432. if (dsidev->dev.platform_data) {
  4433. r = dsi_probe_pdata(dsidev);
  4434. if (r)
  4435. goto err_probe;
  4436. }
  4437. dsi_runtime_put(dsidev);
  4438. if (dsi->module_id == 0)
  4439. dss_debugfs_create_file("dsi1_regs", dsi1_dump_regs);
  4440. else if (dsi->module_id == 1)
  4441. dss_debugfs_create_file("dsi2_regs", dsi2_dump_regs);
  4442. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  4443. if (dsi->module_id == 0)
  4444. dss_debugfs_create_file("dsi1_irqs", dsi1_dump_irqs);
  4445. else if (dsi->module_id == 1)
  4446. dss_debugfs_create_file("dsi2_irqs", dsi2_dump_irqs);
  4447. #endif
  4448. return 0;
  4449. err_probe:
  4450. dsi_runtime_put(dsidev);
  4451. dsi_uninit_output(dsidev);
  4452. err_runtime_get:
  4453. pm_runtime_disable(&dsidev->dev);
  4454. return r;
  4455. }
  4456. static int __exit omap_dsihw_remove(struct platform_device *dsidev)
  4457. {
  4458. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  4459. WARN_ON(dsi->scp_clk_refcount > 0);
  4460. dss_unregister_child_devices(&dsidev->dev);
  4461. dsi_uninit_output(dsidev);
  4462. pm_runtime_disable(&dsidev->dev);
  4463. if (dsi->vdds_dsi_reg != NULL && dsi->vdds_dsi_enabled) {
  4464. regulator_disable(dsi->vdds_dsi_reg);
  4465. dsi->vdds_dsi_enabled = false;
  4466. }
  4467. return 0;
  4468. }
  4469. static int dsi_runtime_suspend(struct device *dev)
  4470. {
  4471. dispc_runtime_put();
  4472. return 0;
  4473. }
  4474. static int dsi_runtime_resume(struct device *dev)
  4475. {
  4476. int r;
  4477. r = dispc_runtime_get();
  4478. if (r)
  4479. return r;
  4480. return 0;
  4481. }
  4482. static const struct dev_pm_ops dsi_pm_ops = {
  4483. .runtime_suspend = dsi_runtime_suspend,
  4484. .runtime_resume = dsi_runtime_resume,
  4485. };
  4486. static struct platform_driver omap_dsihw_driver = {
  4487. .probe = omap_dsihw_probe,
  4488. .remove = __exit_p(omap_dsihw_remove),
  4489. .driver = {
  4490. .name = "omapdss_dsi",
  4491. .owner = THIS_MODULE,
  4492. .pm = &dsi_pm_ops,
  4493. },
  4494. };
  4495. int __init dsi_init_platform_driver(void)
  4496. {
  4497. return platform_driver_register(&omap_dsihw_driver);
  4498. }
  4499. void __exit dsi_uninit_platform_driver(void)
  4500. {
  4501. platform_driver_unregister(&omap_dsihw_driver);
  4502. }