dsi.c 141 KB

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