dsi.c 140 KB

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