dsi.c 83 KB

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