dsi.c 135 KB

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