dsi.c 75 KB

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