dsi.c 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808
  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 <video/omapdss.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 = 0;
  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 (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
  1084. f = cinfo->fint < 1000000 ? 0x3 :
  1085. cinfo->fint < 1250000 ? 0x4 :
  1086. cinfo->fint < 1500000 ? 0x5 :
  1087. cinfo->fint < 1750000 ? 0x6 :
  1088. 0x7;
  1089. }
  1090. l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
  1091. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
  1092. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1093. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1094. 11, 11); /* DSI_PLL_CLKSEL */
  1095. l = FLD_MOD(l, cinfo->highfreq,
  1096. 12, 12); /* DSI_PLL_HIGHFREQ */
  1097. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1098. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1099. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1100. dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
  1101. REG_FLD_MOD(DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1102. if (wait_for_bit_change(DSI_PLL_GO, 0, 0) != 0) {
  1103. DSSERR("dsi pll go bit not going down.\n");
  1104. r = -EIO;
  1105. goto err;
  1106. }
  1107. if (wait_for_bit_change(DSI_PLL_STATUS, 1, 1) != 1) {
  1108. DSSERR("cannot lock PLL\n");
  1109. r = -EIO;
  1110. goto err;
  1111. }
  1112. dsi.pll_locked = 1;
  1113. l = dsi_read_reg(DSI_PLL_CONFIGURATION2);
  1114. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1115. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1116. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1117. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1118. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1119. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1120. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1121. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1122. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1123. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1124. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1125. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1126. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1127. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1128. dsi_write_reg(DSI_PLL_CONFIGURATION2, l);
  1129. DSSDBG("PLL config done\n");
  1130. err:
  1131. return r;
  1132. }
  1133. int dsi_pll_init(struct omap_dss_device *dssdev, bool enable_hsclk,
  1134. bool enable_hsdiv)
  1135. {
  1136. int r = 0;
  1137. enum dsi_pll_power_state pwstate;
  1138. DSSDBG("PLL init\n");
  1139. #ifdef CONFIG_OMAP2_DSS_USE_DSI_PLL
  1140. /*
  1141. * HACK: this is just a quick hack to get the USE_DSI_PLL
  1142. * option working. USE_DSI_PLL is itself a big hack, and
  1143. * should be removed.
  1144. */
  1145. if (dsi.vdds_dsi_reg == NULL) {
  1146. struct regulator *vdds_dsi;
  1147. vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
  1148. if (IS_ERR(vdds_dsi)) {
  1149. DSSERR("can't get VDDS_DSI regulator\n");
  1150. return PTR_ERR(vdds_dsi);
  1151. }
  1152. dsi.vdds_dsi_reg = vdds_dsi;
  1153. }
  1154. #endif
  1155. enable_clocks(1);
  1156. dsi_enable_pll_clock(1);
  1157. r = regulator_enable(dsi.vdds_dsi_reg);
  1158. if (r)
  1159. goto err0;
  1160. /* XXX PLL does not come out of reset without this... */
  1161. dispc_pck_free_enable(1);
  1162. if (wait_for_bit_change(DSI_PLL_STATUS, 0, 1) != 1) {
  1163. DSSERR("PLL not coming out of reset.\n");
  1164. r = -ENODEV;
  1165. dispc_pck_free_enable(0);
  1166. goto err1;
  1167. }
  1168. /* XXX ... but if left on, we get problems when planes do not
  1169. * fill the whole display. No idea about this */
  1170. dispc_pck_free_enable(0);
  1171. if (enable_hsclk && enable_hsdiv)
  1172. pwstate = DSI_PLL_POWER_ON_ALL;
  1173. else if (enable_hsclk)
  1174. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1175. else if (enable_hsdiv)
  1176. pwstate = DSI_PLL_POWER_ON_DIV;
  1177. else
  1178. pwstate = DSI_PLL_POWER_OFF;
  1179. r = dsi_pll_power(pwstate);
  1180. if (r)
  1181. goto err1;
  1182. DSSDBG("PLL init done\n");
  1183. return 0;
  1184. err1:
  1185. regulator_disable(dsi.vdds_dsi_reg);
  1186. err0:
  1187. enable_clocks(0);
  1188. dsi_enable_pll_clock(0);
  1189. return r;
  1190. }
  1191. void dsi_pll_uninit(void)
  1192. {
  1193. enable_clocks(0);
  1194. dsi_enable_pll_clock(0);
  1195. dsi.pll_locked = 0;
  1196. dsi_pll_power(DSI_PLL_POWER_OFF);
  1197. regulator_disable(dsi.vdds_dsi_reg);
  1198. DSSDBG("PLL uninit done\n");
  1199. }
  1200. void dsi_dump_clocks(struct seq_file *s)
  1201. {
  1202. struct dsi_clock_info *cinfo = &dsi.current_cinfo;
  1203. enum dss_clk_source dispc_clk_src, dsi_clk_src;
  1204. dispc_clk_src = dss_get_dispc_clk_source();
  1205. dsi_clk_src = dss_get_dsi_clk_source();
  1206. enable_clocks(1);
  1207. seq_printf(s, "- DSI PLL -\n");
  1208. seq_printf(s, "dsi pll source = %s\n",
  1209. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
  1210. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1211. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1212. cinfo->clkin4ddr, cinfo->regm);
  1213. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1214. dss_get_generic_clk_source_name(dispc_clk_src),
  1215. dss_feat_get_clk_source_name(dispc_clk_src),
  1216. cinfo->dsi_pll_hsdiv_dispc_clk,
  1217. cinfo->regm_dispc,
  1218. dispc_clk_src == DSS_CLK_SRC_FCK ?
  1219. "off" : "on");
  1220. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1221. dss_get_generic_clk_source_name(dsi_clk_src),
  1222. dss_feat_get_clk_source_name(dsi_clk_src),
  1223. cinfo->dsi_pll_hsdiv_dsi_clk,
  1224. cinfo->regm_dsi,
  1225. dsi_clk_src == DSS_CLK_SRC_FCK ?
  1226. "off" : "on");
  1227. seq_printf(s, "- DSI -\n");
  1228. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1229. dss_get_generic_clk_source_name(dsi_clk_src),
  1230. dss_feat_get_clk_source_name(dsi_clk_src));
  1231. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate());
  1232. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1233. cinfo->clkin4ddr / 4);
  1234. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs());
  1235. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1236. seq_printf(s, "VP_CLK\t\t%lu\n"
  1237. "VP_PCLK\t\t%lu\n",
  1238. dispc_lclk_rate(OMAP_DSS_CHANNEL_LCD),
  1239. dispc_pclk_rate(OMAP_DSS_CHANNEL_LCD));
  1240. enable_clocks(0);
  1241. }
  1242. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1243. void dsi_dump_irqs(struct seq_file *s)
  1244. {
  1245. unsigned long flags;
  1246. struct dsi_irq_stats stats;
  1247. spin_lock_irqsave(&dsi.irq_stats_lock, flags);
  1248. stats = dsi.irq_stats;
  1249. memset(&dsi.irq_stats, 0, sizeof(dsi.irq_stats));
  1250. dsi.irq_stats.last_reset = jiffies;
  1251. spin_unlock_irqrestore(&dsi.irq_stats_lock, flags);
  1252. seq_printf(s, "period %u ms\n",
  1253. jiffies_to_msecs(jiffies - stats.last_reset));
  1254. seq_printf(s, "irqs %d\n", stats.irq_count);
  1255. #define PIS(x) \
  1256. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1257. seq_printf(s, "-- DSI interrupts --\n");
  1258. PIS(VC0);
  1259. PIS(VC1);
  1260. PIS(VC2);
  1261. PIS(VC3);
  1262. PIS(WAKEUP);
  1263. PIS(RESYNC);
  1264. PIS(PLL_LOCK);
  1265. PIS(PLL_UNLOCK);
  1266. PIS(PLL_RECALL);
  1267. PIS(COMPLEXIO_ERR);
  1268. PIS(HS_TX_TIMEOUT);
  1269. PIS(LP_RX_TIMEOUT);
  1270. PIS(TE_TRIGGER);
  1271. PIS(ACK_TRIGGER);
  1272. PIS(SYNC_LOST);
  1273. PIS(LDO_POWER_GOOD);
  1274. PIS(TA_TIMEOUT);
  1275. #undef PIS
  1276. #define PIS(x) \
  1277. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1278. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1279. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1280. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1281. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1282. seq_printf(s, "-- VC interrupts --\n");
  1283. PIS(CS);
  1284. PIS(ECC_CORR);
  1285. PIS(PACKET_SENT);
  1286. PIS(FIFO_TX_OVF);
  1287. PIS(FIFO_RX_OVF);
  1288. PIS(BTA);
  1289. PIS(ECC_NO_CORR);
  1290. PIS(FIFO_TX_UDF);
  1291. PIS(PP_BUSY_CHANGE);
  1292. #undef PIS
  1293. #define PIS(x) \
  1294. seq_printf(s, "%-20s %10d\n", #x, \
  1295. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1296. seq_printf(s, "-- CIO interrupts --\n");
  1297. PIS(ERRSYNCESC1);
  1298. PIS(ERRSYNCESC2);
  1299. PIS(ERRSYNCESC3);
  1300. PIS(ERRESC1);
  1301. PIS(ERRESC2);
  1302. PIS(ERRESC3);
  1303. PIS(ERRCONTROL1);
  1304. PIS(ERRCONTROL2);
  1305. PIS(ERRCONTROL3);
  1306. PIS(STATEULPS1);
  1307. PIS(STATEULPS2);
  1308. PIS(STATEULPS3);
  1309. PIS(ERRCONTENTIONLP0_1);
  1310. PIS(ERRCONTENTIONLP1_1);
  1311. PIS(ERRCONTENTIONLP0_2);
  1312. PIS(ERRCONTENTIONLP1_2);
  1313. PIS(ERRCONTENTIONLP0_3);
  1314. PIS(ERRCONTENTIONLP1_3);
  1315. PIS(ULPSACTIVENOT_ALL0);
  1316. PIS(ULPSACTIVENOT_ALL1);
  1317. #undef PIS
  1318. }
  1319. #endif
  1320. void dsi_dump_regs(struct seq_file *s)
  1321. {
  1322. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(r))
  1323. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  1324. DUMPREG(DSI_REVISION);
  1325. DUMPREG(DSI_SYSCONFIG);
  1326. DUMPREG(DSI_SYSSTATUS);
  1327. DUMPREG(DSI_IRQSTATUS);
  1328. DUMPREG(DSI_IRQENABLE);
  1329. DUMPREG(DSI_CTRL);
  1330. DUMPREG(DSI_COMPLEXIO_CFG1);
  1331. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1332. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1333. DUMPREG(DSI_CLK_CTRL);
  1334. DUMPREG(DSI_TIMING1);
  1335. DUMPREG(DSI_TIMING2);
  1336. DUMPREG(DSI_VM_TIMING1);
  1337. DUMPREG(DSI_VM_TIMING2);
  1338. DUMPREG(DSI_VM_TIMING3);
  1339. DUMPREG(DSI_CLK_TIMING);
  1340. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1341. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1342. DUMPREG(DSI_COMPLEXIO_CFG2);
  1343. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1344. DUMPREG(DSI_VM_TIMING4);
  1345. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1346. DUMPREG(DSI_VM_TIMING5);
  1347. DUMPREG(DSI_VM_TIMING6);
  1348. DUMPREG(DSI_VM_TIMING7);
  1349. DUMPREG(DSI_STOPCLK_TIMING);
  1350. DUMPREG(DSI_VC_CTRL(0));
  1351. DUMPREG(DSI_VC_TE(0));
  1352. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1353. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1354. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1355. DUMPREG(DSI_VC_IRQSTATUS(0));
  1356. DUMPREG(DSI_VC_IRQENABLE(0));
  1357. DUMPREG(DSI_VC_CTRL(1));
  1358. DUMPREG(DSI_VC_TE(1));
  1359. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1360. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1361. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1362. DUMPREG(DSI_VC_IRQSTATUS(1));
  1363. DUMPREG(DSI_VC_IRQENABLE(1));
  1364. DUMPREG(DSI_VC_CTRL(2));
  1365. DUMPREG(DSI_VC_TE(2));
  1366. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1367. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1368. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1369. DUMPREG(DSI_VC_IRQSTATUS(2));
  1370. DUMPREG(DSI_VC_IRQENABLE(2));
  1371. DUMPREG(DSI_VC_CTRL(3));
  1372. DUMPREG(DSI_VC_TE(3));
  1373. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1374. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1375. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1376. DUMPREG(DSI_VC_IRQSTATUS(3));
  1377. DUMPREG(DSI_VC_IRQENABLE(3));
  1378. DUMPREG(DSI_DSIPHY_CFG0);
  1379. DUMPREG(DSI_DSIPHY_CFG1);
  1380. DUMPREG(DSI_DSIPHY_CFG2);
  1381. DUMPREG(DSI_DSIPHY_CFG5);
  1382. DUMPREG(DSI_PLL_CONTROL);
  1383. DUMPREG(DSI_PLL_STATUS);
  1384. DUMPREG(DSI_PLL_GO);
  1385. DUMPREG(DSI_PLL_CONFIGURATION1);
  1386. DUMPREG(DSI_PLL_CONFIGURATION2);
  1387. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  1388. #undef DUMPREG
  1389. }
  1390. enum dsi_complexio_power_state {
  1391. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1392. DSI_COMPLEXIO_POWER_ON = 0x1,
  1393. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1394. };
  1395. static int dsi_complexio_power(enum dsi_complexio_power_state state)
  1396. {
  1397. int t = 0;
  1398. /* PWR_CMD */
  1399. REG_FLD_MOD(DSI_COMPLEXIO_CFG1, state, 28, 27);
  1400. /* PWR_STATUS */
  1401. while (FLD_GET(dsi_read_reg(DSI_COMPLEXIO_CFG1), 26, 25) != state) {
  1402. if (++t > 1000) {
  1403. DSSERR("failed to set complexio power state to "
  1404. "%d\n", state);
  1405. return -ENODEV;
  1406. }
  1407. udelay(1);
  1408. }
  1409. return 0;
  1410. }
  1411. static void dsi_complexio_config(struct omap_dss_device *dssdev)
  1412. {
  1413. u32 r;
  1414. int clk_lane = dssdev->phy.dsi.clk_lane;
  1415. int data1_lane = dssdev->phy.dsi.data1_lane;
  1416. int data2_lane = dssdev->phy.dsi.data2_lane;
  1417. int clk_pol = dssdev->phy.dsi.clk_pol;
  1418. int data1_pol = dssdev->phy.dsi.data1_pol;
  1419. int data2_pol = dssdev->phy.dsi.data2_pol;
  1420. r = dsi_read_reg(DSI_COMPLEXIO_CFG1);
  1421. r = FLD_MOD(r, clk_lane, 2, 0);
  1422. r = FLD_MOD(r, clk_pol, 3, 3);
  1423. r = FLD_MOD(r, data1_lane, 6, 4);
  1424. r = FLD_MOD(r, data1_pol, 7, 7);
  1425. r = FLD_MOD(r, data2_lane, 10, 8);
  1426. r = FLD_MOD(r, data2_pol, 11, 11);
  1427. dsi_write_reg(DSI_COMPLEXIO_CFG1, r);
  1428. /* The configuration of the DSI complex I/O (number of data lanes,
  1429. position, differential order) should not be changed while
  1430. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1431. the hardware to take into account a new configuration of the complex
  1432. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1433. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1434. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1435. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1436. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1437. DSI complex I/O configuration is unknown. */
  1438. /*
  1439. REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
  1440. REG_FLD_MOD(DSI_CTRL, 0, 0, 0);
  1441. REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20);
  1442. REG_FLD_MOD(DSI_CTRL, 1, 0, 0);
  1443. */
  1444. }
  1445. static inline unsigned ns2ddr(unsigned ns)
  1446. {
  1447. /* convert time in ns to ddr ticks, rounding up */
  1448. unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
  1449. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1450. }
  1451. static inline unsigned ddr2ns(unsigned ddr)
  1452. {
  1453. unsigned long ddr_clk = dsi.current_cinfo.clkin4ddr / 4;
  1454. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1455. }
  1456. static void dsi_complexio_timings(void)
  1457. {
  1458. u32 r;
  1459. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1460. u32 tlpx_half, tclk_trail, tclk_zero;
  1461. u32 tclk_prepare;
  1462. /* calculate timings */
  1463. /* 1 * DDR_CLK = 2 * UI */
  1464. /* min 40ns + 4*UI max 85ns + 6*UI */
  1465. ths_prepare = ns2ddr(70) + 2;
  1466. /* min 145ns + 10*UI */
  1467. ths_prepare_ths_zero = ns2ddr(175) + 2;
  1468. /* min max(8*UI, 60ns+4*UI) */
  1469. ths_trail = ns2ddr(60) + 5;
  1470. /* min 100ns */
  1471. ths_exit = ns2ddr(145);
  1472. /* tlpx min 50n */
  1473. tlpx_half = ns2ddr(25);
  1474. /* min 60ns */
  1475. tclk_trail = ns2ddr(60) + 2;
  1476. /* min 38ns, max 95ns */
  1477. tclk_prepare = ns2ddr(65);
  1478. /* min tclk-prepare + tclk-zero = 300ns */
  1479. tclk_zero = ns2ddr(260);
  1480. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1481. ths_prepare, ddr2ns(ths_prepare),
  1482. ths_prepare_ths_zero, ddr2ns(ths_prepare_ths_zero));
  1483. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1484. ths_trail, ddr2ns(ths_trail),
  1485. ths_exit, ddr2ns(ths_exit));
  1486. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1487. "tclk_zero %u (%uns)\n",
  1488. tlpx_half, ddr2ns(tlpx_half),
  1489. tclk_trail, ddr2ns(tclk_trail),
  1490. tclk_zero, ddr2ns(tclk_zero));
  1491. DSSDBG("tclk_prepare %u (%uns)\n",
  1492. tclk_prepare, ddr2ns(tclk_prepare));
  1493. /* program timings */
  1494. r = dsi_read_reg(DSI_DSIPHY_CFG0);
  1495. r = FLD_MOD(r, ths_prepare, 31, 24);
  1496. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1497. r = FLD_MOD(r, ths_trail, 15, 8);
  1498. r = FLD_MOD(r, ths_exit, 7, 0);
  1499. dsi_write_reg(DSI_DSIPHY_CFG0, r);
  1500. r = dsi_read_reg(DSI_DSIPHY_CFG1);
  1501. r = FLD_MOD(r, tlpx_half, 22, 16);
  1502. r = FLD_MOD(r, tclk_trail, 15, 8);
  1503. r = FLD_MOD(r, tclk_zero, 7, 0);
  1504. dsi_write_reg(DSI_DSIPHY_CFG1, r);
  1505. r = dsi_read_reg(DSI_DSIPHY_CFG2);
  1506. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1507. dsi_write_reg(DSI_DSIPHY_CFG2, r);
  1508. }
  1509. static int dsi_complexio_init(struct omap_dss_device *dssdev)
  1510. {
  1511. int r = 0;
  1512. DSSDBG("dsi_complexio_init\n");
  1513. /* A dummy read using the SCP interface to any DSIPHY register is
  1514. * required after DSIPHY reset to complete the reset of the DSI complex
  1515. * I/O. */
  1516. dsi_read_reg(DSI_DSIPHY_CFG5);
  1517. if (wait_for_bit_change(DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1518. DSSERR("ComplexIO PHY not coming out of reset.\n");
  1519. r = -ENODEV;
  1520. goto err;
  1521. }
  1522. dsi_complexio_config(dssdev);
  1523. r = dsi_complexio_power(DSI_COMPLEXIO_POWER_ON);
  1524. if (r)
  1525. goto err;
  1526. if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1527. DSSERR("ComplexIO not coming out of reset.\n");
  1528. r = -ENODEV;
  1529. goto err;
  1530. }
  1531. if (dss_has_feature(FEAT_DSI_LDO_STATUS)) {
  1532. if (wait_for_bit_change(DSI_COMPLEXIO_CFG1, 21, 1) != 1) {
  1533. DSSERR("ComplexIO LDO power down.\n");
  1534. r = -ENODEV;
  1535. goto err;
  1536. }
  1537. }
  1538. dsi_complexio_timings();
  1539. /*
  1540. The configuration of the DSI complex I/O (number of data lanes,
  1541. position, differential order) should not be changed while
  1542. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. For the
  1543. hardware to recognize a new configuration of the complex I/O (done
  1544. in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to follow
  1545. this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1, next
  1546. reset the DSS.DSI_CTRL[0] IF_EN to 0, then set DSS.DSI_CLK_CTRL[20]
  1547. LP_CLK_ENABLE to 1, and finally, set again the DSS.DSI_CTRL[0] IF_EN
  1548. bit to 1. If the sequence is not followed, the DSi complex I/O
  1549. configuration is undetermined.
  1550. */
  1551. dsi_if_enable(1);
  1552. dsi_if_enable(0);
  1553. REG_FLD_MOD(DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1554. dsi_if_enable(1);
  1555. dsi_if_enable(0);
  1556. DSSDBG("CIO init done\n");
  1557. err:
  1558. return r;
  1559. }
  1560. static void dsi_complexio_uninit(void)
  1561. {
  1562. dsi_complexio_power(DSI_COMPLEXIO_POWER_OFF);
  1563. }
  1564. static int _dsi_wait_reset(void)
  1565. {
  1566. int t = 0;
  1567. while (REG_GET(DSI_SYSSTATUS, 0, 0) == 0) {
  1568. if (++t > 5) {
  1569. DSSERR("soft reset failed\n");
  1570. return -ENODEV;
  1571. }
  1572. udelay(1);
  1573. }
  1574. return 0;
  1575. }
  1576. static int _dsi_reset(void)
  1577. {
  1578. /* Soft reset */
  1579. REG_FLD_MOD(DSI_SYSCONFIG, 1, 1, 1);
  1580. return _dsi_wait_reset();
  1581. }
  1582. static void dsi_config_tx_fifo(enum fifo_size size1, enum fifo_size size2,
  1583. enum fifo_size size3, enum fifo_size size4)
  1584. {
  1585. u32 r = 0;
  1586. int add = 0;
  1587. int i;
  1588. dsi.vc[0].fifo_size = size1;
  1589. dsi.vc[1].fifo_size = size2;
  1590. dsi.vc[2].fifo_size = size3;
  1591. dsi.vc[3].fifo_size = size4;
  1592. for (i = 0; i < 4; i++) {
  1593. u8 v;
  1594. int size = dsi.vc[i].fifo_size;
  1595. if (add + size > 4) {
  1596. DSSERR("Illegal FIFO configuration\n");
  1597. BUG();
  1598. }
  1599. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1600. r |= v << (8 * i);
  1601. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1602. add += size;
  1603. }
  1604. dsi_write_reg(DSI_TX_FIFO_VC_SIZE, r);
  1605. }
  1606. static void dsi_config_rx_fifo(enum fifo_size size1, enum fifo_size size2,
  1607. enum fifo_size size3, enum fifo_size size4)
  1608. {
  1609. u32 r = 0;
  1610. int add = 0;
  1611. int i;
  1612. dsi.vc[0].fifo_size = size1;
  1613. dsi.vc[1].fifo_size = size2;
  1614. dsi.vc[2].fifo_size = size3;
  1615. dsi.vc[3].fifo_size = size4;
  1616. for (i = 0; i < 4; i++) {
  1617. u8 v;
  1618. int size = dsi.vc[i].fifo_size;
  1619. if (add + size > 4) {
  1620. DSSERR("Illegal FIFO configuration\n");
  1621. BUG();
  1622. }
  1623. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  1624. r |= v << (8 * i);
  1625. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  1626. add += size;
  1627. }
  1628. dsi_write_reg(DSI_RX_FIFO_VC_SIZE, r);
  1629. }
  1630. static int dsi_force_tx_stop_mode_io(void)
  1631. {
  1632. u32 r;
  1633. r = dsi_read_reg(DSI_TIMING1);
  1634. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1635. dsi_write_reg(DSI_TIMING1, r);
  1636. if (wait_for_bit_change(DSI_TIMING1, 15, 0) != 0) {
  1637. DSSERR("TX_STOP bit not going down\n");
  1638. return -EIO;
  1639. }
  1640. return 0;
  1641. }
  1642. static int dsi_vc_enable(int channel, bool enable)
  1643. {
  1644. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  1645. channel, enable);
  1646. enable = enable ? 1 : 0;
  1647. REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 0, 0);
  1648. if (wait_for_bit_change(DSI_VC_CTRL(channel), 0, enable) != enable) {
  1649. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  1650. return -EIO;
  1651. }
  1652. return 0;
  1653. }
  1654. static void dsi_vc_initial_config(int channel)
  1655. {
  1656. u32 r;
  1657. DSSDBGF("%d", channel);
  1658. r = dsi_read_reg(DSI_VC_CTRL(channel));
  1659. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  1660. DSSERR("VC(%d) busy when trying to configure it!\n",
  1661. channel);
  1662. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  1663. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  1664. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  1665. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  1666. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  1667. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  1668. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  1669. if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
  1670. r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
  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. /* DCS_CMD_ENABLE */
  1688. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
  1689. REG_FLD_MOD(DSI_VC_CTRL(channel), 0, 30, 30);
  1690. dsi_vc_enable(channel, 1);
  1691. dsi.vc[channel].mode = DSI_VC_MODE_L4;
  1692. return 0;
  1693. }
  1694. static int dsi_vc_config_vp(int channel)
  1695. {
  1696. if (dsi.vc[channel].mode == DSI_VC_MODE_VP)
  1697. return 0;
  1698. DSSDBGF("%d", channel);
  1699. dsi_vc_enable(channel, 0);
  1700. /* VC_BUSY */
  1701. if (wait_for_bit_change(DSI_VC_CTRL(channel), 15, 0) != 0) {
  1702. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  1703. return -EIO;
  1704. }
  1705. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 1, 1); /* SOURCE, 1 = video port */
  1706. /* DCS_CMD_ENABLE */
  1707. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
  1708. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 30, 30);
  1709. dsi_vc_enable(channel, 1);
  1710. dsi.vc[channel].mode = DSI_VC_MODE_VP;
  1711. return 0;
  1712. }
  1713. void omapdss_dsi_vc_enable_hs(int channel, bool enable)
  1714. {
  1715. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  1716. WARN_ON(!dsi_bus_is_locked());
  1717. dsi_vc_enable(channel, 0);
  1718. dsi_if_enable(0);
  1719. REG_FLD_MOD(DSI_VC_CTRL(channel), enable, 9, 9);
  1720. dsi_vc_enable(channel, 1);
  1721. dsi_if_enable(1);
  1722. dsi_force_tx_stop_mode_io();
  1723. }
  1724. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  1725. static void dsi_vc_flush_long_data(int channel)
  1726. {
  1727. while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  1728. u32 val;
  1729. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  1730. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  1731. (val >> 0) & 0xff,
  1732. (val >> 8) & 0xff,
  1733. (val >> 16) & 0xff,
  1734. (val >> 24) & 0xff);
  1735. }
  1736. }
  1737. static void dsi_show_rx_ack_with_err(u16 err)
  1738. {
  1739. DSSERR("\tACK with ERROR (%#x):\n", err);
  1740. if (err & (1 << 0))
  1741. DSSERR("\t\tSoT Error\n");
  1742. if (err & (1 << 1))
  1743. DSSERR("\t\tSoT Sync Error\n");
  1744. if (err & (1 << 2))
  1745. DSSERR("\t\tEoT Sync Error\n");
  1746. if (err & (1 << 3))
  1747. DSSERR("\t\tEscape Mode Entry Command Error\n");
  1748. if (err & (1 << 4))
  1749. DSSERR("\t\tLP Transmit Sync Error\n");
  1750. if (err & (1 << 5))
  1751. DSSERR("\t\tHS Receive Timeout Error\n");
  1752. if (err & (1 << 6))
  1753. DSSERR("\t\tFalse Control Error\n");
  1754. if (err & (1 << 7))
  1755. DSSERR("\t\t(reserved7)\n");
  1756. if (err & (1 << 8))
  1757. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  1758. if (err & (1 << 9))
  1759. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  1760. if (err & (1 << 10))
  1761. DSSERR("\t\tChecksum Error\n");
  1762. if (err & (1 << 11))
  1763. DSSERR("\t\tData type not recognized\n");
  1764. if (err & (1 << 12))
  1765. DSSERR("\t\tInvalid VC ID\n");
  1766. if (err & (1 << 13))
  1767. DSSERR("\t\tInvalid Transmission Length\n");
  1768. if (err & (1 << 14))
  1769. DSSERR("\t\t(reserved14)\n");
  1770. if (err & (1 << 15))
  1771. DSSERR("\t\tDSI Protocol Violation\n");
  1772. }
  1773. static u16 dsi_vc_flush_receive_data(int channel)
  1774. {
  1775. /* RX_FIFO_NOT_EMPTY */
  1776. while (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  1777. u32 val;
  1778. u8 dt;
  1779. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  1780. DSSERR("\trawval %#08x\n", val);
  1781. dt = FLD_GET(val, 5, 0);
  1782. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  1783. u16 err = FLD_GET(val, 23, 8);
  1784. dsi_show_rx_ack_with_err(err);
  1785. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  1786. DSSERR("\tDCS short response, 1 byte: %#x\n",
  1787. FLD_GET(val, 23, 8));
  1788. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  1789. DSSERR("\tDCS short response, 2 byte: %#x\n",
  1790. FLD_GET(val, 23, 8));
  1791. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  1792. DSSERR("\tDCS long response, len %d\n",
  1793. FLD_GET(val, 23, 8));
  1794. dsi_vc_flush_long_data(channel);
  1795. } else {
  1796. DSSERR("\tunknown datatype 0x%02x\n", dt);
  1797. }
  1798. }
  1799. return 0;
  1800. }
  1801. static int dsi_vc_send_bta(int channel)
  1802. {
  1803. if (dsi.debug_write || dsi.debug_read)
  1804. DSSDBG("dsi_vc_send_bta %d\n", channel);
  1805. WARN_ON(!dsi_bus_is_locked());
  1806. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
  1807. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  1808. dsi_vc_flush_receive_data(channel);
  1809. }
  1810. REG_FLD_MOD(DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  1811. return 0;
  1812. }
  1813. int dsi_vc_send_bta_sync(int channel)
  1814. {
  1815. DECLARE_COMPLETION_ONSTACK(completion);
  1816. int r = 0;
  1817. u32 err;
  1818. r = dsi_register_isr_vc(channel, dsi_completion_handler,
  1819. &completion, DSI_VC_IRQ_BTA);
  1820. if (r)
  1821. goto err0;
  1822. r = dsi_register_isr(dsi_completion_handler, &completion,
  1823. DSI_IRQ_ERROR_MASK);
  1824. if (r)
  1825. goto err1;
  1826. r = dsi_vc_send_bta(channel);
  1827. if (r)
  1828. goto err2;
  1829. if (wait_for_completion_timeout(&completion,
  1830. msecs_to_jiffies(500)) == 0) {
  1831. DSSERR("Failed to receive BTA\n");
  1832. r = -EIO;
  1833. goto err2;
  1834. }
  1835. err = dsi_get_errors();
  1836. if (err) {
  1837. DSSERR("Error while sending BTA: %x\n", err);
  1838. r = -EIO;
  1839. goto err2;
  1840. }
  1841. err2:
  1842. dsi_unregister_isr(dsi_completion_handler, &completion,
  1843. DSI_IRQ_ERROR_MASK);
  1844. err1:
  1845. dsi_unregister_isr_vc(channel, dsi_completion_handler,
  1846. &completion, DSI_VC_IRQ_BTA);
  1847. err0:
  1848. return r;
  1849. }
  1850. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  1851. static inline void dsi_vc_write_long_header(int channel, u8 data_type,
  1852. u16 len, u8 ecc)
  1853. {
  1854. u32 val;
  1855. u8 data_id;
  1856. WARN_ON(!dsi_bus_is_locked());
  1857. data_id = data_type | dsi.vc[channel].vc_id << 6;
  1858. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  1859. FLD_VAL(ecc, 31, 24);
  1860. dsi_write_reg(DSI_VC_LONG_PACKET_HEADER(channel), val);
  1861. }
  1862. static inline void dsi_vc_write_long_payload(int channel,
  1863. u8 b1, u8 b2, u8 b3, u8 b4)
  1864. {
  1865. u32 val;
  1866. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  1867. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  1868. b1, b2, b3, b4, val); */
  1869. dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  1870. }
  1871. static int dsi_vc_send_long(int channel, u8 data_type, u8 *data, u16 len,
  1872. u8 ecc)
  1873. {
  1874. /*u32 val; */
  1875. int i;
  1876. u8 *p;
  1877. int r = 0;
  1878. u8 b1, b2, b3, b4;
  1879. if (dsi.debug_write)
  1880. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  1881. /* len + header */
  1882. if (dsi.vc[channel].fifo_size * 32 * 4 < len + 4) {
  1883. DSSERR("unable to send long packet: packet too long.\n");
  1884. return -EINVAL;
  1885. }
  1886. dsi_vc_config_l4(channel);
  1887. dsi_vc_write_long_header(channel, data_type, len, ecc);
  1888. p = data;
  1889. for (i = 0; i < len >> 2; i++) {
  1890. if (dsi.debug_write)
  1891. DSSDBG("\tsending full packet %d\n", i);
  1892. b1 = *p++;
  1893. b2 = *p++;
  1894. b3 = *p++;
  1895. b4 = *p++;
  1896. dsi_vc_write_long_payload(channel, b1, b2, b3, b4);
  1897. }
  1898. i = len % 4;
  1899. if (i) {
  1900. b1 = 0; b2 = 0; b3 = 0;
  1901. if (dsi.debug_write)
  1902. DSSDBG("\tsending remainder bytes %d\n", i);
  1903. switch (i) {
  1904. case 3:
  1905. b1 = *p++;
  1906. b2 = *p++;
  1907. b3 = *p++;
  1908. break;
  1909. case 2:
  1910. b1 = *p++;
  1911. b2 = *p++;
  1912. break;
  1913. case 1:
  1914. b1 = *p++;
  1915. break;
  1916. }
  1917. dsi_vc_write_long_payload(channel, b1, b2, b3, 0);
  1918. }
  1919. return r;
  1920. }
  1921. static int dsi_vc_send_short(int channel, u8 data_type, u16 data, u8 ecc)
  1922. {
  1923. u32 r;
  1924. u8 data_id;
  1925. WARN_ON(!dsi_bus_is_locked());
  1926. if (dsi.debug_write)
  1927. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  1928. channel,
  1929. data_type, data & 0xff, (data >> 8) & 0xff);
  1930. dsi_vc_config_l4(channel);
  1931. if (FLD_GET(dsi_read_reg(DSI_VC_CTRL(channel)), 16, 16)) {
  1932. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  1933. return -EINVAL;
  1934. }
  1935. data_id = data_type | dsi.vc[channel].vc_id << 6;
  1936. r = (data_id << 0) | (data << 8) | (ecc << 24);
  1937. dsi_write_reg(DSI_VC_SHORT_PACKET_HEADER(channel), r);
  1938. return 0;
  1939. }
  1940. int dsi_vc_send_null(int channel)
  1941. {
  1942. u8 nullpkg[] = {0, 0, 0, 0};
  1943. return dsi_vc_send_long(channel, DSI_DT_NULL_PACKET, nullpkg, 4, 0);
  1944. }
  1945. EXPORT_SYMBOL(dsi_vc_send_null);
  1946. int dsi_vc_dcs_write_nosync(int channel, u8 *data, int len)
  1947. {
  1948. int r;
  1949. BUG_ON(len == 0);
  1950. if (len == 1) {
  1951. r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_0,
  1952. data[0], 0);
  1953. } else if (len == 2) {
  1954. r = dsi_vc_send_short(channel, DSI_DT_DCS_SHORT_WRITE_1,
  1955. data[0] | (data[1] << 8), 0);
  1956. } else {
  1957. /* 0x39 = DCS Long Write */
  1958. r = dsi_vc_send_long(channel, DSI_DT_DCS_LONG_WRITE,
  1959. data, len, 0);
  1960. }
  1961. return r;
  1962. }
  1963. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  1964. int dsi_vc_dcs_write(int channel, u8 *data, int len)
  1965. {
  1966. int r;
  1967. r = dsi_vc_dcs_write_nosync(channel, data, len);
  1968. if (r)
  1969. goto err;
  1970. r = dsi_vc_send_bta_sync(channel);
  1971. if (r)
  1972. goto err;
  1973. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) { /* RX_FIFO_NOT_EMPTY */
  1974. DSSERR("rx fifo not empty after write, dumping data:\n");
  1975. dsi_vc_flush_receive_data(channel);
  1976. r = -EIO;
  1977. goto err;
  1978. }
  1979. return 0;
  1980. err:
  1981. DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
  1982. channel, data[0], len);
  1983. return r;
  1984. }
  1985. EXPORT_SYMBOL(dsi_vc_dcs_write);
  1986. int dsi_vc_dcs_write_0(int channel, u8 dcs_cmd)
  1987. {
  1988. return dsi_vc_dcs_write(channel, &dcs_cmd, 1);
  1989. }
  1990. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  1991. int dsi_vc_dcs_write_1(int channel, u8 dcs_cmd, u8 param)
  1992. {
  1993. u8 buf[2];
  1994. buf[0] = dcs_cmd;
  1995. buf[1] = param;
  1996. return dsi_vc_dcs_write(channel, buf, 2);
  1997. }
  1998. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  1999. int dsi_vc_dcs_read(int channel, u8 dcs_cmd, u8 *buf, int buflen)
  2000. {
  2001. u32 val;
  2002. u8 dt;
  2003. int r;
  2004. if (dsi.debug_read)
  2005. DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
  2006. r = dsi_vc_send_short(channel, DSI_DT_DCS_READ, dcs_cmd, 0);
  2007. if (r)
  2008. goto err;
  2009. r = dsi_vc_send_bta_sync(channel);
  2010. if (r)
  2011. goto err;
  2012. /* RX_FIFO_NOT_EMPTY */
  2013. if (REG_GET(DSI_VC_CTRL(channel), 20, 20) == 0) {
  2014. DSSERR("RX fifo empty when trying to read.\n");
  2015. r = -EIO;
  2016. goto err;
  2017. }
  2018. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  2019. if (dsi.debug_read)
  2020. DSSDBG("\theader: %08x\n", val);
  2021. dt = FLD_GET(val, 5, 0);
  2022. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2023. u16 err = FLD_GET(val, 23, 8);
  2024. dsi_show_rx_ack_with_err(err);
  2025. r = -EIO;
  2026. goto err;
  2027. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2028. u8 data = FLD_GET(val, 15, 8);
  2029. if (dsi.debug_read)
  2030. DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
  2031. if (buflen < 1) {
  2032. r = -EIO;
  2033. goto err;
  2034. }
  2035. buf[0] = data;
  2036. return 1;
  2037. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2038. u16 data = FLD_GET(val, 23, 8);
  2039. if (dsi.debug_read)
  2040. DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
  2041. if (buflen < 2) {
  2042. r = -EIO;
  2043. goto err;
  2044. }
  2045. buf[0] = data & 0xff;
  2046. buf[1] = (data >> 8) & 0xff;
  2047. return 2;
  2048. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  2049. int w;
  2050. int len = FLD_GET(val, 23, 8);
  2051. if (dsi.debug_read)
  2052. DSSDBG("\tDCS long response, len %d\n", len);
  2053. if (len > buflen) {
  2054. r = -EIO;
  2055. goto err;
  2056. }
  2057. /* two byte checksum ends the packet, not included in len */
  2058. for (w = 0; w < len + 2;) {
  2059. int b;
  2060. val = dsi_read_reg(DSI_VC_SHORT_PACKET_HEADER(channel));
  2061. if (dsi.debug_read)
  2062. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2063. (val >> 0) & 0xff,
  2064. (val >> 8) & 0xff,
  2065. (val >> 16) & 0xff,
  2066. (val >> 24) & 0xff);
  2067. for (b = 0; b < 4; ++b) {
  2068. if (w < len)
  2069. buf[w] = (val >> (b * 8)) & 0xff;
  2070. /* we discard the 2 byte checksum */
  2071. ++w;
  2072. }
  2073. }
  2074. return len;
  2075. } else {
  2076. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2077. r = -EIO;
  2078. goto err;
  2079. }
  2080. BUG();
  2081. err:
  2082. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
  2083. channel, dcs_cmd);
  2084. return r;
  2085. }
  2086. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2087. int dsi_vc_dcs_read_1(int channel, u8 dcs_cmd, u8 *data)
  2088. {
  2089. int r;
  2090. r = dsi_vc_dcs_read(channel, dcs_cmd, data, 1);
  2091. if (r < 0)
  2092. return r;
  2093. if (r != 1)
  2094. return -EIO;
  2095. return 0;
  2096. }
  2097. EXPORT_SYMBOL(dsi_vc_dcs_read_1);
  2098. int dsi_vc_dcs_read_2(int channel, u8 dcs_cmd, u8 *data1, u8 *data2)
  2099. {
  2100. u8 buf[2];
  2101. int r;
  2102. r = dsi_vc_dcs_read(channel, dcs_cmd, buf, 2);
  2103. if (r < 0)
  2104. return r;
  2105. if (r != 2)
  2106. return -EIO;
  2107. *data1 = buf[0];
  2108. *data2 = buf[1];
  2109. return 0;
  2110. }
  2111. EXPORT_SYMBOL(dsi_vc_dcs_read_2);
  2112. int dsi_vc_set_max_rx_packet_size(int channel, u16 len)
  2113. {
  2114. return dsi_vc_send_short(channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
  2115. len, 0);
  2116. }
  2117. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2118. static void dsi_set_lp_rx_timeout(unsigned ticks, bool x4, bool x16)
  2119. {
  2120. unsigned long fck;
  2121. unsigned long total_ticks;
  2122. u32 r;
  2123. BUG_ON(ticks > 0x1fff);
  2124. /* ticks in DSI_FCK */
  2125. fck = dsi_fclk_rate();
  2126. r = dsi_read_reg(DSI_TIMING2);
  2127. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  2128. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2129. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2130. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2131. dsi_write_reg(DSI_TIMING2, r);
  2132. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2133. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2134. total_ticks,
  2135. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2136. (total_ticks * 1000) / (fck / 1000 / 1000));
  2137. }
  2138. static void dsi_set_ta_timeout(unsigned ticks, bool x8, bool x16)
  2139. {
  2140. unsigned long fck;
  2141. unsigned long total_ticks;
  2142. u32 r;
  2143. BUG_ON(ticks > 0x1fff);
  2144. /* ticks in DSI_FCK */
  2145. fck = dsi_fclk_rate();
  2146. r = dsi_read_reg(DSI_TIMING1);
  2147. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  2148. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2149. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2150. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2151. dsi_write_reg(DSI_TIMING1, r);
  2152. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2153. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2154. total_ticks,
  2155. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2156. (total_ticks * 1000) / (fck / 1000 / 1000));
  2157. }
  2158. static void dsi_set_stop_state_counter(unsigned ticks, bool x4, bool x16)
  2159. {
  2160. unsigned long fck;
  2161. unsigned long total_ticks;
  2162. u32 r;
  2163. BUG_ON(ticks > 0x1fff);
  2164. /* ticks in DSI_FCK */
  2165. fck = dsi_fclk_rate();
  2166. r = dsi_read_reg(DSI_TIMING1);
  2167. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2168. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2169. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2170. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2171. dsi_write_reg(DSI_TIMING1, r);
  2172. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2173. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2174. total_ticks,
  2175. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2176. (total_ticks * 1000) / (fck / 1000 / 1000));
  2177. }
  2178. static void dsi_set_hs_tx_timeout(unsigned ticks, bool x4, bool x16)
  2179. {
  2180. unsigned long fck;
  2181. unsigned long total_ticks;
  2182. u32 r;
  2183. BUG_ON(ticks > 0x1fff);
  2184. /* ticks in TxByteClkHS */
  2185. fck = dsi_get_txbyteclkhs();
  2186. r = dsi_read_reg(DSI_TIMING2);
  2187. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  2188. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2189. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2190. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2191. dsi_write_reg(DSI_TIMING2, r);
  2192. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2193. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2194. total_ticks,
  2195. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2196. (total_ticks * 1000) / (fck / 1000 / 1000));
  2197. }
  2198. static int dsi_proto_config(struct omap_dss_device *dssdev)
  2199. {
  2200. u32 r;
  2201. int buswidth = 0;
  2202. dsi_config_tx_fifo(DSI_FIFO_SIZE_32,
  2203. DSI_FIFO_SIZE_32,
  2204. DSI_FIFO_SIZE_32,
  2205. DSI_FIFO_SIZE_32);
  2206. dsi_config_rx_fifo(DSI_FIFO_SIZE_32,
  2207. DSI_FIFO_SIZE_32,
  2208. DSI_FIFO_SIZE_32,
  2209. DSI_FIFO_SIZE_32);
  2210. /* XXX what values for the timeouts? */
  2211. dsi_set_stop_state_counter(0x1000, false, false);
  2212. dsi_set_ta_timeout(0x1fff, true, true);
  2213. dsi_set_lp_rx_timeout(0x1fff, true, true);
  2214. dsi_set_hs_tx_timeout(0x1fff, true, true);
  2215. switch (dssdev->ctrl.pixel_size) {
  2216. case 16:
  2217. buswidth = 0;
  2218. break;
  2219. case 18:
  2220. buswidth = 1;
  2221. break;
  2222. case 24:
  2223. buswidth = 2;
  2224. break;
  2225. default:
  2226. BUG();
  2227. }
  2228. r = dsi_read_reg(DSI_CTRL);
  2229. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2230. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2231. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2232. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2233. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2234. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2235. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
  2236. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2237. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2238. if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  2239. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2240. /* DCS_CMD_CODE, 1=start, 0=continue */
  2241. r = FLD_MOD(r, 0, 25, 25);
  2242. }
  2243. dsi_write_reg(DSI_CTRL, r);
  2244. dsi_vc_initial_config(0);
  2245. dsi_vc_initial_config(1);
  2246. dsi_vc_initial_config(2);
  2247. dsi_vc_initial_config(3);
  2248. return 0;
  2249. }
  2250. static void dsi_proto_timings(struct omap_dss_device *dssdev)
  2251. {
  2252. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  2253. unsigned tclk_pre, tclk_post;
  2254. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  2255. unsigned ths_trail, ths_exit;
  2256. unsigned ddr_clk_pre, ddr_clk_post;
  2257. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  2258. unsigned ths_eot;
  2259. u32 r;
  2260. r = dsi_read_reg(DSI_DSIPHY_CFG0);
  2261. ths_prepare = FLD_GET(r, 31, 24);
  2262. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  2263. ths_zero = ths_prepare_ths_zero - ths_prepare;
  2264. ths_trail = FLD_GET(r, 15, 8);
  2265. ths_exit = FLD_GET(r, 7, 0);
  2266. r = dsi_read_reg(DSI_DSIPHY_CFG1);
  2267. tlpx = FLD_GET(r, 22, 16) * 2;
  2268. tclk_trail = FLD_GET(r, 15, 8);
  2269. tclk_zero = FLD_GET(r, 7, 0);
  2270. r = dsi_read_reg(DSI_DSIPHY_CFG2);
  2271. tclk_prepare = FLD_GET(r, 7, 0);
  2272. /* min 8*UI */
  2273. tclk_pre = 20;
  2274. /* min 60ns + 52*UI */
  2275. tclk_post = ns2ddr(60) + 26;
  2276. /* ths_eot is 2 for 2 datalanes and 4 for 1 datalane */
  2277. if (dssdev->phy.dsi.data1_lane != 0 &&
  2278. dssdev->phy.dsi.data2_lane != 0)
  2279. ths_eot = 2;
  2280. else
  2281. ths_eot = 4;
  2282. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  2283. 4);
  2284. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  2285. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  2286. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  2287. r = dsi_read_reg(DSI_CLK_TIMING);
  2288. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  2289. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  2290. dsi_write_reg(DSI_CLK_TIMING, r);
  2291. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  2292. ddr_clk_pre,
  2293. ddr_clk_post);
  2294. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  2295. DIV_ROUND_UP(ths_prepare, 4) +
  2296. DIV_ROUND_UP(ths_zero + 3, 4);
  2297. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  2298. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  2299. FLD_VAL(exit_hs_mode_lat, 15, 0);
  2300. dsi_write_reg(DSI_VM_TIMING7, r);
  2301. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  2302. enter_hs_mode_lat, exit_hs_mode_lat);
  2303. }
  2304. #define DSI_DECL_VARS \
  2305. int __dsi_cb = 0; u32 __dsi_cv = 0;
  2306. #define DSI_FLUSH(ch) \
  2307. if (__dsi_cb > 0) { \
  2308. /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
  2309. dsi_write_reg(DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
  2310. __dsi_cb = __dsi_cv = 0; \
  2311. }
  2312. #define DSI_PUSH(ch, data) \
  2313. do { \
  2314. __dsi_cv |= (data) << (__dsi_cb * 8); \
  2315. /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
  2316. if (++__dsi_cb > 3) \
  2317. DSI_FLUSH(ch); \
  2318. } while (0)
  2319. static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
  2320. int x, int y, int w, int h)
  2321. {
  2322. /* Note: supports only 24bit colors in 32bit container */
  2323. int first = 1;
  2324. int fifo_stalls = 0;
  2325. int max_dsi_packet_size;
  2326. int max_data_per_packet;
  2327. int max_pixels_per_packet;
  2328. int pixels_left;
  2329. int bytespp = dssdev->ctrl.pixel_size / 8;
  2330. int scr_width;
  2331. u32 __iomem *data;
  2332. int start_offset;
  2333. int horiz_inc;
  2334. int current_x;
  2335. struct omap_overlay *ovl;
  2336. debug_irq = 0;
  2337. DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
  2338. x, y, w, h);
  2339. ovl = dssdev->manager->overlays[0];
  2340. if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
  2341. return -EINVAL;
  2342. if (dssdev->ctrl.pixel_size != 24)
  2343. return -EINVAL;
  2344. scr_width = ovl->info.screen_width;
  2345. data = ovl->info.vaddr;
  2346. start_offset = scr_width * y + x;
  2347. horiz_inc = scr_width - w;
  2348. current_x = x;
  2349. /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
  2350. * in fifo */
  2351. /* When using CPU, max long packet size is TX buffer size */
  2352. max_dsi_packet_size = dsi.vc[0].fifo_size * 32 * 4;
  2353. /* we seem to get better perf if we divide the tx fifo to half,
  2354. and while the other half is being sent, we fill the other half
  2355. max_dsi_packet_size /= 2; */
  2356. max_data_per_packet = max_dsi_packet_size - 4 - 1;
  2357. max_pixels_per_packet = max_data_per_packet / bytespp;
  2358. DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
  2359. pixels_left = w * h;
  2360. DSSDBG("total pixels %d\n", pixels_left);
  2361. data += start_offset;
  2362. while (pixels_left > 0) {
  2363. /* 0x2c = write_memory_start */
  2364. /* 0x3c = write_memory_continue */
  2365. u8 dcs_cmd = first ? 0x2c : 0x3c;
  2366. int pixels;
  2367. DSI_DECL_VARS;
  2368. first = 0;
  2369. #if 1
  2370. /* using fifo not empty */
  2371. /* TX_FIFO_NOT_EMPTY */
  2372. while (FLD_GET(dsi_read_reg(DSI_VC_CTRL(0)), 5, 5)) {
  2373. fifo_stalls++;
  2374. if (fifo_stalls > 0xfffff) {
  2375. DSSERR("fifo stalls overflow, pixels left %d\n",
  2376. pixels_left);
  2377. dsi_if_enable(0);
  2378. return -EIO;
  2379. }
  2380. udelay(1);
  2381. }
  2382. #elif 1
  2383. /* using fifo emptiness */
  2384. while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
  2385. max_dsi_packet_size) {
  2386. fifo_stalls++;
  2387. if (fifo_stalls > 0xfffff) {
  2388. DSSERR("fifo stalls overflow, pixels left %d\n",
  2389. pixels_left);
  2390. dsi_if_enable(0);
  2391. return -EIO;
  2392. }
  2393. }
  2394. #else
  2395. while ((REG_GET(DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 == 0) {
  2396. fifo_stalls++;
  2397. if (fifo_stalls > 0xfffff) {
  2398. DSSERR("fifo stalls overflow, pixels left %d\n",
  2399. pixels_left);
  2400. dsi_if_enable(0);
  2401. return -EIO;
  2402. }
  2403. }
  2404. #endif
  2405. pixels = min(max_pixels_per_packet, pixels_left);
  2406. pixels_left -= pixels;
  2407. dsi_vc_write_long_header(0, DSI_DT_DCS_LONG_WRITE,
  2408. 1 + pixels * bytespp, 0);
  2409. DSI_PUSH(0, dcs_cmd);
  2410. while (pixels-- > 0) {
  2411. u32 pix = __raw_readl(data++);
  2412. DSI_PUSH(0, (pix >> 16) & 0xff);
  2413. DSI_PUSH(0, (pix >> 8) & 0xff);
  2414. DSI_PUSH(0, (pix >> 0) & 0xff);
  2415. current_x++;
  2416. if (current_x == x+w) {
  2417. current_x = x;
  2418. data += horiz_inc;
  2419. }
  2420. }
  2421. DSI_FLUSH(0);
  2422. }
  2423. return 0;
  2424. }
  2425. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  2426. u16 x, u16 y, u16 w, u16 h)
  2427. {
  2428. unsigned bytespp;
  2429. unsigned bytespl;
  2430. unsigned bytespf;
  2431. unsigned total_len;
  2432. unsigned packet_payload;
  2433. unsigned packet_len;
  2434. u32 l;
  2435. int r;
  2436. const unsigned channel = dsi.update_channel;
  2437. /* line buffer is 1024 x 24bits */
  2438. /* XXX: for some reason using full buffer size causes considerable TX
  2439. * slowdown with update sizes that fill the whole buffer */
  2440. const unsigned line_buf_size = 1023 * 3;
  2441. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  2442. x, y, w, h);
  2443. dsi_vc_config_vp(channel);
  2444. bytespp = dssdev->ctrl.pixel_size / 8;
  2445. bytespl = w * bytespp;
  2446. bytespf = bytespl * h;
  2447. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  2448. * number of lines in a packet. See errata about VP_CLK_RATIO */
  2449. if (bytespf < line_buf_size)
  2450. packet_payload = bytespf;
  2451. else
  2452. packet_payload = (line_buf_size) / bytespl * bytespl;
  2453. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  2454. total_len = (bytespf / packet_payload) * packet_len;
  2455. if (bytespf % packet_payload)
  2456. total_len += (bytespf % packet_payload) + 1;
  2457. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  2458. dsi_write_reg(DSI_VC_TE(channel), l);
  2459. dsi_vc_write_long_header(channel, DSI_DT_DCS_LONG_WRITE, packet_len, 0);
  2460. if (dsi.te_enabled)
  2461. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  2462. else
  2463. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  2464. dsi_write_reg(DSI_VC_TE(channel), l);
  2465. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  2466. * because DSS interrupts are not capable of waking up the CPU and the
  2467. * framedone interrupt could be delayed for quite a long time. I think
  2468. * the same goes for any DSS interrupts, but for some reason I have not
  2469. * seen the problem anywhere else than here.
  2470. */
  2471. dispc_disable_sidle();
  2472. dsi_perf_mark_start();
  2473. r = queue_delayed_work(dsi.workqueue, &dsi.framedone_timeout_work,
  2474. msecs_to_jiffies(250));
  2475. BUG_ON(r == 0);
  2476. dss_start_update(dssdev);
  2477. if (dsi.te_enabled) {
  2478. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  2479. * for TE is longer than the timer allows */
  2480. REG_FLD_MOD(DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  2481. dsi_vc_send_bta(channel);
  2482. #ifdef DSI_CATCH_MISSING_TE
  2483. mod_timer(&dsi.te_timer, jiffies + msecs_to_jiffies(250));
  2484. #endif
  2485. }
  2486. }
  2487. #ifdef DSI_CATCH_MISSING_TE
  2488. static void dsi_te_timeout(unsigned long arg)
  2489. {
  2490. DSSERR("TE not received for 250ms!\n");
  2491. }
  2492. #endif
  2493. static void dsi_framedone_bta_callback(void *data, u32 mask);
  2494. static void dsi_handle_framedone(int error)
  2495. {
  2496. const int channel = dsi.update_channel;
  2497. dsi_unregister_isr_vc(channel, dsi_framedone_bta_callback,
  2498. NULL, DSI_VC_IRQ_BTA);
  2499. cancel_delayed_work(&dsi.framedone_timeout_work);
  2500. /* SIDLEMODE back to smart-idle */
  2501. dispc_enable_sidle();
  2502. if (dsi.te_enabled) {
  2503. /* enable LP_RX_TO again after the TE */
  2504. REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2505. }
  2506. /* RX_FIFO_NOT_EMPTY */
  2507. if (REG_GET(DSI_VC_CTRL(channel), 20, 20)) {
  2508. DSSERR("Received error during frame transfer:\n");
  2509. dsi_vc_flush_receive_data(channel);
  2510. if (!error)
  2511. error = -EIO;
  2512. }
  2513. dsi.framedone_callback(error, dsi.framedone_data);
  2514. if (!error)
  2515. dsi_perf_show("DISPC");
  2516. }
  2517. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  2518. {
  2519. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  2520. * 250ms which would conflict with this timeout work. What should be
  2521. * done is first cancel the transfer on the HW, and then cancel the
  2522. * possibly scheduled framedone work. However, cancelling the transfer
  2523. * on the HW is buggy, and would probably require resetting the whole
  2524. * DSI */
  2525. DSSERR("Framedone not received for 250ms!\n");
  2526. dsi_handle_framedone(-ETIMEDOUT);
  2527. }
  2528. static void dsi_framedone_bta_callback(void *data, u32 mask)
  2529. {
  2530. dsi_handle_framedone(0);
  2531. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  2532. dispc_fake_vsync_irq();
  2533. #endif
  2534. }
  2535. static void dsi_framedone_irq_callback(void *data, u32 mask)
  2536. {
  2537. const int channel = dsi.update_channel;
  2538. int r;
  2539. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  2540. * turns itself off. However, DSI still has the pixels in its buffers,
  2541. * and is sending the data.
  2542. */
  2543. if (dsi.te_enabled) {
  2544. /* enable LP_RX_TO again after the TE */
  2545. REG_FLD_MOD(DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  2546. }
  2547. /* Send BTA after the frame. We need this for the TE to work, as TE
  2548. * trigger is only sent for BTAs without preceding packet. Thus we need
  2549. * to BTA after the pixel packets so that next BTA will cause TE
  2550. * trigger.
  2551. *
  2552. * This is not needed when TE is not in use, but we do it anyway to
  2553. * make sure that the transfer has been completed. It would be more
  2554. * optimal, but more complex, to wait only just before starting next
  2555. * transfer.
  2556. *
  2557. * Also, as there's no interrupt telling when the transfer has been
  2558. * done and the channel could be reconfigured, the only way is to
  2559. * busyloop until TE_SIZE is zero. With BTA we can do this
  2560. * asynchronously.
  2561. * */
  2562. r = dsi_register_isr_vc(channel, dsi_framedone_bta_callback,
  2563. NULL, DSI_VC_IRQ_BTA);
  2564. if (r) {
  2565. DSSERR("Failed to register BTA ISR\n");
  2566. dsi_handle_framedone(-EIO);
  2567. return;
  2568. }
  2569. r = dsi_vc_send_bta(channel);
  2570. if (r) {
  2571. DSSERR("BTA after framedone failed\n");
  2572. dsi_unregister_isr_vc(channel, dsi_framedone_bta_callback,
  2573. NULL, DSI_VC_IRQ_BTA);
  2574. dsi_handle_framedone(-EIO);
  2575. }
  2576. }
  2577. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  2578. u16 *x, u16 *y, u16 *w, u16 *h,
  2579. bool enlarge_update_area)
  2580. {
  2581. u16 dw, dh;
  2582. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  2583. if (*x > dw || *y > dh)
  2584. return -EINVAL;
  2585. if (*x + *w > dw)
  2586. return -EINVAL;
  2587. if (*y + *h > dh)
  2588. return -EINVAL;
  2589. if (*w == 1)
  2590. return -EINVAL;
  2591. if (*w == 0 || *h == 0)
  2592. return -EINVAL;
  2593. dsi_perf_mark_setup();
  2594. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  2595. dss_setup_partial_planes(dssdev, x, y, w, h,
  2596. enlarge_update_area);
  2597. dispc_set_lcd_size(dssdev->manager->id, *w, *h);
  2598. }
  2599. return 0;
  2600. }
  2601. EXPORT_SYMBOL(omap_dsi_prepare_update);
  2602. int omap_dsi_update(struct omap_dss_device *dssdev,
  2603. int channel,
  2604. u16 x, u16 y, u16 w, u16 h,
  2605. void (*callback)(int, void *), void *data)
  2606. {
  2607. dsi.update_channel = channel;
  2608. /* OMAP DSS cannot send updates of odd widths.
  2609. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  2610. * here to make sure we catch erroneous updates. Otherwise we'll only
  2611. * see rather obscure HW error happening, as DSS halts. */
  2612. BUG_ON(x % 2 == 1);
  2613. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  2614. dsi.framedone_callback = callback;
  2615. dsi.framedone_data = data;
  2616. dsi.update_region.x = x;
  2617. dsi.update_region.y = y;
  2618. dsi.update_region.w = w;
  2619. dsi.update_region.h = h;
  2620. dsi.update_region.device = dssdev;
  2621. dsi_update_screen_dispc(dssdev, x, y, w, h);
  2622. } else {
  2623. int r;
  2624. r = dsi_update_screen_l4(dssdev, x, y, w, h);
  2625. if (r)
  2626. return r;
  2627. dsi_perf_show("L4");
  2628. callback(0, data);
  2629. }
  2630. return 0;
  2631. }
  2632. EXPORT_SYMBOL(omap_dsi_update);
  2633. /* Display funcs */
  2634. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  2635. {
  2636. int r;
  2637. r = omap_dispc_register_isr(dsi_framedone_irq_callback, NULL,
  2638. DISPC_IRQ_FRAMEDONE);
  2639. if (r) {
  2640. DSSERR("can't get FRAMEDONE irq\n");
  2641. return r;
  2642. }
  2643. dispc_set_lcd_display_type(dssdev->manager->id,
  2644. OMAP_DSS_LCD_DISPLAY_TFT);
  2645. dispc_set_parallel_interface_mode(dssdev->manager->id,
  2646. OMAP_DSS_PARALLELMODE_DSI);
  2647. dispc_enable_fifohandcheck(dssdev->manager->id, 1);
  2648. dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
  2649. {
  2650. struct omap_video_timings timings = {
  2651. .hsw = 1,
  2652. .hfp = 1,
  2653. .hbp = 1,
  2654. .vsw = 1,
  2655. .vfp = 0,
  2656. .vbp = 0,
  2657. };
  2658. dispc_set_lcd_timings(dssdev->manager->id, &timings);
  2659. }
  2660. return 0;
  2661. }
  2662. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  2663. {
  2664. omap_dispc_unregister_isr(dsi_framedone_irq_callback, NULL,
  2665. DISPC_IRQ_FRAMEDONE);
  2666. }
  2667. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  2668. {
  2669. struct dsi_clock_info cinfo;
  2670. int r;
  2671. /* we always use DSS_CLK_SYSCK as input clock */
  2672. cinfo.use_sys_clk = true;
  2673. cinfo.regn = dssdev->phy.dsi.div.regn;
  2674. cinfo.regm = dssdev->phy.dsi.div.regm;
  2675. cinfo.regm_dispc = dssdev->phy.dsi.div.regm_dispc;
  2676. cinfo.regm_dsi = dssdev->phy.dsi.div.regm_dsi;
  2677. r = dsi_calc_clock_rates(dssdev, &cinfo);
  2678. if (r) {
  2679. DSSERR("Failed to calc dsi clocks\n");
  2680. return r;
  2681. }
  2682. r = dsi_pll_set_clock_div(&cinfo);
  2683. if (r) {
  2684. DSSERR("Failed to set dsi clocks\n");
  2685. return r;
  2686. }
  2687. return 0;
  2688. }
  2689. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  2690. {
  2691. struct dispc_clock_info dispc_cinfo;
  2692. int r;
  2693. unsigned long long fck;
  2694. fck = dsi_get_pll_hsdiv_dispc_rate();
  2695. dispc_cinfo.lck_div = dssdev->phy.dsi.div.lck_div;
  2696. dispc_cinfo.pck_div = dssdev->phy.dsi.div.pck_div;
  2697. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  2698. if (r) {
  2699. DSSERR("Failed to calc dispc clocks\n");
  2700. return r;
  2701. }
  2702. r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  2703. if (r) {
  2704. DSSERR("Failed to set dispc clocks\n");
  2705. return r;
  2706. }
  2707. return 0;
  2708. }
  2709. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  2710. {
  2711. int r;
  2712. /* The SCPClk is required for both PLL and CIO registers on OMAP4 */
  2713. /* CIO_CLK_ICG, enable L3 clk to CIO */
  2714. REG_FLD_MOD(DSI_CLK_CTRL, 1, 14, 14);
  2715. _dsi_print_reset_status();
  2716. r = dsi_pll_init(dssdev, true, true);
  2717. if (r)
  2718. goto err0;
  2719. r = dsi_configure_dsi_clocks(dssdev);
  2720. if (r)
  2721. goto err1;
  2722. dss_select_dispc_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC);
  2723. dss_select_dsi_clk_source(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI);
  2724. dss_select_lcd_clk_source(dssdev->manager->id,
  2725. DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC);
  2726. DSSDBG("PLL OK\n");
  2727. r = dsi_configure_dispc_clocks(dssdev);
  2728. if (r)
  2729. goto err2;
  2730. r = dsi_complexio_init(dssdev);
  2731. if (r)
  2732. goto err2;
  2733. _dsi_print_reset_status();
  2734. dsi_proto_timings(dssdev);
  2735. dsi_set_lp_clk_divisor(dssdev);
  2736. if (1)
  2737. _dsi_print_reset_status();
  2738. r = dsi_proto_config(dssdev);
  2739. if (r)
  2740. goto err3;
  2741. /* enable interface */
  2742. dsi_vc_enable(0, 1);
  2743. dsi_vc_enable(1, 1);
  2744. dsi_vc_enable(2, 1);
  2745. dsi_vc_enable(3, 1);
  2746. dsi_if_enable(1);
  2747. dsi_force_tx_stop_mode_io();
  2748. return 0;
  2749. err3:
  2750. dsi_complexio_uninit();
  2751. err2:
  2752. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  2753. dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
  2754. err1:
  2755. dsi_pll_uninit();
  2756. err0:
  2757. return r;
  2758. }
  2759. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev)
  2760. {
  2761. /* disable interface */
  2762. dsi_if_enable(0);
  2763. dsi_vc_enable(0, 0);
  2764. dsi_vc_enable(1, 0);
  2765. dsi_vc_enable(2, 0);
  2766. dsi_vc_enable(3, 0);
  2767. dss_select_dispc_clk_source(DSS_CLK_SRC_FCK);
  2768. dss_select_dsi_clk_source(DSS_CLK_SRC_FCK);
  2769. dsi_complexio_uninit();
  2770. dsi_pll_uninit();
  2771. }
  2772. static int dsi_core_init(void)
  2773. {
  2774. /* Autoidle */
  2775. REG_FLD_MOD(DSI_SYSCONFIG, 1, 0, 0);
  2776. /* ENWAKEUP */
  2777. REG_FLD_MOD(DSI_SYSCONFIG, 1, 2, 2);
  2778. /* SIDLEMODE smart-idle */
  2779. REG_FLD_MOD(DSI_SYSCONFIG, 2, 4, 3);
  2780. _dsi_initialize_irq();
  2781. return 0;
  2782. }
  2783. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  2784. {
  2785. int r = 0;
  2786. DSSDBG("dsi_display_enable\n");
  2787. WARN_ON(!dsi_bus_is_locked());
  2788. mutex_lock(&dsi.lock);
  2789. r = omap_dss_start_device(dssdev);
  2790. if (r) {
  2791. DSSERR("failed to start device\n");
  2792. goto err0;
  2793. }
  2794. enable_clocks(1);
  2795. dsi_enable_pll_clock(1);
  2796. r = _dsi_reset();
  2797. if (r)
  2798. goto err1;
  2799. dsi_core_init();
  2800. r = dsi_display_init_dispc(dssdev);
  2801. if (r)
  2802. goto err1;
  2803. r = dsi_display_init_dsi(dssdev);
  2804. if (r)
  2805. goto err2;
  2806. mutex_unlock(&dsi.lock);
  2807. return 0;
  2808. err2:
  2809. dsi_display_uninit_dispc(dssdev);
  2810. err1:
  2811. enable_clocks(0);
  2812. dsi_enable_pll_clock(0);
  2813. omap_dss_stop_device(dssdev);
  2814. err0:
  2815. mutex_unlock(&dsi.lock);
  2816. DSSDBG("dsi_display_enable FAILED\n");
  2817. return r;
  2818. }
  2819. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  2820. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev)
  2821. {
  2822. DSSDBG("dsi_display_disable\n");
  2823. WARN_ON(!dsi_bus_is_locked());
  2824. mutex_lock(&dsi.lock);
  2825. dsi_display_uninit_dispc(dssdev);
  2826. dsi_display_uninit_dsi(dssdev);
  2827. enable_clocks(0);
  2828. dsi_enable_pll_clock(0);
  2829. omap_dss_stop_device(dssdev);
  2830. mutex_unlock(&dsi.lock);
  2831. }
  2832. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  2833. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  2834. {
  2835. dsi.te_enabled = enable;
  2836. return 0;
  2837. }
  2838. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  2839. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  2840. u32 fifo_size, enum omap_burst_size *burst_size,
  2841. u32 *fifo_low, u32 *fifo_high)
  2842. {
  2843. unsigned burst_size_bytes;
  2844. *burst_size = OMAP_DSS_BURST_16x32;
  2845. burst_size_bytes = 16 * 32 / 8;
  2846. *fifo_high = fifo_size - burst_size_bytes;
  2847. *fifo_low = fifo_size - burst_size_bytes * 2;
  2848. }
  2849. int dsi_init_display(struct omap_dss_device *dssdev)
  2850. {
  2851. DSSDBG("DSI init\n");
  2852. /* XXX these should be figured out dynamically */
  2853. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  2854. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  2855. if (dsi.vdds_dsi_reg == NULL) {
  2856. struct regulator *vdds_dsi;
  2857. vdds_dsi = regulator_get(&dsi.pdev->dev, "vdds_dsi");
  2858. if (IS_ERR(vdds_dsi)) {
  2859. DSSERR("can't get VDDS_DSI regulator\n");
  2860. return PTR_ERR(vdds_dsi);
  2861. }
  2862. dsi.vdds_dsi_reg = vdds_dsi;
  2863. }
  2864. return 0;
  2865. }
  2866. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  2867. {
  2868. int i;
  2869. for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
  2870. if (!dsi.vc[i].dssdev) {
  2871. dsi.vc[i].dssdev = dssdev;
  2872. *channel = i;
  2873. return 0;
  2874. }
  2875. }
  2876. DSSERR("cannot get VC for display %s", dssdev->name);
  2877. return -ENOSPC;
  2878. }
  2879. EXPORT_SYMBOL(omap_dsi_request_vc);
  2880. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  2881. {
  2882. if (vc_id < 0 || vc_id > 3) {
  2883. DSSERR("VC ID out of range\n");
  2884. return -EINVAL;
  2885. }
  2886. if (channel < 0 || channel > 3) {
  2887. DSSERR("Virtual Channel out of range\n");
  2888. return -EINVAL;
  2889. }
  2890. if (dsi.vc[channel].dssdev != dssdev) {
  2891. DSSERR("Virtual Channel not allocated to display %s\n",
  2892. dssdev->name);
  2893. return -EINVAL;
  2894. }
  2895. dsi.vc[channel].vc_id = vc_id;
  2896. return 0;
  2897. }
  2898. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  2899. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  2900. {
  2901. if ((channel >= 0 && channel <= 3) &&
  2902. dsi.vc[channel].dssdev == dssdev) {
  2903. dsi.vc[channel].dssdev = NULL;
  2904. dsi.vc[channel].vc_id = 0;
  2905. }
  2906. }
  2907. EXPORT_SYMBOL(omap_dsi_release_vc);
  2908. void dsi_wait_pll_hsdiv_dispc_active(void)
  2909. {
  2910. if (wait_for_bit_change(DSI_PLL_STATUS, 7, 1) != 1)
  2911. DSSERR("%s (%s) not active\n",
  2912. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  2913. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  2914. }
  2915. void dsi_wait_pll_hsdiv_dsi_active(void)
  2916. {
  2917. if (wait_for_bit_change(DSI_PLL_STATUS, 8, 1) != 1)
  2918. DSSERR("%s (%s) not active\n",
  2919. dss_get_generic_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  2920. dss_feat_get_clk_source_name(DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  2921. }
  2922. static void dsi_calc_clock_param_ranges(void)
  2923. {
  2924. dsi.regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  2925. dsi.regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  2926. dsi.regm_dispc_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  2927. dsi.regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  2928. dsi.fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  2929. dsi.fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  2930. dsi.lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  2931. }
  2932. static int dsi_init(struct platform_device *pdev)
  2933. {
  2934. u32 rev;
  2935. int r, i;
  2936. struct resource *dsi_mem;
  2937. spin_lock_init(&dsi.irq_lock);
  2938. spin_lock_init(&dsi.errors_lock);
  2939. dsi.errors = 0;
  2940. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  2941. spin_lock_init(&dsi.irq_stats_lock);
  2942. dsi.irq_stats.last_reset = jiffies;
  2943. #endif
  2944. mutex_init(&dsi.lock);
  2945. sema_init(&dsi.bus_lock, 1);
  2946. dsi.workqueue = create_singlethread_workqueue("dsi");
  2947. if (dsi.workqueue == NULL)
  2948. return -ENOMEM;
  2949. INIT_DELAYED_WORK_DEFERRABLE(&dsi.framedone_timeout_work,
  2950. dsi_framedone_timeout_work_callback);
  2951. #ifdef DSI_CATCH_MISSING_TE
  2952. init_timer(&dsi.te_timer);
  2953. dsi.te_timer.function = dsi_te_timeout;
  2954. dsi.te_timer.data = 0;
  2955. #endif
  2956. dsi_mem = platform_get_resource(dsi.pdev, IORESOURCE_MEM, 0);
  2957. if (!dsi_mem) {
  2958. DSSERR("can't get IORESOURCE_MEM DSI\n");
  2959. r = -EINVAL;
  2960. goto err1;
  2961. }
  2962. dsi.base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  2963. if (!dsi.base) {
  2964. DSSERR("can't ioremap DSI\n");
  2965. r = -ENOMEM;
  2966. goto err1;
  2967. }
  2968. dsi.irq = platform_get_irq(dsi.pdev, 0);
  2969. if (dsi.irq < 0) {
  2970. DSSERR("platform_get_irq failed\n");
  2971. r = -ENODEV;
  2972. goto err2;
  2973. }
  2974. r = request_irq(dsi.irq, omap_dsi_irq_handler, IRQF_SHARED,
  2975. "OMAP DSI1", dsi.pdev);
  2976. if (r < 0) {
  2977. DSSERR("request_irq failed\n");
  2978. goto err2;
  2979. }
  2980. /* DSI VCs initialization */
  2981. for (i = 0; i < ARRAY_SIZE(dsi.vc); i++) {
  2982. dsi.vc[i].mode = DSI_VC_MODE_L4;
  2983. dsi.vc[i].dssdev = NULL;
  2984. dsi.vc[i].vc_id = 0;
  2985. }
  2986. dsi_calc_clock_param_ranges();
  2987. enable_clocks(1);
  2988. rev = dsi_read_reg(DSI_REVISION);
  2989. dev_dbg(&pdev->dev, "OMAP DSI rev %d.%d\n",
  2990. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  2991. enable_clocks(0);
  2992. return 0;
  2993. err2:
  2994. iounmap(dsi.base);
  2995. err1:
  2996. destroy_workqueue(dsi.workqueue);
  2997. return r;
  2998. }
  2999. static void dsi_exit(void)
  3000. {
  3001. if (dsi.vdds_dsi_reg != NULL) {
  3002. regulator_put(dsi.vdds_dsi_reg);
  3003. dsi.vdds_dsi_reg = NULL;
  3004. }
  3005. free_irq(dsi.irq, dsi.pdev);
  3006. iounmap(dsi.base);
  3007. destroy_workqueue(dsi.workqueue);
  3008. DSSDBG("omap_dsi_exit\n");
  3009. }
  3010. /* DSI1 HW IP initialisation */
  3011. static int omap_dsi1hw_probe(struct platform_device *pdev)
  3012. {
  3013. int r;
  3014. dsi.pdev = pdev;
  3015. r = dsi_init(pdev);
  3016. if (r) {
  3017. DSSERR("Failed to initialize DSI\n");
  3018. goto err_dsi;
  3019. }
  3020. err_dsi:
  3021. return r;
  3022. }
  3023. static int omap_dsi1hw_remove(struct platform_device *pdev)
  3024. {
  3025. dsi_exit();
  3026. return 0;
  3027. }
  3028. static struct platform_driver omap_dsi1hw_driver = {
  3029. .probe = omap_dsi1hw_probe,
  3030. .remove = omap_dsi1hw_remove,
  3031. .driver = {
  3032. .name = "omapdss_dsi1",
  3033. .owner = THIS_MODULE,
  3034. },
  3035. };
  3036. int dsi_init_platform_driver(void)
  3037. {
  3038. return platform_driver_register(&omap_dsi1hw_driver);
  3039. }
  3040. void dsi_uninit_platform_driver(void)
  3041. {
  3042. return platform_driver_unregister(&omap_dsi1hw_driver);
  3043. }