dsi.c 132 KB

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