dsi.c 79 KB

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