dsi.c 128 KB

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