dsi.c 138 KB

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