dsi.c 75 KB

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