dsi.c 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790
  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/semaphore.h>
  29. #include <linux/seq_file.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/regulator/consumer.h>
  32. #include <linux/wait.h>
  33. #include <linux/workqueue.h>
  34. #include <plat/display.h>
  35. #include <plat/clock.h>
  36. #include "dss.h"
  37. #include "dss_features.h"
  38. /*#define VERBOSE_IRQ*/
  39. #define DSI_CATCH_MISSING_TE
  40. struct dsi_reg { u16 idx; };
  41. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  42. #define DSI_SZ_REGS SZ_1K
  43. /* DSI Protocol Engine */
  44. #define DSI_REVISION DSI_REG(0x0000)
  45. #define DSI_SYSCONFIG DSI_REG(0x0010)
  46. #define DSI_SYSSTATUS DSI_REG(0x0014)
  47. #define DSI_IRQSTATUS DSI_REG(0x0018)
  48. #define DSI_IRQENABLE DSI_REG(0x001C)
  49. #define DSI_CTRL DSI_REG(0x0040)
  50. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  51. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  52. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  53. #define DSI_CLK_CTRL DSI_REG(0x0054)
  54. #define DSI_TIMING1 DSI_REG(0x0058)
  55. #define DSI_TIMING2 DSI_REG(0x005C)
  56. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  57. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  58. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  59. #define DSI_CLK_TIMING DSI_REG(0x006C)
  60. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  61. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  62. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  63. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  64. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  65. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  66. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  67. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  68. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  69. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  70. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  71. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  72. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  73. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  74. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  75. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  76. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  77. /* DSIPHY_SCP */
  78. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  79. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  80. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  81. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  82. /* DSI_PLL_CTRL_SCP */
  83. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  84. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  85. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  86. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  87. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  88. #define REG_GET(idx, start, end) \
  89. FLD_GET(dsi_read_reg(idx), start, end)
  90. #define REG_FLD_MOD(idx, val, start, end) \
  91. dsi_write_reg(idx, FLD_MOD(dsi_read_reg(idx), val, start, end))
  92. /* Global interrupts */
  93. #define DSI_IRQ_VC0 (1 << 0)
  94. #define DSI_IRQ_VC1 (1 << 1)
  95. #define DSI_IRQ_VC2 (1 << 2)
  96. #define DSI_IRQ_VC3 (1 << 3)
  97. #define DSI_IRQ_WAKEUP (1 << 4)
  98. #define DSI_IRQ_RESYNC (1 << 5)
  99. #define DSI_IRQ_PLL_LOCK (1 << 7)
  100. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  101. #define DSI_IRQ_PLL_RECALL (1 << 9)
  102. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  103. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  104. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  105. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  106. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  107. #define DSI_IRQ_SYNC_LOST (1 << 18)
  108. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  109. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  110. #define DSI_IRQ_ERROR_MASK \
  111. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  112. DSI_IRQ_TA_TIMEOUT)
  113. #define DSI_IRQ_CHANNEL_MASK 0xf
  114. /* Virtual channel interrupts */
  115. #define DSI_VC_IRQ_CS (1 << 0)
  116. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  117. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  118. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  119. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  120. #define DSI_VC_IRQ_BTA (1 << 5)
  121. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  122. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  123. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  124. #define DSI_VC_IRQ_ERROR_MASK \
  125. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  126. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  127. DSI_VC_IRQ_FIFO_TX_UDF)
  128. /* ComplexIO interrupts */
  129. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  130. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  131. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  132. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  133. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  134. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  135. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  136. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  137. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  138. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  139. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  140. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  141. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  142. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  143. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  144. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  145. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  146. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  147. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  148. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  149. #define DSI_CIO_IRQ_ERROR_MASK \
  150. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  151. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  152. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRCONTROL1 | \
  153. DSI_CIO_IRQ_ERRCONTROL2 | DSI_CIO_IRQ_ERRCONTROL3 | \
  154. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  155. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  156. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3)
  157. #define DSI_DT_DCS_SHORT_WRITE_0 0x05
  158. #define DSI_DT_DCS_SHORT_WRITE_1 0x15
  159. #define DSI_DT_DCS_READ 0x06
  160. #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
  161. #define DSI_DT_NULL_PACKET 0x09
  162. #define DSI_DT_DCS_LONG_WRITE 0x39
  163. #define DSI_DT_RX_ACK_WITH_ERR 0x02
  164. #define DSI_DT_RX_DCS_LONG_READ 0x1c
  165. #define DSI_DT_RX_SHORT_READ_1 0x21
  166. #define DSI_DT_RX_SHORT_READ_2 0x22
  167. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  168. #define DSI_MAX_NR_ISRS 2
  169. struct dsi_isr_data {
  170. omap_dsi_isr_t isr;
  171. void *arg;
  172. u32 mask;
  173. };
  174. enum fifo_size {
  175. DSI_FIFO_SIZE_0 = 0,
  176. DSI_FIFO_SIZE_32 = 1,
  177. DSI_FIFO_SIZE_64 = 2,
  178. DSI_FIFO_SIZE_96 = 3,
  179. DSI_FIFO_SIZE_128 = 4,
  180. };
  181. enum dsi_vc_mode {
  182. DSI_VC_MODE_L4 = 0,
  183. DSI_VC_MODE_VP,
  184. };
  185. struct dsi_update_region {
  186. u16 x, y, w, h;
  187. struct omap_dss_device *device;
  188. };
  189. struct dsi_irq_stats {
  190. unsigned long last_reset;
  191. unsigned irq_count;
  192. unsigned dsi_irqs[32];
  193. unsigned vc_irqs[4][32];
  194. unsigned cio_irqs[32];
  195. };
  196. struct dsi_isr_tables {
  197. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  198. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  199. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  200. };
  201. static struct
  202. {
  203. struct platform_device *pdev;
  204. void __iomem *base;
  205. int irq;
  206. struct dsi_clock_info current_cinfo;
  207. struct regulator *vdds_dsi_reg;
  208. struct {
  209. enum dsi_vc_mode mode;
  210. struct omap_dss_device *dssdev;
  211. enum fifo_size fifo_size;
  212. int vc_id;
  213. } vc[4];
  214. struct mutex lock;
  215. struct semaphore bus_lock;
  216. unsigned pll_locked;
  217. spinlock_t irq_lock;
  218. struct dsi_isr_tables isr_tables;
  219. /* space for a copy used by the interrupt handler */
  220. struct dsi_isr_tables isr_tables_copy;
  221. int update_channel;
  222. struct dsi_update_region update_region;
  223. bool te_enabled;
  224. struct workqueue_struct *workqueue;
  225. void (*framedone_callback)(int, void *);
  226. void *framedone_data;
  227. struct delayed_work framedone_timeout_work;
  228. #ifdef DSI_CATCH_MISSING_TE
  229. struct timer_list te_timer;
  230. #endif
  231. unsigned long cache_req_pck;
  232. unsigned long cache_clk_freq;
  233. struct dsi_clock_info cache_cinfo;
  234. u32 errors;
  235. spinlock_t errors_lock;
  236. #ifdef DEBUG
  237. ktime_t perf_setup_time;
  238. ktime_t perf_start_time;
  239. #endif
  240. int debug_read;
  241. int debug_write;
  242. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  243. spinlock_t irq_stats_lock;
  244. struct dsi_irq_stats irq_stats;
  245. #endif
  246. /* DSI PLL Parameter Ranges */
  247. unsigned long regm_max, regn_max;
  248. unsigned long regm_dispc_max, regm_dsi_max;
  249. unsigned long fint_min, fint_max;
  250. unsigned long lpdiv_max;
  251. } dsi;
  252. #ifdef DEBUG
  253. static unsigned int dsi_perf;
  254. module_param_named(dsi_perf, dsi_perf, bool, 0644);
  255. #endif
  256. static inline void dsi_write_reg(const struct dsi_reg idx, u32 val)
  257. {
  258. __raw_writel(val, dsi.base + idx.idx);
  259. }
  260. static inline u32 dsi_read_reg(const struct dsi_reg idx)
  261. {
  262. return __raw_readl(dsi.base + idx.idx);
  263. }
  264. void dsi_save_context(void)
  265. {
  266. }
  267. void dsi_restore_context(void)
  268. {
  269. }
  270. void dsi_bus_lock(void)
  271. {
  272. down(&dsi.bus_lock);
  273. }
  274. EXPORT_SYMBOL(dsi_bus_lock);
  275. void dsi_bus_unlock(void)
  276. {
  277. up(&dsi.bus_lock);
  278. }
  279. EXPORT_SYMBOL(dsi_bus_unlock);
  280. static bool dsi_bus_is_locked(void)
  281. {
  282. return dsi.bus_lock.count == 0;
  283. }
  284. static void dsi_completion_handler(void *data, u32 mask)
  285. {
  286. complete((struct completion *)data);
  287. }
  288. static inline int wait_for_bit_change(const struct dsi_reg idx, int bitnum,
  289. int value)
  290. {
  291. int t = 100000;
  292. while (REG_GET(idx, bitnum, bitnum) != value) {
  293. if (--t == 0)
  294. return !value;
  295. }
  296. return value;
  297. }
  298. #ifdef DEBUG
  299. static void dsi_perf_mark_setup(void)
  300. {
  301. dsi.perf_setup_time = ktime_get();
  302. }
  303. static void dsi_perf_mark_start(void)
  304. {
  305. dsi.perf_start_time = ktime_get();
  306. }
  307. static void dsi_perf_show(const char *name)
  308. {
  309. ktime_t t, setup_time, trans_time;
  310. u32 total_bytes;
  311. u32 setup_us, trans_us, total_us;
  312. if (!dsi_perf)
  313. return;
  314. t = ktime_get();
  315. setup_time = ktime_sub(dsi.perf_start_time, dsi.perf_setup_time);
  316. setup_us = (u32)ktime_to_us(setup_time);
  317. if (setup_us == 0)
  318. setup_us = 1;
  319. trans_time = ktime_sub(t, dsi.perf_start_time);
  320. trans_us = (u32)ktime_to_us(trans_time);
  321. if (trans_us == 0)
  322. trans_us = 1;
  323. total_us = setup_us + trans_us;
  324. total_bytes = dsi.update_region.w *
  325. dsi.update_region.h *
  326. dsi.update_region.device->ctrl.pixel_size / 8;
  327. printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
  328. "%u bytes, %u kbytes/sec\n",
  329. name,
  330. setup_us,
  331. trans_us,
  332. total_us,
  333. 1000*1000 / total_us,
  334. total_bytes,
  335. total_bytes * 1000 / total_us);
  336. }
  337. #else
  338. #define dsi_perf_mark_setup()
  339. #define dsi_perf_mark_start()
  340. #define dsi_perf_show(x)
  341. #endif
  342. static void print_irq_status(u32 status)
  343. {
  344. if (status == 0)
  345. return;
  346. #ifndef VERBOSE_IRQ
  347. if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  348. return;
  349. #endif
  350. printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
  351. #define PIS(x) \
  352. if (status & DSI_IRQ_##x) \
  353. printk(#x " ");
  354. #ifdef VERBOSE_IRQ
  355. PIS(VC0);
  356. PIS(VC1);
  357. PIS(VC2);
  358. PIS(VC3);
  359. #endif
  360. PIS(WAKEUP);
  361. PIS(RESYNC);
  362. PIS(PLL_LOCK);
  363. PIS(PLL_UNLOCK);
  364. PIS(PLL_RECALL);
  365. PIS(COMPLEXIO_ERR);
  366. PIS(HS_TX_TIMEOUT);
  367. PIS(LP_RX_TIMEOUT);
  368. PIS(TE_TRIGGER);
  369. PIS(ACK_TRIGGER);
  370. PIS(SYNC_LOST);
  371. PIS(LDO_POWER_GOOD);
  372. PIS(TA_TIMEOUT);
  373. #undef PIS
  374. printk("\n");
  375. }
  376. static void print_irq_status_vc(int channel, u32 status)
  377. {
  378. if (status == 0)
  379. return;
  380. #ifndef VERBOSE_IRQ
  381. if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  382. return;
  383. #endif
  384. printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
  385. #define PIS(x) \
  386. if (status & DSI_VC_IRQ_##x) \
  387. printk(#x " ");
  388. PIS(CS);
  389. PIS(ECC_CORR);
  390. #ifdef VERBOSE_IRQ
  391. PIS(PACKET_SENT);
  392. #endif
  393. PIS(FIFO_TX_OVF);
  394. PIS(FIFO_RX_OVF);
  395. PIS(BTA);
  396. PIS(ECC_NO_CORR);
  397. PIS(FIFO_TX_UDF);
  398. PIS(PP_BUSY_CHANGE);
  399. #undef PIS
  400. printk("\n");
  401. }
  402. static void print_irq_status_cio(u32 status)
  403. {
  404. if (status == 0)
  405. return;
  406. printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
  407. #define PIS(x) \
  408. if (status & DSI_CIO_IRQ_##x) \
  409. printk(#x " ");
  410. PIS(ERRSYNCESC1);
  411. PIS(ERRSYNCESC2);
  412. PIS(ERRSYNCESC3);
  413. PIS(ERRESC1);
  414. PIS(ERRESC2);
  415. PIS(ERRESC3);
  416. PIS(ERRCONTROL1);
  417. PIS(ERRCONTROL2);
  418. PIS(ERRCONTROL3);
  419. PIS(STATEULPS1);
  420. PIS(STATEULPS2);
  421. PIS(STATEULPS3);
  422. PIS(ERRCONTENTIONLP0_1);
  423. PIS(ERRCONTENTIONLP1_1);
  424. PIS(ERRCONTENTIONLP0_2);
  425. PIS(ERRCONTENTIONLP1_2);
  426. PIS(ERRCONTENTIONLP0_3);
  427. PIS(ERRCONTENTIONLP1_3);
  428. PIS(ULPSACTIVENOT_ALL0);
  429. PIS(ULPSACTIVENOT_ALL1);
  430. #undef PIS
  431. printk("\n");
  432. }
  433. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  434. static void dsi_collect_irq_stats(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  435. {
  436. int i;
  437. spin_lock(&dsi.irq_stats_lock);
  438. dsi.irq_stats.irq_count++;
  439. dss_collect_irq_stats(irqstatus, dsi.irq_stats.dsi_irqs);
  440. for (i = 0; i < 4; ++i)
  441. dss_collect_irq_stats(vcstatus[i], dsi.irq_stats.vc_irqs[i]);
  442. dss_collect_irq_stats(ciostatus, dsi.irq_stats.cio_irqs);
  443. spin_unlock(&dsi.irq_stats_lock);
  444. }
  445. #else
  446. #define dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus)
  447. #endif
  448. static int debug_irq;
  449. static void dsi_handle_irq_errors(u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  450. {
  451. int i;
  452. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  453. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  454. print_irq_status(irqstatus);
  455. spin_lock(&dsi.errors_lock);
  456. dsi.errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  457. spin_unlock(&dsi.errors_lock);
  458. } else if (debug_irq) {
  459. print_irq_status(irqstatus);
  460. }
  461. for (i = 0; i < 4; ++i) {
  462. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  463. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  464. i, vcstatus[i]);
  465. print_irq_status_vc(i, vcstatus[i]);
  466. } else if (debug_irq) {
  467. print_irq_status_vc(i, vcstatus[i]);
  468. }
  469. }
  470. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  471. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  472. print_irq_status_cio(ciostatus);
  473. } else if (debug_irq) {
  474. print_irq_status_cio(ciostatus);
  475. }
  476. }
  477. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  478. unsigned isr_array_size, u32 irqstatus)
  479. {
  480. struct dsi_isr_data *isr_data;
  481. int i;
  482. for (i = 0; i < isr_array_size; i++) {
  483. isr_data = &isr_array[i];
  484. if (isr_data->isr && isr_data->mask & irqstatus)
  485. isr_data->isr(isr_data->arg, irqstatus);
  486. }
  487. }
  488. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  489. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  490. {
  491. int i;
  492. dsi_call_isrs(isr_tables->isr_table,
  493. ARRAY_SIZE(isr_tables->isr_table),
  494. irqstatus);
  495. for (i = 0; i < 4; ++i) {
  496. if (vcstatus[i] == 0)
  497. continue;
  498. dsi_call_isrs(isr_tables->isr_table_vc[i],
  499. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  500. vcstatus[i]);
  501. }
  502. if (ciostatus != 0)
  503. dsi_call_isrs(isr_tables->isr_table_cio,
  504. ARRAY_SIZE(isr_tables->isr_table_cio),
  505. ciostatus);
  506. }
  507. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  508. {
  509. u32 irqstatus, vcstatus[4], ciostatus;
  510. int i;
  511. spin_lock(&dsi.irq_lock);
  512. irqstatus = dsi_read_reg(DSI_IRQSTATUS);
  513. /* IRQ is not for us */
  514. if (!irqstatus) {
  515. spin_unlock(&dsi.irq_lock);
  516. return IRQ_NONE;
  517. }
  518. dsi_write_reg(DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  519. /* flush posted write */
  520. dsi_read_reg(DSI_IRQSTATUS);
  521. for (i = 0; i < 4; ++i) {
  522. if ((irqstatus & (1 << i)) == 0) {
  523. vcstatus[i] = 0;
  524. continue;
  525. }
  526. vcstatus[i] = dsi_read_reg(DSI_VC_IRQSTATUS(i));
  527. dsi_write_reg(DSI_VC_IRQSTATUS(i), vcstatus[i]);
  528. /* flush posted write */
  529. dsi_read_reg(DSI_VC_IRQSTATUS(i));
  530. }
  531. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  532. ciostatus = dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
  533. dsi_write_reg(DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  534. /* flush posted write */
  535. dsi_read_reg(DSI_COMPLEXIO_IRQ_STATUS);
  536. } else {
  537. ciostatus = 0;
  538. }
  539. #ifdef DSI_CATCH_MISSING_TE
  540. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  541. del_timer(&dsi.te_timer);
  542. #endif
  543. /* make a copy and unlock, so that isrs can unregister
  544. * themselves */
  545. memcpy(&dsi.isr_tables_copy, &dsi.isr_tables, sizeof(dsi.isr_tables));
  546. spin_unlock(&dsi.irq_lock);
  547. dsi_handle_isrs(&dsi.isr_tables_copy, irqstatus, vcstatus, ciostatus);
  548. dsi_handle_irq_errors(irqstatus, vcstatus, ciostatus);
  549. dsi_collect_irq_stats(irqstatus, vcstatus, ciostatus);
  550. return IRQ_HANDLED;
  551. }
  552. /* dsi.irq_lock has to be locked by the caller */
  553. static void _omap_dsi_configure_irqs(struct dsi_isr_data *isr_array,
  554. unsigned isr_array_size, u32 default_mask,
  555. const struct dsi_reg enable_reg,
  556. const struct dsi_reg status_reg)
  557. {
  558. struct dsi_isr_data *isr_data;
  559. u32 mask;
  560. u32 old_mask;
  561. int i;
  562. mask = default_mask;
  563. for (i = 0; i < isr_array_size; i++) {
  564. isr_data = &isr_array[i];
  565. if (isr_data->isr == NULL)
  566. continue;
  567. mask |= isr_data->mask;
  568. }
  569. old_mask = dsi_read_reg(enable_reg);
  570. /* clear the irqstatus for newly enabled irqs */
  571. dsi_write_reg(status_reg, (mask ^ old_mask) & mask);
  572. dsi_write_reg(enable_reg, mask);
  573. /* flush posted writes */
  574. dsi_read_reg(enable_reg);
  575. dsi_read_reg(status_reg);
  576. }
  577. /* dsi.irq_lock has to be locked by the caller */
  578. static void _omap_dsi_set_irqs(void)
  579. {
  580. u32 mask = DSI_IRQ_ERROR_MASK;
  581. #ifdef DSI_CATCH_MISSING_TE
  582. mask |= DSI_IRQ_TE_TRIGGER;
  583. #endif
  584. _omap_dsi_configure_irqs(dsi.isr_tables.isr_table,
  585. ARRAY_SIZE(dsi.isr_tables.isr_table), mask,
  586. DSI_IRQENABLE, DSI_IRQSTATUS);
  587. }
  588. /* dsi.irq_lock has to be locked by the caller */
  589. static void _omap_dsi_set_irqs_vc(int vc)
  590. {
  591. _omap_dsi_configure_irqs(dsi.isr_tables.isr_table_vc[vc],
  592. ARRAY_SIZE(dsi.isr_tables.isr_table_vc[vc]),
  593. DSI_VC_IRQ_ERROR_MASK,
  594. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  595. }
  596. /* dsi.irq_lock has to be locked by the caller */
  597. static void _omap_dsi_set_irqs_cio(void)
  598. {
  599. _omap_dsi_configure_irqs(dsi.isr_tables.isr_table_cio,
  600. ARRAY_SIZE(dsi.isr_tables.isr_table_cio),
  601. DSI_CIO_IRQ_ERROR_MASK,
  602. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  603. }
  604. static void _dsi_initialize_irq(void)
  605. {
  606. unsigned long flags;
  607. int vc;
  608. spin_lock_irqsave(&dsi.irq_lock, flags);
  609. memset(&dsi.isr_tables, 0, sizeof(dsi.isr_tables));
  610. _omap_dsi_set_irqs();
  611. for (vc = 0; vc < 4; ++vc)
  612. _omap_dsi_set_irqs_vc(vc);
  613. _omap_dsi_set_irqs_cio();
  614. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  615. }
  616. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  617. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  618. {
  619. struct dsi_isr_data *isr_data;
  620. int free_idx;
  621. int i;
  622. BUG_ON(isr == NULL);
  623. /* check for duplicate entry and find a free slot */
  624. free_idx = -1;
  625. for (i = 0; i < isr_array_size; i++) {
  626. isr_data = &isr_array[i];
  627. if (isr_data->isr == isr && isr_data->arg == arg &&
  628. isr_data->mask == mask) {
  629. return -EINVAL;
  630. }
  631. if (isr_data->isr == NULL && free_idx == -1)
  632. free_idx = i;
  633. }
  634. if (free_idx == -1)
  635. return -EBUSY;
  636. isr_data = &isr_array[free_idx];
  637. isr_data->isr = isr;
  638. isr_data->arg = arg;
  639. isr_data->mask = mask;
  640. return 0;
  641. }
  642. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  643. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  644. {
  645. struct dsi_isr_data *isr_data;
  646. int i;
  647. for (i = 0; i < isr_array_size; i++) {
  648. isr_data = &isr_array[i];
  649. if (isr_data->isr != isr || isr_data->arg != arg ||
  650. isr_data->mask != mask)
  651. continue;
  652. isr_data->isr = NULL;
  653. isr_data->arg = NULL;
  654. isr_data->mask = 0;
  655. return 0;
  656. }
  657. return -EINVAL;
  658. }
  659. static int dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask)
  660. {
  661. unsigned long flags;
  662. int r;
  663. spin_lock_irqsave(&dsi.irq_lock, flags);
  664. r = _dsi_register_isr(isr, arg, mask, dsi.isr_tables.isr_table,
  665. ARRAY_SIZE(dsi.isr_tables.isr_table));
  666. if (r == 0)
  667. _omap_dsi_set_irqs();
  668. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  669. return r;
  670. }
  671. static int dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask)
  672. {
  673. unsigned long flags;
  674. int r;
  675. spin_lock_irqsave(&dsi.irq_lock, flags);
  676. r = _dsi_unregister_isr(isr, arg, mask, dsi.isr_tables.isr_table,
  677. ARRAY_SIZE(dsi.isr_tables.isr_table));
  678. if (r == 0)
  679. _omap_dsi_set_irqs();
  680. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  681. return r;
  682. }
  683. static int dsi_register_isr_vc(int channel, omap_dsi_isr_t isr, void *arg,
  684. u32 mask)
  685. {
  686. unsigned long flags;
  687. int r;
  688. spin_lock_irqsave(&dsi.irq_lock, flags);
  689. r = _dsi_register_isr(isr, arg, mask,
  690. dsi.isr_tables.isr_table_vc[channel],
  691. ARRAY_SIZE(dsi.isr_tables.isr_table_vc[channel]));
  692. if (r == 0)
  693. _omap_dsi_set_irqs_vc(channel);
  694. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  695. return r;
  696. }
  697. static int dsi_unregister_isr_vc(int channel, omap_dsi_isr_t isr, void *arg,
  698. u32 mask)
  699. {
  700. unsigned long flags;
  701. int r;
  702. spin_lock_irqsave(&dsi.irq_lock, flags);
  703. r = _dsi_unregister_isr(isr, arg, mask,
  704. dsi.isr_tables.isr_table_vc[channel],
  705. ARRAY_SIZE(dsi.isr_tables.isr_table_vc[channel]));
  706. if (r == 0)
  707. _omap_dsi_set_irqs_vc(channel);
  708. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  709. return r;
  710. }
  711. static int dsi_register_isr_cio(omap_dsi_isr_t isr, void *arg, u32 mask)
  712. {
  713. unsigned long flags;
  714. int r;
  715. spin_lock_irqsave(&dsi.irq_lock, flags);
  716. r = _dsi_register_isr(isr, arg, mask, dsi.isr_tables.isr_table_cio,
  717. ARRAY_SIZE(dsi.isr_tables.isr_table_cio));
  718. if (r == 0)
  719. _omap_dsi_set_irqs_cio();
  720. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  721. return r;
  722. }
  723. static int dsi_unregister_isr_cio(omap_dsi_isr_t isr, void *arg, u32 mask)
  724. {
  725. unsigned long flags;
  726. int r;
  727. spin_lock_irqsave(&dsi.irq_lock, flags);
  728. r = _dsi_unregister_isr(isr, arg, mask, dsi.isr_tables.isr_table_cio,
  729. ARRAY_SIZE(dsi.isr_tables.isr_table_cio));
  730. if (r == 0)
  731. _omap_dsi_set_irqs_cio();
  732. spin_unlock_irqrestore(&dsi.irq_lock, flags);
  733. return r;
  734. }
  735. static u32 dsi_get_errors(void)
  736. {
  737. unsigned long flags;
  738. u32 e;
  739. spin_lock_irqsave(&dsi.errors_lock, flags);
  740. e = dsi.errors;
  741. dsi.errors = 0;
  742. spin_unlock_irqrestore(&dsi.errors_lock, flags);
  743. return e;
  744. }
  745. /* DSI func clock. this could also be dsi_pll_hsdiv_dsi_clk */
  746. static inline void enable_clocks(bool enable)
  747. {
  748. if (enable)
  749. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  750. else
  751. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  752. }
  753. /* source clock for DSI PLL. this could also be PCLKFREE */
  754. static inline void dsi_enable_pll_clock(bool enable)
  755. {
  756. if (enable)
  757. dss_clk_enable(DSS_CLK_SYSCK);
  758. else
  759. dss_clk_disable(DSS_CLK_SYSCK);
  760. if (enable && dsi.pll_locked) {
  761. if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1)
  762. DSSERR("cannot lock PLL when enabling clocks\n");
  763. }
  764. }
  765. #ifdef DEBUG
  766. static void _dsi_print_reset_status(void)
  767. {
  768. u32 l;
  769. if (!dss_debug)
  770. return;
  771. /* A dummy read using the SCP interface to any DSIPHY register is
  772. * required after DSIPHY reset to complete the reset of the DSI complex
  773. * I/O. */
  774. l = dsi_read_reg(DSI_DSIPHY_CFG5);
  775. printk(KERN_DEBUG "DSI resets: ");
  776. l = dsi_read_reg(DSI_PLL_STATUS);
  777. printk("PLL (%d) ", FLD_GET(l, 0, 0));
  778. l = dsi_read_reg(DSI_COMPLEXIO_CFG1);
  779. printk("CIO (%d) ", FLD_GET(l, 29, 29));
  780. l = dsi_read_reg(DSI_DSIPHY_CFG5);
  781. printk("PHY (%x, %d, %d, %d)\n",
  782. FLD_GET(l, 28, 26),
  783. FLD_GET(l, 29, 29),
  784. FLD_GET(l, 30, 30),
  785. FLD_GET(l, 31, 31));
  786. }
  787. #else
  788. #define _dsi_print_reset_status()
  789. #endif
  790. static inline int dsi_if_enable(bool enable)
  791. {
  792. DSSDBG("dsi_if_enable(%d)\n", enable);
  793. enable = enable ? 1 : 0;
  794. REG_FLD_MOD(DSI_CTRL, enable, 0, 0); /* IF_EN */
  795. if (wait_for_bit_change(DSI_CTRL, 0, enable) != enable) {
  796. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  797. return -EIO;
  798. }
  799. return 0;
  800. }
  801. unsigned long dsi_get_pll_hsdiv_dispc_rate(void)
  802. {
  803. return dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk;
  804. }
  805. static unsigned long dsi_get_pll_hsdiv_dsi_rate(void)
  806. {
  807. return dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk;
  808. }
  809. static unsigned long dsi_get_txbyteclkhs(void)
  810. {
  811. return dsi.current_cinfo.clkin4ddr / 16;
  812. }
  813. static unsigned long dsi_fclk_rate(void)
  814. {
  815. unsigned long r;
  816. if (dss_get_dsi_clk_source() == DSS_CLK_SRC_FCK) {
  817. /* DSI FCLK source is DSS_CLK_FCK */
  818. r = dss_clk_get_rate(DSS_CLK_FCK);
  819. } else {
  820. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  821. r = dsi_get_pll_hsdiv_dsi_rate();
  822. }
  823. return r;
  824. }
  825. static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
  826. {
  827. unsigned long dsi_fclk;
  828. unsigned lp_clk_div;
  829. unsigned long lp_clk;
  830. lp_clk_div = dssdev->phy.dsi.div.lp_clk_div;
  831. if (lp_clk_div == 0 || lp_clk_div > dsi.lpdiv_max)
  832. return -EINVAL;
  833. dsi_fclk = dsi_fclk_rate();
  834. lp_clk = dsi_fclk / 2 / lp_clk_div;
  835. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  836. dsi.current_cinfo.lp_clk = lp_clk;
  837. dsi.current_cinfo.lp_clk_div = lp_clk_div;
  838. REG_FLD_MOD(DSI_CLK_CTRL, lp_clk_div, 12, 0); /* LP_CLK_DIVISOR */
  839. REG_FLD_MOD(DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0,
  840. 21, 21); /* LP_RX_SYNCHRO_ENABLE */
  841. return 0;
  842. }
  843. enum dsi_pll_power_state {
  844. DSI_PLL_POWER_OFF = 0x0,
  845. DSI_PLL_POWER_ON_HSCLK = 0x1,
  846. DSI_PLL_POWER_ON_ALL = 0x2,
  847. DSI_PLL_POWER_ON_DIV = 0x3,
  848. };
  849. static int dsi_pll_power(enum dsi_pll_power_state state)
  850. {
  851. int t = 0;
  852. /* DSI-PLL power command 0x3 is not working */
  853. if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
  854. state == DSI_PLL_POWER_ON_DIV)
  855. state = DSI_PLL_POWER_ON_ALL;
  856. REG_FLD_MOD(DSI_CLK_CTRL, state, 31, 30); /* PLL_PWR_CMD */
  857. /* PLL_PWR_STATUS */
  858. while (FLD_GET(dsi_read_reg(DSI_CLK_CTRL), 29, 28) != state) {
  859. if (++t > 1000) {
  860. DSSERR("Failed to set DSI PLL power mode to %d\n",
  861. state);
  862. return -ENODEV;
  863. }
  864. udelay(1);
  865. }
  866. return 0;
  867. }
  868. /* calculate clock rates using dividers in cinfo */
  869. static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
  870. struct dsi_clock_info *cinfo)
  871. {
  872. if (cinfo->regn == 0 || cinfo->regn > dsi.regn_max)
  873. return -EINVAL;
  874. if (cinfo->regm == 0 || cinfo->regm > dsi.regm_max)
  875. return -EINVAL;
  876. if (cinfo->regm_dispc > dsi.regm_dispc_max)
  877. return -EINVAL;
  878. if (cinfo->regm_dsi > dsi.regm_dsi_max)
  879. return -EINVAL;
  880. if (cinfo->use_sys_clk) {
  881. cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
  882. /* XXX it is unclear if highfreq should be used
  883. * with DSS_SYS_CLK source also */
  884. cinfo->highfreq = 0;
  885. } else {
  886. cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
  887. if (cinfo->clkin < 32000000)
  888. cinfo->highfreq = 0;
  889. else
  890. cinfo->highfreq = 1;
  891. }
  892. cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
  893. if (cinfo->fint > dsi.fint_max || cinfo->fint < dsi.fint_min)
  894. return -EINVAL;
  895. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  896. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  897. return -EINVAL;
  898. if (cinfo->regm_dispc > 0)
  899. cinfo->dsi_pll_hsdiv_dispc_clk =
  900. cinfo->clkin4ddr / cinfo->regm_dispc;
  901. else
  902. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  903. if (cinfo->regm_dsi > 0)
  904. cinfo->dsi_pll_hsdiv_dsi_clk =
  905. cinfo->clkin4ddr / cinfo->regm_dsi;
  906. else
  907. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  908. return 0;
  909. }
  910. int dsi_pll_calc_clock_div_pck(bool is_tft, unsigned long req_pck,
  911. struct dsi_clock_info *dsi_cinfo,
  912. struct dispc_clock_info *dispc_cinfo)
  913. {
  914. struct dsi_clock_info cur, best;
  915. struct dispc_clock_info best_dispc;
  916. int min_fck_per_pck;
  917. int match = 0;
  918. unsigned long dss_sys_clk, max_dss_fck;
  919. dss_sys_clk = dss_clk_get_rate(DSS_CLK_SYSCK);
  920. max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  921. if (req_pck == dsi.cache_req_pck &&
  922. dsi.cache_cinfo.clkin == dss_sys_clk) {
  923. DSSDBG("DSI clock info found from cache\n");
  924. *dsi_cinfo = dsi.cache_cinfo;
  925. dispc_find_clk_divs(is_tft, req_pck,
  926. dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
  927. return 0;
  928. }
  929. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  930. if (min_fck_per_pck &&
  931. req_pck * min_fck_per_pck > max_dss_fck) {
  932. DSSERR("Requested pixel clock not possible with the current "
  933. "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
  934. "the constraint off.\n");
  935. min_fck_per_pck = 0;
  936. }
  937. DSSDBG("dsi_pll_calc\n");
  938. retry:
  939. memset(&best, 0, sizeof(best));
  940. memset(&best_dispc, 0, sizeof(best_dispc));
  941. memset(&cur, 0, sizeof(cur));
  942. cur.clkin = dss_sys_clk;
  943. cur.use_sys_clk = 1;
  944. cur.highfreq = 0;
  945. /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
  946. /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
  947. /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
  948. for (cur.regn = 1; cur.regn < dsi.regn_max; ++cur.regn) {
  949. if (cur.highfreq == 0)
  950. cur.fint = cur.clkin / cur.regn;
  951. else
  952. cur.fint = cur.clkin / (2 * cur.regn);
  953. if (cur.fint > dsi.fint_max || cur.fint < dsi.fint_min)
  954. continue;
  955. /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
  956. for (cur.regm = 1; cur.regm < dsi.regm_max; ++cur.regm) {
  957. unsigned long a, b;
  958. a = 2 * cur.regm * (cur.clkin/1000);
  959. b = cur.regn * (cur.highfreq + 1);
  960. cur.clkin4ddr = a / b * 1000;
  961. if (cur.clkin4ddr > 1800 * 1000 * 1000)
  962. break;
  963. /* dsi_pll_hsdiv_dispc_clk(MHz) =
  964. * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
  965. for (cur.regm_dispc = 1; cur.regm_dispc < dsi.regm_dispc_max;
  966. ++cur.regm_dispc) {
  967. struct dispc_clock_info cur_dispc;
  968. cur.dsi_pll_hsdiv_dispc_clk =
  969. cur.clkin4ddr / cur.regm_dispc;
  970. /* this will narrow down the search a bit,
  971. * but still give pixclocks below what was
  972. * requested */
  973. if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
  974. break;
  975. if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
  976. continue;
  977. if (min_fck_per_pck &&
  978. cur.dsi_pll_hsdiv_dispc_clk <
  979. req_pck * min_fck_per_pck)
  980. continue;
  981. match = 1;
  982. dispc_find_clk_divs(is_tft, req_pck,
  983. cur.dsi_pll_hsdiv_dispc_clk,
  984. &cur_dispc);
  985. if (abs(cur_dispc.pck - req_pck) <
  986. abs(best_dispc.pck - req_pck)) {
  987. best = cur;
  988. best_dispc = cur_dispc;
  989. if (cur_dispc.pck == req_pck)
  990. goto found;
  991. }
  992. }
  993. }
  994. }
  995. found:
  996. if (!match) {
  997. if (min_fck_per_pck) {
  998. DSSERR("Could not find suitable clock settings.\n"
  999. "Turning FCK/PCK constraint off and"
  1000. "trying again.\n");
  1001. min_fck_per_pck = 0;
  1002. goto retry;
  1003. }
  1004. DSSERR("Could not find suitable clock settings.\n");
  1005. return -EINVAL;
  1006. }
  1007. /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
  1008. best.regm_dsi = 0;
  1009. best.dsi_pll_hsdiv_dsi_clk = 0;
  1010. if (dsi_cinfo)
  1011. *dsi_cinfo = best;
  1012. if (dispc_cinfo)
  1013. *dispc_cinfo = best_dispc;
  1014. dsi.cache_req_pck = req_pck;
  1015. dsi.cache_clk_freq = 0;
  1016. dsi.cache_cinfo = best;
  1017. return 0;
  1018. }
  1019. int dsi_pll_set_clock_div(struct dsi_clock_info *cinfo)
  1020. {
  1021. int r = 0;
  1022. u32 l;
  1023. int f;
  1024. u8 regn_start, regn_end, regm_start, regm_end;
  1025. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1026. DSSDBGF();
  1027. dsi.current_cinfo.use_sys_clk = cinfo->use_sys_clk;
  1028. dsi.current_cinfo.highfreq = cinfo->highfreq;
  1029. dsi.current_cinfo.fint = cinfo->fint;
  1030. dsi.current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1031. dsi.current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1032. cinfo->dsi_pll_hsdiv_dispc_clk;
  1033. dsi.current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1034. cinfo->dsi_pll_hsdiv_dsi_clk;
  1035. dsi.current_cinfo.regn = cinfo->regn;
  1036. dsi.current_cinfo.regm = cinfo->regm;
  1037. dsi.current_cinfo.regm_dispc = cinfo->regm_dispc;
  1038. dsi.current_cinfo.regm_dsi = cinfo->regm_dsi;
  1039. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1040. DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
  1041. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
  1042. cinfo->clkin,
  1043. cinfo->highfreq);
  1044. /* DSIPHY == CLKIN4DDR */
  1045. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
  1046. cinfo->regm,
  1047. cinfo->regn,
  1048. cinfo->clkin,
  1049. cinfo->highfreq + 1,
  1050. cinfo->clkin4ddr);
  1051. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1052. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1053. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1054. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1055. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1056. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1057. cinfo->dsi_pll_hsdiv_dispc_clk);
  1058. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1059. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1060. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1061. cinfo->dsi_pll_hsdiv_dsi_clk);
  1062. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1063. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1064. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1065. &regm_dispc_end);
  1066. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1067. &regm_dsi_end);
  1068. REG_FLD_MOD(DSI_PLL_CONTROL, 0, 0, 0); /* DSI_PLL_AUTOMODE = manual */
  1069. l = dsi_read_reg(DSI_PLL_CONFIGURATION1);
  1070. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1071. /* DSI_PLL_REGN */
  1072. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1073. /* DSI_PLL_REGM */
  1074. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1075. /* DSI_CLOCK_DIV */
  1076. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1077. regm_dispc_start, regm_dispc_end);
  1078. /* DSIPROTO_CLOCK_DIV */
  1079. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1080. regm_dsi_start, regm_dsi_end);
  1081. dsi_write_reg(DSI_PLL_CONFIGURATION1, l);
  1082. BUG_ON(cinfo->fint < dsi.fint_min || cinfo->fint > dsi.fint_max);
  1083. if (cinfo->fint < 1000000)
  1084. f = 0x3;
  1085. else if (cinfo->fint < 1250000)
  1086. f = 0x4;
  1087. else if (cinfo->fint < 1500000)
  1088. f = 0x5;
  1089. else if (cinfo->fint < 1750000)
  1090. f = 0x6;
  1091. else
  1092. f = 0x7;
  1093. l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
  1094. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1095. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1096. 11, 11); /* DSI_PLL_CLKSEL */
  1097. l = FLD_MOD(l, cinfo->highfreq,
  1098. 12, 12); /* DSI_PLL_HIGHFREQ */
  1099. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1100. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1101. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1102. dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
  1103. REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1104. if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
  1105. DSSERR("dsi pll go bit not going down.\n");
  1106. r = -EIO;
  1107. goto err;
  1108. }
  1109. if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
  1110. DSSERR("cannot lock PLL\n");
  1111. r = -EIO;
  1112. goto err;
  1113. }
  1114. dsi.pll_locked = 1;
  1115. l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
  1116. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1117. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1118. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1119. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1120. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1121. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1122. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1123. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1124. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1125. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1126. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1127. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1128. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1129. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1130. dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
  1131. DSSDBG("PLL config done\n");
  1132. err:
  1133. return r;
  1134. }
  1135. int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
  1136. bool enable_hsdiv)
  1137. {
  1138. int r = 0;
  1139. enum dsi_pll_power_state pwstate;
  1140. DSSDBG("PLL init\n");
  1141. #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
  1142. /*
  1143. * HACK: this is just a quick hack to get the USE_DSI_PLL
  1144. * option working. USE_DSI_PLL is itself a big hack, and
  1145. * should be removed.
  1146. */
  1147. if (dsi.vdds_dsi_reg == NULL) {
  1148. struct regulator *vdds_dsi;
  1149. vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
  1150. if (IS_ERR(vdds_dsi)) {
  1151. DSSERR("can't get VDDS_DSI regulator\n");
  1152. return PTR_ERR(vdds_dsi);
  1153. }
  1154. dsi.vdds_dsi_reg = vdds_dsi;
  1155. }
  1156. #endif
  1157. enable_clocks(1);
  1158. dsi_enable_pll_clock(1);
  1159. r = regulator_enable(dsi.vdds_dsi_reg);
  1160. if (r)
  1161. goto err0;
  1162. /* XXX PLL does not come out of reset without this... */
  1163. dispc_pck_free_enable(1);
  1164. if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
  1165. DSSERR("PLL not coming out of reset.\n");
  1166. r = -ENODEV;
  1167. dispc_pck_free_enable(0);
  1168. goto err1;
  1169. }
  1170. /* XXX ... but if left on, we get problems when planes do not
  1171. * fill the whole display. No idea about this */
  1172. dispc_pck_free_enable(0);
  1173. if (enable_hsclk && enable_hsdiv)
  1174. pwstate = DSI_PLL_POWER_ON_ALL;
  1175. else if (enable_hsclk)
  1176. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1177. else if (enable_hsdiv)
  1178. pwstate = DSI_PLL_POWER_ON_DIV;
  1179. else
  1180. pwstate = DSI_PLL_POWER_OFF;
  1181. r = dsi_pll_power(pwstate);
  1182. if (r)
  1183. goto err1;
  1184. DSSDBG("PLL init done\n");
  1185. return 0;
  1186. err1:
  1187. regulator_disable(dsi.vdds_dsi_reg);
  1188. err0:
  1189. enable_clocks(0);
  1190. dsi_enable_pll_clock(0);
  1191. return r;
  1192. }
  1193. void dsi_pll_uninit(void)
  1194. {
  1195. enable_clocks(0);
  1196. dsi_enable_pll_clock(0);
  1197. dsi.pll_locked = 0;
  1198. dsi_pll_power(DSI_PLL_POWER_OFF);
  1199. regulator_disable(dsi.vdds_dsi_reg);
  1200. DSSDBG("PLL uninit done\n");
  1201. }
  1202. void dsi_dump_clocks(struct seq_file *s)
  1203. {
  1204. struct dsi_clock_info *cinfo = &dsi.current_cinfo;
  1205. enum dss_clk_source dispc_clk_src, dsi_clk_src;
  1206. dispc_clk_src = dss_get_dispc_clk_source();
  1207. dsi_clk_src = dss_get_dsi_clk_source();
  1208. enable_clocks(1);
  1209. seq_printf(s, "- DSI PLL -\n");
  1210. seq_printf(s, "dsi pll source = %s\n",
  1211. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
  1212. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1213. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1214. cinfo->clkin4ddr, cinfo->regm);
  1215. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1216. dss_get_generic_clk_source_name(dispc_clk_src),
  1217. dss_feat_get_clk_source_name(dispc_clk_src),
  1218. cinfo->dsi_pll_hsdiv_dispc_clk,
  1219. cinfo->regm_dispc,
  1220. dispc_clk_src == DSS_CLK_SRC_FCK ?
  1221. "off" : "on");
  1222. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1223. dss_get_generic_clk_source_name(dsi_clk_src),
  1224. dss_feat_get_clk_source_name(dsi_clk_src),
  1225. cinfo->dsi_pll_hsdiv_dsi_clk,
  1226. cinfo->regm_dsi,
  1227. dsi_clk_src == DSS_CLK_SRC_FCK ?
  1228. "off" : "on");
  1229. seq_printf(s, "- DSI -\n");
  1230. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1231. dss_get_generic_clk_source_name(dsi_clk_src),
  1232. dss_feat_get_clk_source_name(dsi_clk_src));
  1233. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
  1234. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1235. cinfo->clkin4ddr / 4);
  1236. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
  1237. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1238. seq_printf(s, "VP_CLK\t\t%lu\n"
  1239. "VP_PCLK\t\t%lu\n",
  1240. dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
  1241. dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
  1242. enable_clocks(0);
  1243. }
  1244. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1245. void dsi_dump_irqs(struct seq_file *s)
  1246. {
  1247. unsigned long flags;
  1248. struct dsi_irq_stats stats;
  1249. spin_lock_irqsave(&dsi.irq_stats_lock, flags);
  1250. stats = dsi.irq_stats;
  1251. memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
  1252. dsi.irq_stats.last_reset = jiffies;
  1253. spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
  1254. seq_printf(s, "period %u ms\n",
  1255. jiffies_to_msecs(jiffies - stats.last_reset));
  1256. seq_printf(s, "irqs %d\n", stats.irq_count);
  1257. #define PIS(x) \
  1258. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1259. seq_printf(s, "-- DSI interrupts --\n");
  1260. PIS(VC0);
  1261. PIS(VC1);
  1262. PIS(VC2);
  1263. PIS(VC3);
  1264. PIS(WAKEUP);
  1265. PIS(RESYNC);
  1266. PIS(PLL_LOCK);
  1267. PIS(PLL_UNLOCK);
  1268. PIS(PLL_RECALL);
  1269. PIS(COMPLEXIO_ERR);
  1270. PIS(HS_TX_TIMEOUT);
  1271. PIS(LP_RX_TIMEOUT);
  1272. PIS(TE_TRIGGER);
  1273. PIS(ACK_TRIGGER);
  1274. PIS(SYNC_LOST);
  1275. PIS(LDO_POWER_GOOD);
  1276. PIS(TA_TIMEOUT);
  1277. #undef PIS
  1278. #define PIS(x) \
  1279. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1280. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1281. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1282. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1283. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1284. seq_printf(s, "-- VC interrupts --\n");
  1285. PIS(CS);
  1286. PIS(ECC_CORR);
  1287. PIS(PACKET_SENT);
  1288. PIS(FIFO_TX_OVF);
  1289. PIS(FIFO_RX_OVF);
  1290. PIS(BTA);
  1291. PIS(ECC_NO_CORR);
  1292. PIS(FIFO_TX_UDF);
  1293. PIS(PP_BUSY_CHANGE);
  1294. #undef PIS
  1295. #define PIS(x) \
  1296. seq_printf(s, "%-20s %10d\n", #x, \
  1297. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1298. seq_printf(s, "-- CIO interrupts --\n");
  1299. PIS(ERRSYNCESC1);
  1300. PIS(ERRSYNCESC2);
  1301. PIS(ERRSYNCESC3);
  1302. PIS(ERRESC1);
  1303. PIS(ERRESC2);
  1304. PIS(ERRESC3);
  1305. PIS(ERRCONTROL1);
  1306. PIS(ERRCONTROL2);
  1307. PIS(ERRCONTROL3);
  1308. PIS(STATEULPS1);
  1309. PIS(STATEULPS2);
  1310. PIS(STATEULPS3);
  1311. PIS(ERRCONTENTIONLP0_1);
  1312. PIS(ERRCONTENTIONLP1_1);
  1313. PIS(ERRCONTENTIONLP0_2);
  1314. PIS(ERRCONTENTIONLP1_2);
  1315. PIS(ERRCONTENTIONLP0_3);
  1316. PIS(ERRCONTENTIONLP1_3);
  1317. PIS(ULPSACTIVENOT_ALL0);
  1318. PIS(ULPSACTIVENOT_ALL1);
  1319. #undef PIS
  1320. }
  1321. #endif
  1322. void dsi_dump_regs(struct seq_file *s)
  1323. {
  1324. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
  1325. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  1326. DUMPREG(DSI_REVISION);
  1327. DUMPREG(DSI_SYSCONFIG);
  1328. DUMPREG(DSI_SYSSTATUS);
  1329. DUMPREG(DSI_IRQSTATUS);
  1330. DUMPREG(DSI_IRQENABLE);
  1331. DUMPREG(DSI_CTRL);
  1332. DUMPREG(DSI_COMPLEXIO_CFG1);
  1333. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1334. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1335. DUMPREG(DSI_CLK_CTRL);
  1336. DUMPREG(DSI_TIMING1);
  1337. DUMPREG(DSI_TIMING2);
  1338. DUMPREG(DSI_VM_TIMING1);
  1339. DUMPREG(DSI_VM_TIMING2);
  1340. DUMPREG(DSI_VM_TIMING3);
  1341. DUMPREG(DSI_CLK_TIMING);
  1342. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1343. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1344. DUMPREG(DSI_COMPLEXIO_CFG2);
  1345. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1346. DUMPREG(DSI_VM_TIMING4);
  1347. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1348. DUMPREG(DSI_VM_TIMING5);
  1349. DUMPREG(DSI_VM_TIMING6);
  1350. DUMPREG(DSI_VM_TIMING7);
  1351. DUMPREG(DSI_STOPCLK_TIMING);
  1352. DUMPREG(DSI_VC_CTRL(0));
  1353. DUMPREG(DSI_VC_TE(0));
  1354. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1355. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1356. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1357. DUMPREG(DSI_VC_IRQSTATUS(0));
  1358. DUMPREG(DSI_VC_IRQENABLE(0));
  1359. DUMPREG(DSI_VC_CTRL(1));
  1360. DUMPREG(DSI_VC_TE(1));
  1361. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1362. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1363. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1364. DUMPREG(DSI_VC_IRQSTATUS(1));
  1365. DUMPREG(DSI_VC_IRQENABLE(1));
  1366. DUMPREG(DSI_VC_CTRL(2));
  1367. DUMPREG(DSI_VC_TE(2));
  1368. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1369. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1370. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1371. DUMPREG(DSI_VC_IRQSTATUS(2));
  1372. DUMPREG(DSI_VC_IRQENABLE(2));
  1373. DUMPREG(DSI_VC_CTRL(3));
  1374. DUMPREG(DSI_VC_TE(3));
  1375. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1376. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1377. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1378. DUMPREG(DSI_VC_IRQSTATUS(3));
  1379. DUMPREG(DSI_VC_IRQENABLE(3));
  1380. DUMPREG(DSI_DSIPHY_CFG0);
  1381. DUMPREG(DSI_DSIPHY_CFG1);
  1382. DUMPREG(DSI_DSIPHY_CFG2);
  1383. DUMPREG(DSI_DSIPHY_CFG5);
  1384. DUMPREG(DSI_PLL_CONTROL);
  1385. DUMPREG(DSI_PLL_STATUS);
  1386. DUMPREG(DSI_PLL_GO);
  1387. DUMPREG(DSI_PLL_CONFIGURATION1);
  1388. DUMPREG(DSI_PLL_CONFIGURATION2);
  1389. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  1390. #undef DUMPREG
  1391. }
  1392. enum dsi_complexio_power_state {
  1393. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1394. DSI_COMPLEXIO_POWER_ON = 0x1,
  1395. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1396. };
  1397. static int dsi_complexio_power(enum dsi_complexio_power_state state)
  1398. {
  1399. int t = 0;
  1400. /* PWR_CMD */
  1401. REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
  1402. /* PWR_STATUS */
  1403. while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
  1404. if (++t > 1000) {
  1405. DSSERR("failed to set complexio power state to "
  1406. "%d\n", state);
  1407. return -ENODEV;
  1408. }
  1409. udelay(1);
  1410. }
  1411. return 0;
  1412. }
  1413. static void dsi_complexio_config(struct omap_dss_device *dssdev)
  1414. {
  1415. u32 r;
  1416. int clk_lane = dssdev->phy.dsi.clk_lane;
  1417. int data1_lane = dssdev->phy.dsi.data1_lane;
  1418. int data2_lane = dssdev->phy.dsi.data2_lane;
  1419. int clk_pol = dssdev->phy.dsi.clk_pol;
  1420. int data1_pol = dssdev->phy.dsi.data1_pol;
  1421. int data2_pol = dssdev->phy.dsi.data2_pol;
  1422. r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
  1423. r = FLD_MOD(r, clk_lane, 2, 0);
  1424. r = FLD_MOD(r, clk_pol, 3, 3);
  1425. r = FLD_MOD(r, data1_lane, 6, 4);
  1426. r = FLD_MOD(r, data1_pol, 7, 7);
  1427. r = FLD_MOD(r, data2_lane, 10, 8);
  1428. r = FLD_MOD(r, data2_pol, 11, 11);
  1429. dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
  1430. /* The configuration of the DSI complex I/O (number of data lanes,
  1431. position, differential order) should not be changed while
  1432. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1433. the hardware to take into account a new configuration of the complex
  1434. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1435. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1436. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1437. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1438. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1439. DSI complex I/O configuration is unknown. */
  1440. /*
  1441. REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
  1442. REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
  1443. REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
  1444. REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
  1445. */
  1446. }
  1447. static inline unsigned ns2ddr(unsigned ns)
  1448. {
  1449. /* convert time in ns to ddr ticks, rounding up */
  1450. unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
  1451. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1452. }
  1453. static inline unsigned ddr2ns(unsigned ddr)
  1454. {
  1455. unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
  1456. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1457. }
  1458. static void dsi_complexio_timings(void)
  1459. {
  1460. u32 r;
  1461. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1462. u32 tlpx_half, tclk_trail, tclk_zero;
  1463. u32 tclk_prepare;
  1464. /* calculate timings */
  1465. /* 1 * DDR_CLK = 2 * UI */
  1466. /* min 40ns + 4*UI max 85ns + 6*UI */
  1467. ths_prepare = ns2ddr(70) + 2;
  1468. /* min 145ns + 10*UI */
  1469. ths_prepare_ths_zero = ns2ddr(175) + 2;
  1470. /* min max(8*UI, 60ns+4*UI) */
  1471. ths_trail = ns2ddr(60) + 5;
  1472. /* min 100ns */
  1473. ths_exit = ns2ddr(145);
  1474. /* tlpx min 50n */
  1475. tlpx_half = ns2ddr(25);
  1476. /* min 60ns */
  1477. tclk_trail = ns2ddr(60) + 2;
  1478. /* min 38ns, max 95ns */
  1479. tclk_prepare = ns2ddr(65);
  1480. /* min tclk-prepare + tclk-zero = 300ns */
  1481. tclk_zero = ns2ddr(260);
  1482. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1483. ths_prepare, ddr2ns(ths_prepare),
  1484. ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
  1485. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1486. ths_trail, ddr2ns(ths_trail),
  1487. ths_exit, ddr2ns(ths_exit));
  1488. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1489. "tclk_zero %u (%uns)\n",
  1490. tlpx_half, ddr2ns(tlpx_half),
  1491. tclk_trail, ddr2ns(tclk_trail),
  1492. tclk_zero, ddr2ns(tclk_zero));
  1493. DSSDBG("tclk_prepare %u (%uns)\n",
  1494. tclk_prepare, ddr2ns(tclk_prepare));
  1495. /* program timings */
  1496. r = dsi_read_reg(DSI_DSIPHY_CFG0);
  1497. r = FLD_MOD(r, ths_prepare, 31, 24);
  1498. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1499. r = FLD_MOD(r, ths_trail, 15, 8);
  1500. r = FLD_MOD(r, ths_exit, 7, 0);
  1501. dsi_write_reg(DSI_DSIPHY_CFG0, r);
  1502. r = dsi_read_reg(DSI_DSIPHY_CFG1);
  1503. r = FLD_MOD(r, tlpx_half, 22, 16);
  1504. r = FLD_MOD(r, tclk_trail, 15, 8);
  1505. r = FLD_MOD(r, tclk_zero, 7, 0);
  1506. dsi_write_reg(DSI_DSIPHY_CFG1, r);
  1507. r = dsi_read_reg(DSI_DSIPHY_CFG2);
  1508. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1509. dsi_write_reg(DSI_DSIPHY_CFG2, r);
  1510. }
  1511. static int dsi_complexio_init(struct omap_dss_device *dssdev)
  1512. {
  1513. int r = 0;
  1514. DSSDBG("dsi_complexio_init\n");
  1515. /* CIO_CLK_ICG, enable L3 clk to CIO */
  1516. REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
  1517. /* A dummy read using the SCP interface to any DSIPHY register is
  1518. * required after DSIPHY reset to complete the reset of the DSI complex
  1519. * I/O. */
  1520. dsi_read_reg(DSI_DSIPHY_CFG5);
  1521. if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1522. DSSERR("ComplexIO PHY not coming out of reset.\n");
  1523. r = -ENODEV;
  1524. goto err;
  1525. }
  1526. dsi_complexio_config(dssdev);
  1527. r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
  1528. if (r)
  1529. goto err;
  1530. if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1531. DSSERR("ComplexIO not coming out of reset.\n");
  1532. r = -ENODEV;
  1533. goto err;
  1534. }
  1535. if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
  1536. DSSERR("ComplexIO LDO power down.\n");
  1537. r = -ENODEV;
  1538. goto err;
  1539. }
  1540. dsi_complexio_timings();
  1541. /*
  1542. The configuration of the DSI complex I/O (number of data lanes,
  1543. position, differential order) should not be changed while
  1544. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
  1545. hardware to recognize a new configuration of the complex I/O (done
  1546. in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
  1547. this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
  1548. reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
  1549. LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
  1550. bit to 1. If the sequence is not followed, the DSi complex I/O
  1551. configuration is undetermined.
  1552. */
  1553. dsi_if_enable(1);
  1554. dsi_if_enable(0);
  1555. REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1556. dsi_if_enable(1);
  1557. dsi_if_enable(0);
  1558. DSSDBG("CIO init done\n");
  1559. err:
  1560. return r;
  1561. }
  1562. static void dsi_complexio_uninit(void)
  1563. {
  1564. dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
  1565. }
  1566. static int _dsi_wait_reset(void)
  1567. {
  1568. int t = 0;
  1569. while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
  1570. if (++t > 5) {
  1571. DSSERR("soft reset failed\n");
  1572. return -ENODEV;
  1573. }
  1574. udelay(1);
  1575. }
  1576. return 0;
  1577. }
  1578. static int _dsi_reset(void)
  1579. {
  1580. /* Soft reset */
  1581. REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
  1582. return _dsi_wait_reset();
  1583. }
  1584. static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
  1585. enum fifo_size size3, enum fifo_size size4)
  1586. {
  1587. u32 r = 0;
  1588. int add = 0;
  1589. int i;
  1590. dsi.vc[0].fifo_size = size1;
  1591. dsi.vc[1].fifo_size = size2;
  1592. dsi.vc[2].fifo_size = size3;
  1593. dsi.vc[3].fifo_size = size4;
  1594. for (i = 0; i < 4; i++) {
  1595. u8 v;
  1596. int size = dsi.vc[i].fifo_size;
  1597. if (add + size > 4) {
  1598. DSSERR("Illegal FIFO configuration\n");
  1599. BUG();
  1600. }
  1601. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1602. r |= v << (8 * i);
  1603. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1604. add += size;
  1605. }
  1606. dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
  1607. }
  1608. static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
  1609. enum fifo_size size3, enum fifo_size size4)
  1610. {
  1611. u32 r = 0;
  1612. int add = 0;
  1613. int i;
  1614. dsi.vc[0].fifo_size = size1;
  1615. dsi.vc[1].fifo_size = size2;
  1616. dsi.vc[2].fifo_size = size3;
  1617. dsi.vc[3].fifo_size = size4;
  1618. for (i = 0; i < 4; i++) {
  1619. u8 v;
  1620. int size = dsi.vc[i].fifo_size;
  1621. if (add + size > 4) {
  1622. DSSERR("Illegal FIFO configuration\n");
  1623. BUG();
  1624. }
  1625. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1626. r |= v << (8 * i);
  1627. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1628. add += size;
  1629. }
  1630. dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
  1631. }
  1632. static int dsi_force_tx_stop_mode_io(void)
  1633. {
  1634. u32 r;
  1635. r = dsi_read_reg(DSI_TIMING1);
  1636. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1637. dsi_write_reg(DSI_TIMING1, r);
  1638. if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
  1639. DSSERR("TX_STOP bit not going down\n");
  1640. return -EIO;
  1641. }
  1642. return 0;
  1643. }
  1644. static int dsi_vc_enable(int channel, bool enable)
  1645. {
  1646. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  1647. channel, enable);
  1648. enable = enable ? 1 : 0;
  1649. REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
  1650. if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
  1651. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  1652. return -EIO;
  1653. }
  1654. return 0;
  1655. }
  1656. static void dsi_vc_initial_config(int channel)
  1657. {
  1658. u32 r;
  1659. DSSDBGF("%d", channel);
  1660. r = dsi_read_reg(DSI_VC_CTRL(channel));
  1661. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  1662. DSSERR("VC(%d) busy when trying to configure it!\n",
  1663. channel);
  1664. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  1665. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  1666. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  1667. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  1668. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  1669. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  1670. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  1671. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  1672. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  1673. dsi_write_reg(DSI_VC_CTRL(channel), r);
  1674. }
  1675. static int dsi_vc_config_l4(int channel)
  1676. {
  1677. if (dsi.vc[channel].mode == DSI_VC_MODE_L4)
  1678. return 0;
  1679. DSSDBGF("%d", channel);
  1680. dsi_vc_enable(channel, 0);
  1681. /* VC_BUSY */
  1682. if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
  1683. DSSERR("vc(%d) busy when trying to config for L4\n", channel);
  1684. return -EIO;
  1685. }
  1686. REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
  1687. dsi_vc_enable(channel, 1);
  1688. dsi.vc[channel].mode = DSI_VC_MODE_L4;
  1689. return 0;
  1690. }
  1691. static int dsi_vc_config_vp(int channel)
  1692. {
  1693. if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
  1694. return 0;
  1695. DSSDBGF("%d", channel);
  1696. dsi_vc_enable(channel, 0);
  1697. /* VC_BUSY */
  1698. if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
  1699. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  1700. return -EIO;
  1701. }
  1702. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
  1703. dsi_vc_enable(channel, 1);
  1704. dsi.vc[channel].mode = DSI_VC_MODE_VP;
  1705. return 0;
  1706. }
  1707. void omapdss_dsi_vc_enable_hs(int channel, bool enable)
  1708. {
  1709. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  1710. WARN_ON(!dsi_bus_is_locked());
  1711. dsi_vc_enable(channel, 0);
  1712. dsi_if_enable(0);
  1713. REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
  1714. dsi_vc_enable(channel, 1);
  1715. dsi_if_enable(1);
  1716. dsi_force_tx_stop_mode_io();
  1717. }
  1718. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  1719. static void dsi_vc_flush_long_data(int channel)
  1720. {
  1721. while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  1722. u32 val;
  1723. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  1724. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  1725. (val >> 0) & 0xff,
  1726. (val >> 8) & 0xff,
  1727. (val >> 16) & 0xff,
  1728. (val >> 24) & 0xff);
  1729. }
  1730. }
  1731. static void dsi_show_rx_ack_with_err(u16 err)
  1732. {
  1733. DSSERR("\tACK with ERROR (%#x):\n", err);
  1734. if (err & (1 << 0))
  1735. DSSERR("\t\tSoT Error\n");
  1736. if (err & (1 << 1))
  1737. DSSERR("\t\tSoT Sync Error\n");
  1738. if (err & (1 << 2))
  1739. DSSERR("\t\tEoT Sync Error\n");
  1740. if (err & (1 << 3))
  1741. DSSERR("\t\tEscape Mode Entry Command Error\n");
  1742. if (err & (1 << 4))
  1743. DSSERR("\t\tLP Transmit Sync Error\n");
  1744. if (err & (1 << 5))
  1745. DSSERR("\t\tHS Receive Timeout Error\n");
  1746. if (err & (1 << 6))
  1747. DSSERR("\t\tFalse Control Error\n");
  1748. if (err & (1 << 7))
  1749. DSSERR("\t\t(reserved7)\n");
  1750. if (err & (1 << 8))
  1751. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  1752. if (err & (1 << 9))
  1753. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  1754. if (err & (1 << 10))
  1755. DSSERR("\t\tChecksum Error\n");
  1756. if (err & (1 << 11))
  1757. DSSERR("\t\tData type not recognized\n");
  1758. if (err & (1 << 12))
  1759. DSSERR("\t\tInvalid VC ID\n");
  1760. if (err & (1 << 13))
  1761. DSSERR("\t\tInvalid Transmission Length\n");
  1762. if (err & (1 << 14))
  1763. DSSERR("\t\t(reserved14)\n");
  1764. if (err & (1 << 15))
  1765. DSSERR("\t\tDSI Protocol Violation\n");
  1766. }
  1767. static u16 dsi_vc_flush_receive_data(int channel)
  1768. {
  1769. /* RX_FIFO_NOT_EMPTY */
  1770. while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  1771. u32 val;
  1772. u8 dt;
  1773. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  1774. DSSERR("\trawval %#08x\n", val);
  1775. dt = FLD_GET(val, 5, 0);
  1776. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  1777. u16 err = FLD_GET(val, 23, 8);
  1778. dsi_show_rx_ack_with_err(err);
  1779. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  1780. DSSERR("\tDCS short response, 1 byte: %#x\n",
  1781. FLD_GET(val, 23, 8));
  1782. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  1783. DSSERR("\tDCS short response, 2 byte: %#x\n",
  1784. FLD_GET(val, 23, 8));
  1785. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  1786. DSSERR("\tDCS long response, len %d\n",
  1787. FLD_GET(val, 23, 8));
  1788. dsi_vc_flush_long_data(channel);
  1789. } else {
  1790. DSSERR("\tunknown datatype 0x%02x\n", dt);
  1791. }
  1792. }
  1793. return 0;
  1794. }
  1795. static int dsi_vc_send_bta(int channel)
  1796. {
  1797. if (dsi.debug_write || dsi.debug_read)
  1798. DSSDBG("dsi_vc_send_bta %d\n", channel);
  1799. WARN_ON(!dsi_bus_is_locked());
  1800. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
  1801. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  1802. dsi_vc_flush_receive_data(channel);
  1803. }
  1804. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  1805. return 0;
  1806. }
  1807. int dsi_vc_send_bta_sync(int channel)
  1808. {
  1809. DECLARE_COMPLETION_ONSTACK(completion);
  1810. int r = 0;
  1811. u32 err;
  1812. r = dsi_register_isr_vc(channel, dsi_completion_handler,
  1813. &completion, DSI_VC_IRQ_BTA);
  1814. if (r)
  1815. goto err0;
  1816. r = dsi_register_isr(dsi_completion_handler, &completion,
  1817. DSI_IRQ_ERROR_MASK);
  1818. if (r)
  1819. goto err1;
  1820. r = dsi_vc_send_bta(channel);
  1821. if (r)
  1822. goto err2;
  1823. if (wait_for_completion_timeout(&completion,
  1824. msecs_to_jiffies(500)) == 0) {
  1825. DSSERR("Failed to receive BTA\n");
  1826. r = -EIO;
  1827. goto err2;
  1828. }
  1829. err = dsi_get_errors();
  1830. if (err) {
  1831. DSSERR("Error while sending BTA: %x\n", err);
  1832. r = -EIO;
  1833. goto err2;
  1834. }
  1835. err2:
  1836. dsi_unregister_isr(dsi_completion_handler, &completion,
  1837. DSI_IRQ_ERROR_MASK);
  1838. err1:
  1839. dsi_unregister_isr_vc(channel, dsi_completion_handler,
  1840. &completion, DSI_VC_IRQ_BTA);
  1841. err0:
  1842. return r;
  1843. }
  1844. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  1845. static inline void dsi_vc_write_long_header(int channel, u8 data_type,
  1846. u16 len, u8 ecc)
  1847. {
  1848. u32 val;
  1849. u8 data_id;
  1850. WARN_ON(!dsi_bus_is_locked());
  1851. data_id = data_type | dsi.vc[channel].vc_id << 6;
  1852. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  1853. FLD_VAL(ecc, 31, 24);
  1854. dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
  1855. }
  1856. static inline void dsi_vc_write_long_payload(int channel,
  1857. u8 b1, u8 b2, u8 b3, u8 b4)
  1858. {
  1859. u32 val;
  1860. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  1861. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  1862. b1, b2, b3, b4, val); */
  1863. dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  1864. }
  1865. static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
  1866. u8 ecc)
  1867. {
  1868. /*u32 val; */
  1869. int i;
  1870. u8 *p;
  1871. int r = 0;
  1872. u8 b1, b2, b3, b4;
  1873. if (dsi.debug_write)
  1874. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  1875. /* len + header */
  1876. if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
  1877. DSSERR("unable to send long packet: packet too long.\n");
  1878. return -EINVAL;
  1879. }
  1880. dsi_vc_config_l4(channel);
  1881. dsi_vc_write_long_header(channel, data_type, len, ecc);
  1882. p = data;
  1883. for (i = 0; i < len >> 2; i++) {
  1884. if (dsi.debug_write)
  1885. DSSDBG("\tsending full packet %d\n", i);
  1886. b1 = *p++;
  1887. b2 = *p++;
  1888. b3 = *p++;
  1889. b4 = *p++;
  1890. dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
  1891. }
  1892. i = len % 4;
  1893. if (i) {
  1894. b1 = 0; b2 = 0; b3 = 0;
  1895. if (dsi.debug_write)
  1896. DSSDBG("\tsending remainder bytes %d\n", i);
  1897. switch (i) {
  1898. case 3:
  1899. b1 = *p++;
  1900. b2 = *p++;
  1901. b3 = *p++;
  1902. break;
  1903. case 2:
  1904. b1 = *p++;
  1905. b2 = *p++;
  1906. break;
  1907. case 1:
  1908. b1 = *p++;
  1909. break;
  1910. }
  1911. dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
  1912. }
  1913. return r;
  1914. }
  1915. static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
  1916. {
  1917. u32 r;
  1918. u8 data_id;
  1919. WARN_ON(!dsi_bus_is_locked());
  1920. if (dsi.debug_write)
  1921. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  1922. channel,
  1923. data_type, data & 0xff, (data >> 8) & 0xff);
  1924. dsi_vc_config_l4(channel);
  1925. if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
  1926. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  1927. return -EINVAL;
  1928. }
  1929. data_id = data_type | dsi.vc[channel].vc_id << 6;
  1930. r = (data_id << 0) | (data << 8) | (ecc << 24);
  1931. dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
  1932. return 0;
  1933. }
  1934. int dsi_vc_send_null(int channel)
  1935. {
  1936. u8 nullpkg[] = {0, 0, 0, 0};
  1937. return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
  1938. }
  1939. EXPORT_SYMBOL(dsi_vc_send_null);
  1940. int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
  1941. {
  1942. int r;
  1943. BUG_ON(len == 0);
  1944. if (len == 1) {
  1945. r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
  1946. data[0], 0);
  1947. } else if (len == 2) {
  1948. r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
  1949. data[0] | (data[1] << 8), 0);
  1950. } else {
  1951. /* 0x39 = DCS Long Write */
  1952. r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
  1953. data, len, 0);
  1954. }
  1955. return r;
  1956. }
  1957. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  1958. int dsi_vc_dcs_write(int channel, u8 *data, int len)
  1959. {
  1960. int r;
  1961. r = dsi_vc_dcs_write_nosync(channel, data, len);
  1962. if (r)
  1963. goto err;
  1964. r = dsi_vc_send_bta_sync(channel);
  1965. if (r)
  1966. goto err;
  1967. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
  1968. DSSERR("rx fifo not empty after write, dumping data:\n");
  1969. dsi_vc_flush_receive_data(channel);
  1970. r = -EIO;
  1971. goto err;
  1972. }
  1973. return 0;
  1974. err:
  1975. DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
  1976. channel, data[0], len);
  1977. return r;
  1978. }
  1979. EXPORT_SYMBOL(dsi_vc_dcs_write);
  1980. int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
  1981. {
  1982. return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
  1983. }
  1984. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  1985. int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
  1986. {
  1987. u8 buf[2];
  1988. buf[0] = dcs_cmd;
  1989. buf[1] = param;
  1990. return dsi_vc_dcs_write(channel, buf, 2);
  1991. }
  1992. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  1993. int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
  1994. {
  1995. u32 val;
  1996. u8 dt;
  1997. int r;
  1998. if (dsi.debug_read)
  1999. DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
  2000. r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
  2001. if (r)
  2002. goto err;
  2003. r = dsi_vc_send_bta_sync(channel);
  2004. if (r)
  2005. goto err;
  2006. /* RX_FIFO_NOT_EMPTY */
  2007. if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
  2008. DSSERR("RX fifo empty when trying to read.\n");
  2009. r = -EIO;
  2010. goto err;
  2011. }
  2012. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  2013. if (dsi.debug_read)
  2014. DSSDBG("\theader: %08x\n", val);
  2015. dt = FLD_GET(val, 5, 0);
  2016. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2017. u16 err = FLD_GET(val, 23, 8);
  2018. dsi_show_rx_ack_with_err(err);
  2019. r = -EIO;
  2020. goto err;
  2021. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2022. u8 data = FLD_GET(val, 15, 8);
  2023. if (dsi.debug_read)
  2024. DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
  2025. if (buflen < 1) {
  2026. r = -EIO;
  2027. goto err;
  2028. }
  2029. buf[0] = data;
  2030. return 1;
  2031. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2032. u16 data = FLD_GET(val, 23, 8);
  2033. if (dsi.debug_read)
  2034. DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
  2035. if (buflen < 2) {
  2036. r = -EIO;
  2037. goto err;
  2038. }
  2039. buf[0] = data & 0xff;
  2040. buf[1] = (data >> 8) & 0xff;
  2041. return 2;
  2042. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  2043. int w;
  2044. int len = FLD_GET(val, 23, 8);
  2045. if (dsi.debug_read)
  2046. DSSDBG("\tDCS long response, len %d\n", len);
  2047. if (len > buflen) {
  2048. r = -EIO;
  2049. goto err;
  2050. }
  2051. /* two byte checksum ends the packet, not included in len */
  2052. for (w = 0; w < len + 2;) {
  2053. int b;
  2054. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  2055. if (dsi.debug_read)
  2056. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2057. (val >> 0) & 0xff,
  2058. (val >> 8) & 0xff,
  2059. (val >> 16) & 0xff,
  2060. (val >> 24) & 0xff);
  2061. for (b = 0; b < 4; ++b) {
  2062. if (w < len)
  2063. buf[w] = (val >> (b * 8)) & 0xff;
  2064. /* we discard the 2 byte checksum */
  2065. ++w;
  2066. }
  2067. }
  2068. return len;
  2069. } else {
  2070. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2071. r = -EIO;
  2072. goto err;
  2073. }
  2074. BUG();
  2075. err:
  2076. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
  2077. channel, dcs_cmd);
  2078. return r;
  2079. }
  2080. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2081. int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
  2082. {
  2083. int r;
  2084. r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
  2085. if (r < 0)
  2086. return r;
  2087. if (r != 1)
  2088. return -EIO;
  2089. return 0;
  2090. }
  2091. EXPORT_SYMBOL(dsi_vc_dcs_read_1);
  2092. int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
  2093. {
  2094. u8 buf[2];
  2095. int r;
  2096. r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
  2097. if (r < 0)
  2098. return r;
  2099. if (r != 2)
  2100. return -EIO;
  2101. *data1 = buf[0];
  2102. *data2 = buf[1];
  2103. return 0;
  2104. }
  2105. EXPORT_SYMBOL(dsi_vc_dcs_read_2);
  2106. int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
  2107. {
  2108. return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
  2109. len, 0);
  2110. }
  2111. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2112. static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
  2113. {
  2114. unsigned long fck;
  2115. unsigned long total_ticks;
  2116. u32 r;
  2117. BUG_ON(ticks > 0x1fff);
  2118. /* ticks in DSI_FCK */
  2119. fck = dsi_fclk_rate();
  2120. r = dsi_read_reg(DSI_TIMING2);
  2121. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  2122. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2123. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2124. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2125. dsi_write_reg(DSI_TIMING2, r);
  2126. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2127. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2128. total_ticks,
  2129. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2130. (total_ticks * 1000) / (fck / 1000 / 1000));
  2131. }
  2132. static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
  2133. {
  2134. unsigned long fck;
  2135. unsigned long total_ticks;
  2136. u32 r;
  2137. BUG_ON(ticks > 0x1fff);
  2138. /* ticks in DSI_FCK */
  2139. fck = dsi_fclk_rate();
  2140. r = dsi_read_reg(DSI_TIMING1);
  2141. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  2142. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2143. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2144. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2145. dsi_write_reg(DSI_TIMING1, r);
  2146. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2147. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2148. total_ticks,
  2149. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2150. (total_ticks * 1000) / (fck / 1000 / 1000));
  2151. }
  2152. static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
  2153. {
  2154. unsigned long fck;
  2155. unsigned long total_ticks;
  2156. u32 r;
  2157. BUG_ON(ticks > 0x1fff);
  2158. /* ticks in DSI_FCK */
  2159. fck = dsi_fclk_rate();
  2160. r = dsi_read_reg(DSI_TIMING1);
  2161. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2162. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2163. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2164. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2165. dsi_write_reg(DSI_TIMING1, r);
  2166. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2167. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2168. total_ticks,
  2169. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2170. (total_ticks * 1000) / (fck / 1000 / 1000));
  2171. }
  2172. static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
  2173. {
  2174. unsigned long fck;
  2175. unsigned long total_ticks;
  2176. u32 r;
  2177. BUG_ON(ticks > 0x1fff);
  2178. /* ticks in TxByteClkHS */
  2179. fck = dsi_get_txbyteclkhs();
  2180. r = dsi_read_reg(DSI_TIMING2);
  2181. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  2182. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2183. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2184. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2185. dsi_write_reg(DSI_TIMING2, r);
  2186. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2187. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2188. total_ticks,
  2189. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2190. (total_ticks * 1000) / (fck / 1000 / 1000));
  2191. }
  2192. static int dsi_proto_config(struct omap_dss_device *dssdev)
  2193. {
  2194. u32 r;
  2195. int buswidth = 0;
  2196. dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
  2197. DSI_FIFO_SIZE_32,
  2198. DSI_FIFO_SIZE_32,
  2199. DSI_FIFO_SIZE_32);
  2200. dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
  2201. DSI_FIFO_SIZE_32,
  2202. DSI_FIFO_SIZE_32,
  2203. DSI_FIFO_SIZE_32);
  2204. /* XXX what values for the timeouts? */
  2205. dsi_set_stop_state_counter(0x1000, false, false);
  2206. dsi_set_ta_timeout(0x1fff, true, true);
  2207. dsi_set_lp_rx_timeout(0x1fff, true, true);
  2208. dsi_set_hs_tx_timeout(0x1fff, true, true);
  2209. switch (dssdev->ctrl.pixel_size) {
  2210. case 16:
  2211. buswidth = 0;
  2212. break;
  2213. case 18:
  2214. buswidth = 1;
  2215. break;
  2216. case 24:
  2217. buswidth = 2;
  2218. break;
  2219. default:
  2220. BUG();
  2221. }
  2222. r = dsi_read_reg(DSI_CTRL);
  2223. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2224. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2225. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2226. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2227. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2228. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2229. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
  2230. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2231. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2232. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2233. r = FLD_MOD(r, 0, 25, 25); /* DCS_CMD_CODE, 1=start, 0=continue */
  2234. dsi_write_reg(DSI_CTRL, r);
  2235. dsi_vc_initial_config(0);
  2236. dsi_vc_initial_config(1);
  2237. dsi_vc_initial_config(2);
  2238. dsi_vc_initial_config(3);
  2239. return 0;
  2240. }
  2241. static void dsi_proto_timings(struct omap_dss_device *dssdev)
  2242. {
  2243. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  2244. unsigned tclk_pre, tclk_post;
  2245. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  2246. unsigned ths_trail, ths_exit;
  2247. unsigned ddr_clk_pre, ddr_clk_post;
  2248. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  2249. unsigned ths_eot;
  2250. u32 r;
  2251. r = dsi_read_reg(DSI_DSIPHY_CFG0);
  2252. ths_prepare = FLD_GET(r, 31, 24);
  2253. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  2254. ths_zero = ths_prepare_ths_zero - ths_prepare;
  2255. ths_trail = FLD_GET(r, 15, 8);
  2256. ths_exit = FLD_GET(r, 7, 0);
  2257. r = dsi_read_reg(DSI_DSIPHY_CFG1);
  2258. tlpx = FLD_GET(r, 22, 16) * 2;
  2259. tclk_trail = FLD_GET(r, 15, 8);
  2260. tclk_zero = FLD_GET(r, 7, 0);
  2261. r = dsi_read_reg(DSI_DSIPHY_CFG2);
  2262. tclk_prepare = FLD_GET(r, 7, 0);
  2263. /* min 8*UI */
  2264. tclk_pre = 20;
  2265. /* min 60ns + 52*UI */
  2266. tclk_post = ns2ddr(60) + 26;
  2267. /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
  2268. if (dssdev->phy.dsi.data1_lane != 0 &&
  2269. dssdev->phy.dsi.data2_lane != 0)
  2270. ths_eot = 2;
  2271. else
  2272. ths_eot = 4;
  2273. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  2274. 4);
  2275. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  2276. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  2277. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  2278. r = dsi_read_reg(DSI_CLK_TIMING);
  2279. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  2280. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  2281. dsi_write_reg(DSI_CLK_TIMING, r);
  2282. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  2283. ddr_clk_pre,
  2284. ddr_clk_post);
  2285. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  2286. DIV_ROUND_UP(ths_prepare, 4) +
  2287. DIV_ROUND_UP(ths_zero + 3, 4);
  2288. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  2289. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  2290. FLD_VAL(exit_hs_mode_lat, 15, 0);
  2291. dsi_write_reg(DSI_VM_TIMING7, r);
  2292. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  2293. enter_hs_mode_lat, exit_hs_mode_lat);
  2294. }
  2295. #define DSI_DECL_VARS \
  2296. int __dsi_cb = 0; u32 __dsi_cv = 0;
  2297. #define DSI_FLUSH(ch) \
  2298. if (__dsi_cb > 0) { \
  2299. /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
  2300. dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
  2301. __dsi_cb = __dsi_cv = 0; \
  2302. }
  2303. #define DSI_PUSH(ch, data) \
  2304. do { \
  2305. __dsi_cv |= (data) << (__dsi_cb * 8); \
  2306. /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
  2307. if (++__dsi_cb > 3) \
  2308. DSI_FLUSH(ch); \
  2309. } while (0)
  2310. static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
  2311. int x, int y, int w, int h)
  2312. {
  2313. /* Note: supports only 24bit colors in 32bit container */
  2314. int first = 1;
  2315. int fifo_stalls = 0;
  2316. int max_dsi_packet_size;
  2317. int max_data_per_packet;
  2318. int max_pixels_per_packet;
  2319. int pixels_left;
  2320. int bytespp = dssdev->ctrl.pixel_size / 8;
  2321. int scr_width;
  2322. u32 __iomem *data;
  2323. int start_offset;
  2324. int horiz_inc;
  2325. int current_x;
  2326. struct omap_overlay *ovl;
  2327. debug_irq = 0;
  2328. DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
  2329. x, y, w, h);
  2330. ovl = dssdev->manager->overlays[0];
  2331. if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
  2332. return -EINVAL;
  2333. if (dssdev->ctrl.pixel_size != 24)
  2334. return -EINVAL;
  2335. scr_width = ovl->info.screen_width;
  2336. data = ovl->info.vaddr;
  2337. start_offset = scr_width * y + x;
  2338. horiz_inc = scr_width - w;
  2339. current_x = x;
  2340. /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
  2341. * in fifo */
  2342. /* When using CPU, max long packet size is TX buffer size */
  2343. max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
  2344. /* we seem to get better perf if we divide the tx fifo to half,
  2345. and while the other half is being sent, we fill the other half
  2346. max_dsi_packet_size /= 2; */
  2347. max_data_per_packet = max_dsi_packet_size - 4 - 1;
  2348. max_pixels_per_packet = max_data_per_packet / bytespp;
  2349. DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
  2350. pixels_left = w * h;
  2351. DSSDBG("total pixels %d\n", pixels_left);
  2352. data += start_offset;
  2353. while (pixels_left > 0) {
  2354. /* 0x2c = write_memory_start */
  2355. /* 0x3c = write_memory_continue */
  2356. u8 dcs_cmd = first ? 0x2c : 0x3c;
  2357. int pixels;
  2358. DSI_DECL_VARS;
  2359. first = 0;
  2360. #if 1
  2361. /* using fifo not empty */
  2362. /* TX_FIFO_NOT_EMPTY */
  2363. while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
  2364. fifo_stalls++;
  2365. if (fifo_stalls > 0xfffff) {
  2366. DSSERR("fifo stalls overflow, pixels left %d\n",
  2367. pixels_left);
  2368. dsi_if_enable(0);
  2369. return -EIO;
  2370. }
  2371. udelay(1);
  2372. }
  2373. #elif 1
  2374. /* using fifo emptiness */
  2375. while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
  2376. max_dsi_packet_size) {
  2377. fifo_stalls++;
  2378. if (fifo_stalls > 0xfffff) {
  2379. DSSERR("fifo stalls overflow, pixels left %d\n",
  2380. pixels_left);
  2381. dsi_if_enable(0);
  2382. return -EIO;
  2383. }
  2384. }
  2385. #else
  2386. while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
  2387. fifo_stalls++;
  2388. if (fifo_stalls > 0xfffff) {
  2389. DSSERR("fifo stalls overflow, pixels left %d\n",
  2390. pixels_left);
  2391. dsi_if_enable(0);
  2392. return -EIO;
  2393. }
  2394. }
  2395. #endif
  2396. pixels = min(max_pixels_per_packet, pixels_left);
  2397. pixels_left -= pixels;
  2398. dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
  2399. 1 + pixels * bytespp, 0);
  2400. DSI_PUSH(0, dcs_cmd);
  2401. while (pixels-- > 0) {
  2402. u32 pix = __raw_readl(data++);
  2403. DSI_PUSH(0, (pix >> 16) & 0xff);
  2404. DSI_PUSH(0, (pix >> 8) & 0xff);
  2405. DSI_PUSH(0, (pix >> 0) & 0xff);
  2406. current_x++;
  2407. if (current_x == x+w) {
  2408. current_x = x;
  2409. data += horiz_inc;
  2410. }
  2411. }
  2412. DSI_FLUSH(0);
  2413. }
  2414. return 0;
  2415. }
  2416. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  2417. u16 x, u16 y, u16 w, u16 h)
  2418. {
  2419. unsigned bytespp;
  2420. unsigned bytespl;
  2421. unsigned bytespf;
  2422. unsigned total_len;
  2423. unsigned packet_payload;
  2424. unsigned packet_len;
  2425. u32 l;
  2426. int r;
  2427. const unsigned channel = dsi.update_channel;
  2428. /* line buffer is 1024 x 24bits */
  2429. /* XXX: for some reason using full buffer size causes considerable TX
  2430. * slowdown with update sizes that fill the whole buffer */
  2431. const unsigned line_buf_size = 1023 * 3;
  2432. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  2433. x, y, w, h);
  2434. dsi_vc_config_vp(channel);
  2435. bytespp = dssdev->ctrl.pixel_size / 8;
  2436. bytespl = w * bytespp;
  2437. bytespf = bytespl * h;
  2438. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  2439. * number of lines in a packet. See errata about VP_CLK_RATIO */
  2440. if (bytespf < line_buf_size)
  2441. packet_payload = bytespf;
  2442. else
  2443. packet_payload = (line_buf_size) / bytespl * bytespl;
  2444. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  2445. total_len = (bytespf / packet_payload) * packet_len;
  2446. if (bytespf % packet_payload)
  2447. total_len += (bytespf % packet_payload) + 1;
  2448. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  2449. dsi_write_reg(DSI_VC_TE(channel), l);
  2450. dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
  2451. if (dsi.te_enabled)
  2452. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  2453. else
  2454. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  2455. dsi_write_reg(DSI_VC_TE(channel), l);
  2456. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  2457. * because DSS interrupts are not capable of waking up the CPU and the
  2458. * framedone interrupt could be delayed for quite a long time. I think
  2459. * the same goes for any DSS interrupts, but for some reason I have not
  2460. * seen the problem anywhere else than here.
  2461. */
  2462. dispc_disable_sidle();
  2463. dsi_perf_mark_start();
  2464. r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
  2465. msecs_to_jiffies(250));
  2466. BUG_ON(r == 0);
  2467. dss_start_update(dssdev);
  2468. if (dsi.te_enabled) {
  2469. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  2470. * for TE is longer than the timer allows */
  2471. REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  2472. dsi_vc_send_bta(channel);
  2473. #ifdef DSI_CATCH_MISSING_TE
  2474. mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
  2475. #endif
  2476. }
  2477. }
  2478. #ifdef DSI_CATCH_MISSING_TE
  2479. static void dsi_te_timeout(unsigned long arg)
  2480. {
  2481. DSSERR("TE not received for 250ms!\n");
  2482. }
  2483. #endif
  2484. static void dsi_framedone_bta_callback(void *data, u32 mask);
  2485. static void dsi_handle_framedone(int error)
  2486. {
  2487. const int channel = dsi.update_channel;
  2488. dsi_unregister_isr_vc(channel, dsi_framedone_bta_callback,
  2489. NULL, DSI_VC_IRQ_BTA);
  2490. cancel_delayed_work(&dsi.framedone_timeout_work);
  2491. /* SIDLEMODE back to smart-idle */
  2492. dispc_enable_sidle();
  2493. if (dsi.te_enabled) {
  2494. /* enable LP_RX_TO again after the TE */
  2495. REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2496. }
  2497. /* RX_FIFO_NOT_EMPTY */
  2498. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  2499. DSSERR("Received error during frame transfer:\n");
  2500. dsi_vc_flush_receive_data(channel);
  2501. if (!error)
  2502. error = -EIO;
  2503. }
  2504. dsi.framedone_callback(error, dsi.framedone_data);
  2505. if (!error)
  2506. dsi_perf_show("DISPC");
  2507. }
  2508. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  2509. {
  2510. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  2511. * 250ms which would conflict with this timeout work. What should be
  2512. * done is first cancel the transfer on the HW, and then cancel the
  2513. * possibly scheduled framedone work. However, cancelling the transfer
  2514. * on the HW is buggy, and would probably require resetting the whole
  2515. * DSI */
  2516. DSSERR("Framedone not received for 250ms!\n");
  2517. dsi_handle_framedone(-ETIMEDOUT);
  2518. }
  2519. static void dsi_framedone_bta_callback(void *data, u32 mask)
  2520. {
  2521. dsi_handle_framedone(0);
  2522. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  2523. dispc_fake_vsync_irq();
  2524. #endif
  2525. }
  2526. static void dsi_framedone_irq_callback(void *data, u32 mask)
  2527. {
  2528. const int channel = dsi.update_channel;
  2529. int r;
  2530. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  2531. * turns itself off. However, DSI still has the pixels in its buffers,
  2532. * and is sending the data.
  2533. */
  2534. if (dsi.te_enabled) {
  2535. /* enable LP_RX_TO again after the TE */
  2536. REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2537. }
  2538. /* Send BTA after the frame. We need this for the TE to work, as TE
  2539. * trigger is only sent for BTAs without preceding packet. Thus we need
  2540. * to BTA after the pixel packets so that next BTA will cause TE
  2541. * trigger.
  2542. *
  2543. * This is not needed when TE is not in use, but we do it anyway to
  2544. * make sure that the transfer has been completed. It would be more
  2545. * optimal, but more complex, to wait only just before starting next
  2546. * transfer.
  2547. *
  2548. * Also, as there's no interrupt telling when the transfer has been
  2549. * done and the channel could be reconfigured, the only way is to
  2550. * busyloop until TE_SIZE is zero. With BTA we can do this
  2551. * asynchronously.
  2552. * */
  2553. r = dsi_register_isr_vc(channel, dsi_framedone_bta_callback,
  2554. NULL, DSI_VC_IRQ_BTA);
  2555. if (r) {
  2556. DSSERR("Failed to register BTA ISR\n");
  2557. dsi_handle_framedone(-EIO);
  2558. return;
  2559. }
  2560. r = dsi_vc_send_bta(channel);
  2561. if (r) {
  2562. DSSERR("BTA after framedone failed\n");
  2563. dsi_unregister_isr_vc(channel, dsi_framedone_bta_callback,
  2564. NULL, DSI_VC_IRQ_BTA);
  2565. dsi_handle_framedone(-EIO);
  2566. }
  2567. }
  2568. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  2569. u16 *x, u16 *y, u16 *w, u16 *h,
  2570. bool enlarge_update_area)
  2571. {
  2572. u16 dw, dh;
  2573. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  2574. if (*x > dw || *y > dh)
  2575. return -EINVAL;
  2576. if (*x + *w > dw)
  2577. return -EINVAL;
  2578. if (*y + *h > dh)
  2579. return -EINVAL;
  2580. if (*w == 1)
  2581. return -EINVAL;
  2582. if (*w == 0 || *h == 0)
  2583. return -EINVAL;
  2584. dsi_perf_mark_setup();
  2585. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  2586. dss_setup_partial_planes(dssdev, x, y, w, h,
  2587. enlarge_update_area);
  2588. dispc_set_lcd_size(dssdev->manager->id, *w, *h);
  2589. }
  2590. return 0;
  2591. }
  2592. EXPORT_SYMBOL(omap_dsi_prepare_update);
  2593. int omap_dsi_update(struct omap_dss_device *dssdev,
  2594. int channel,
  2595. u16 x, u16 y, u16 w, u16 h,
  2596. void (*callback)(int, void *), void *data)
  2597. {
  2598. dsi.update_channel = channel;
  2599. /* OMAP DSS cannot send updates of odd widths.
  2600. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  2601. * here to make sure we catch erroneous updates. Otherwise we'll only
  2602. * see rather obscure HW error happening, as DSS halts. */
  2603. BUG_ON(x % 2 == 1);
  2604. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  2605. dsi.framedone_callback = callback;
  2606. dsi.framedone_data = data;
  2607. dsi.update_region.x = x;
  2608. dsi.update_region.y = y;
  2609. dsi.update_region.w = w;
  2610. dsi.update_region.h = h;
  2611. dsi.update_region.device = dssdev;
  2612. dsi_update_screen_dispc(dssdev, x, y, w, h);
  2613. } else {
  2614. int r;
  2615. r = dsi_update_screen_l4(dssdev, x, y, w, h);
  2616. if (r)
  2617. return r;
  2618. dsi_perf_show("L4");
  2619. callback(0, data);
  2620. }
  2621. return 0;
  2622. }
  2623. EXPORT_SYMBOL(omap_dsi_update);
  2624. /* Display funcs */
  2625. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  2626. {
  2627. int r;
  2628. r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
  2629. DISPC_IRQ_FRAMEDONE);
  2630. if (r) {
  2631. DSSERR("can't get FRAMEDONE irq\n");
  2632. return r;
  2633. }
  2634. dispc_set_lcd_display_type(dssdev->manager->id,
  2635. OMAP_DSS_LCD_DISPLAY_TFT);
  2636. dispc_set_parallel_interface_mode(dssdev->manager->id,
  2637. OMAP_DSS_PARALLELMODE_DSI);
  2638. dispc_enable_fifohandcheck(dssdev->manager->id, 1);
  2639. dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
  2640. {
  2641. struct omap_video_timings timings = {
  2642. .hsw = 1,
  2643. .hfp = 1,
  2644. .hbp = 1,
  2645. .vsw = 1,
  2646. .vfp = 0,
  2647. .vbp = 0,
  2648. };
  2649. dispc_set_lcd_timings(dssdev->manager->id, &timings);
  2650. }
  2651. return 0;
  2652. }
  2653. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  2654. {
  2655. omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
  2656. DISPC_IRQ_FRAMEDONE);
  2657. }
  2658. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  2659. {
  2660. struct dsi_clock_info cinfo;
  2661. int r;
  2662. /* we always use DSS_CLK_SYSCK as input clock */
  2663. cinfo.use_sys_clk = true;
  2664. cinfo.regn = dssdev->phy.dsi.div.regn;
  2665. cinfo.regm = dssdev->phy.dsi.div.regm;
  2666. cinfo.regm_dispc = dssdev->phy.dsi.div.regm_dispc;
  2667. cinfo.regm_dsi = dssdev->phy.dsi.div.regm_dsi;
  2668. r = dsi_calc_clock_rates(dssdev, &cinfo);
  2669. if (r) {
  2670. DSSERR("Failed to calc dsi clocks\n");
  2671. return r;
  2672. }
  2673. r = dsi_pll_set_clock_div(&cinfo);
  2674. if (r) {
  2675. DSSERR("Failed to set dsi clocks\n");
  2676. return r;
  2677. }
  2678. return 0;
  2679. }
  2680. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  2681. {
  2682. struct dispc_clock_info dispc_cinfo;
  2683. int r;
  2684. unsigned long long fck;
  2685. fck = dsi_get_pll_hsdiv_dispc_rate();
  2686. dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
  2687. dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
  2688. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  2689. if (r) {
  2690. DSSERR("Failed to calc dispc clocks\n");
  2691. return r;
  2692. }
  2693. r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  2694. if (r) {
  2695. DSSERR("Failed to set dispc clocks\n");
  2696. return r;
  2697. }
  2698. return 0;
  2699. }
  2700. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  2701. {
  2702. int r;
  2703. _dsi_print_reset_status();
  2704. r = dsi_pll_init(dssdev, true, true);
  2705. if (r)
  2706. goto err0;
  2707. r = dsi_configure_dsi_clocks(dssdev);
  2708. if (r)
  2709. goto err1;
  2710. dss_select_dispc_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC);
  2711. dss_select_dsi_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI);
  2712. DSSDBG("PLL OK\n");
  2713. r = dsi_configure_dispc_clocks(dssdev);
  2714. if (r)
  2715. goto err2;
  2716. r = dsi_complexio_init(dssdev);
  2717. if (r)
  2718. goto err2;
  2719. _dsi_print_reset_status();
  2720. dsi_proto_timings(dssdev);
  2721. dsi_set_lp_clk_divisor(dssdev);
  2722. if (1)
  2723. _dsi_print_reset_status();
  2724. r = dsi_proto_config(dssdev);
  2725. if (r)
  2726. goto err3;
  2727. /* enable interface */
  2728. dsi_vc_enable(0, 1);
  2729. dsi_vc_enable(1, 1);
  2730. dsi_vc_enable(2, 1);
  2731. dsi_vc_enable(3, 1);
  2732. dsi_if_enable(1);
  2733. dsi_force_tx_stop_mode_io();
  2734. return 0;
  2735. err3:
  2736. dsi_complexio_uninit();
  2737. err2:
  2738. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  2739. dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
  2740. err1:
  2741. dsi_pll_uninit();
  2742. err0:
  2743. return r;
  2744. }
  2745. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
  2746. {
  2747. /* disable interface */
  2748. dsi_if_enable(0);
  2749. dsi_vc_enable(0, 0);
  2750. dsi_vc_enable(1, 0);
  2751. dsi_vc_enable(2, 0);
  2752. dsi_vc_enable(3, 0);
  2753. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  2754. dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
  2755. dsi_complexio_uninit();
  2756. dsi_pll_uninit();
  2757. }
  2758. static int dsi_core_init(void)
  2759. {
  2760. /* Autoidle */
  2761. REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
  2762. /* ENWAKEUP */
  2763. REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
  2764. /* SIDLEMODE smart-idle */
  2765. REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
  2766. _dsi_initialize_irq();
  2767. return 0;
  2768. }
  2769. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  2770. {
  2771. int r = 0;
  2772. DSSDBG("dsi_display_enable\n");
  2773. WARN_ON(!dsi_bus_is_locked());
  2774. mutex_lock(&dsi.lock);
  2775. r = omap_dss_start_device(dssdev);
  2776. if (r) {
  2777. DSSERR("failed to start device\n");
  2778. goto err0;
  2779. }
  2780. enable_clocks(1);
  2781. dsi_enable_pll_clock(1);
  2782. r = _dsi_reset();
  2783. if (r)
  2784. goto err1;
  2785. dsi_core_init();
  2786. r = dsi_display_init_dispc(dssdev);
  2787. if (r)
  2788. goto err1;
  2789. r = dsi_display_init_dsi(dssdev);
  2790. if (r)
  2791. goto err2;
  2792. mutex_unlock(&dsi.lock);
  2793. return 0;
  2794. err2:
  2795. dsi_display_uninit_dispc(dssdev);
  2796. err1:
  2797. enable_clocks(0);
  2798. dsi_enable_pll_clock(0);
  2799. omap_dss_stop_device(dssdev);
  2800. err0:
  2801. mutex_unlock(&dsi.lock);
  2802. DSSDBG("dsi_display_enable FAILED\n");
  2803. return r;
  2804. }
  2805. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  2806. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
  2807. {
  2808. DSSDBG("dsi_display_disable\n");
  2809. WARN_ON(!dsi_bus_is_locked());
  2810. mutex_lock(&dsi.lock);
  2811. dsi_display_uninit_dispc(dssdev);
  2812. dsi_display_uninit_dsi(dssdev);
  2813. enable_clocks(0);
  2814. dsi_enable_pll_clock(0);
  2815. omap_dss_stop_device(dssdev);
  2816. mutex_unlock(&dsi.lock);
  2817. }
  2818. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  2819. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  2820. {
  2821. dsi.te_enabled = enable;
  2822. return 0;
  2823. }
  2824. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  2825. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  2826. u32 fifo_size, enum omap_burst_size *burst_size,
  2827. u32 *fifo_low, u32 *fifo_high)
  2828. {
  2829. unsigned burst_size_bytes;
  2830. *burst_size = OMAP_DSS_BURST_16x32;
  2831. burst_size_bytes = 16 * 32 / 8;
  2832. *fifo_high = fifo_size - burst_size_bytes;
  2833. *fifo_low = fifo_size - burst_size_bytes * 2;
  2834. }
  2835. int dsi_init_display(struct omap_dss_device *dssdev)
  2836. {
  2837. DSSDBG("DSI init\n");
  2838. /* XXX these should be figured out dynamically */
  2839. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  2840. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  2841. if (dsi.vdds_dsi_reg == NULL) {
  2842. struct regulator *vdds_dsi;
  2843. vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
  2844. if (IS_ERR(vdds_dsi)) {
  2845. DSSERR("can't get VDDS_DSI regulator\n");
  2846. return PTR_ERR(vdds_dsi);
  2847. }
  2848. dsi.vdds_dsi_reg = vdds_dsi;
  2849. }
  2850. return 0;
  2851. }
  2852. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  2853. {
  2854. int i;
  2855. for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
  2856. if (!dsi.vc[i].dssdev) {
  2857. dsi.vc[i].dssdev = dssdev;
  2858. *channel = i;
  2859. return 0;
  2860. }
  2861. }
  2862. DSSERR("cannot get VC for display %s", dssdev->name);
  2863. return -ENOSPC;
  2864. }
  2865. EXPORT_SYMBOL(omap_dsi_request_vc);
  2866. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  2867. {
  2868. if (vc_id < 0 || vc_id > 3) {
  2869. DSSERR("VC ID out of range\n");
  2870. return -EINVAL;
  2871. }
  2872. if (channel < 0 || channel > 3) {
  2873. DSSERR("Virtual Channel out of range\n");
  2874. return -EINVAL;
  2875. }
  2876. if (dsi.vc[channel].dssdev != dssdev) {
  2877. DSSERR("Virtual Channel not allocated to display %s\n",
  2878. dssdev->name);
  2879. return -EINVAL;
  2880. }
  2881. dsi.vc[channel].vc_id = vc_id;
  2882. return 0;
  2883. }
  2884. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  2885. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  2886. {
  2887. if ((channel >= 0 && channel <= 3) &&
  2888. dsi.vc[channel].dssdev == dssdev) {
  2889. dsi.vc[channel].dssdev = NULL;
  2890. dsi.vc[channel].vc_id = 0;
  2891. }
  2892. }
  2893. EXPORT_SYMBOL(omap_dsi_release_vc);
  2894. void dsi_wait_pll_hsdiv_dispc_active(void)
  2895. {
  2896. if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
  2897. DSSERR("%s (%s) not active\n",
  2898. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  2899. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  2900. }
  2901. void dsi_wait_pll_hsdiv_dsi_active(void)
  2902. {
  2903. if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
  2904. DSSERR("%s (%s) not active\n",
  2905. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  2906. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  2907. }
  2908. static void dsi_calc_clock_param_ranges(void)
  2909. {
  2910. dsi.regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  2911. dsi.regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  2912. dsi.regm_dispc_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  2913. dsi.regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  2914. dsi.fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  2915. dsi.fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  2916. dsi.lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  2917. }
  2918. static int dsi_init(struct platform_device *pdev)
  2919. {
  2920. u32 rev;
  2921. int r, i;
  2922. struct resource *dsi_mem;
  2923. spin_lock_init(&dsi.irq_lock);
  2924. spin_lock_init(&dsi.errors_lock);
  2925. dsi.errors = 0;
  2926. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2927. spin_lock_init(&dsi.irq_stats_lock);
  2928. dsi.irq_stats.last_reset = jiffies;
  2929. #endif
  2930. mutex_init(&dsi.lock);
  2931. sema_init(&dsi.bus_lock, 1);
  2932. dsi.workqueue = create_singlethread_workqueue("dsi");
  2933. if (dsi.workqueue == NULL)
  2934. return -ENOMEM;
  2935. INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
  2936. dsi_framedone_timeout_work_callback);
  2937. #ifdef DSI_CATCH_MISSING_TE
  2938. init_timer(&dsi.te_timer);
  2939. dsi.te_timer.function = dsi_te_timeout;
  2940. dsi.te_timer.data = 0;
  2941. #endif
  2942. dsi_mem = platform_get_resource(dsi.pdev, IORESOURCE_MEM, 0);
  2943. if (!dsi_mem) {
  2944. DSSERR("can't get IORESOURCE_MEM DSI\n");
  2945. r = -EINVAL;
  2946. goto err1;
  2947. }
  2948. dsi.base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  2949. if (!dsi.base) {
  2950. DSSERR("can't ioremap DSI\n");
  2951. r = -ENOMEM;
  2952. goto err1;
  2953. }
  2954. dsi.irq = platform_get_irq(dsi.pdev, 0);
  2955. if (dsi.irq < 0) {
  2956. DSSERR("platform_get_irq failed\n");
  2957. r = -ENODEV;
  2958. goto err2;
  2959. }
  2960. r = request_irq(dsi.irq, omap_dsi_irq_handler, IRQF_SHARED,
  2961. "OMAP DSI1", dsi.pdev);
  2962. if (r < 0) {
  2963. DSSERR("request_irq failed\n");
  2964. goto err2;
  2965. }
  2966. /* DSI VCs initialization */
  2967. for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
  2968. dsi.vc[i].mode = DSI_VC_MODE_L4;
  2969. dsi.vc[i].dssdev = NULL;
  2970. dsi.vc[i].vc_id = 0;
  2971. }
  2972. dsi_calc_clock_param_ranges();
  2973. enable_clocks(1);
  2974. rev = dsi_read_reg(DSI_REVISION);
  2975. dev_dbg(&pdev->dev, "OMAP DSI rev %d.%d\n",
  2976. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  2977. enable_clocks(0);
  2978. return 0;
  2979. err2:
  2980. iounmap(dsi.base);
  2981. err1:
  2982. destroy_workqueue(dsi.workqueue);
  2983. return r;
  2984. }
  2985. static void dsi_exit(void)
  2986. {
  2987. if (dsi.vdds_dsi_reg != NULL) {
  2988. regulator_put(dsi.vdds_dsi_reg);
  2989. dsi.vdds_dsi_reg = NULL;
  2990. }
  2991. free_irq(dsi.irq, dsi.pdev);
  2992. iounmap(dsi.base);
  2993. destroy_workqueue(dsi.workqueue);
  2994. DSSDBG("omap_dsi_exit\n");
  2995. }
  2996. /* DSI1 HW IP initialisation */
  2997. static int omap_dsi1hw_probe(struct platform_device *pdev)
  2998. {
  2999. int r;
  3000. dsi.pdev = pdev;
  3001. r = dsi_init(pdev);
  3002. if (r) {
  3003. DSSERR("Failed to initialize DSI\n");
  3004. goto err_dsi;
  3005. }
  3006. err_dsi:
  3007. return r;
  3008. }
  3009. static int omap_dsi1hw_remove(struct platform_device *pdev)
  3010. {
  3011. dsi_exit();
  3012. return 0;
  3013. }
  3014. static struct platform_driver omap_dsi1hw_driver = {
  3015. .probe = omap_dsi1hw_probe,
  3016. .remove = omap_dsi1hw_remove,
  3017. .driver = {
  3018. .name = "omapdss_dsi1",
  3019. .owner = THIS_MODULE,
  3020. },
  3021. };
  3022. int dsi_init_platform_driver(void)
  3023. {
  3024. return platform_driver_register(&omap_dsi1hw_driver);
  3025. }
  3026. void dsi_uninit_platform_driver(void)
  3027. {
  3028. return platform_driver_unregister(&omap_dsi1hw_driver);
  3029. }