dsi.c 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507
  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 <linux/sched.h>
  35. #include <linux/slab.h>
  36. #include <linux/debugfs.h>
  37. #include <linux/pm_runtime.h>
  38. #include <video/omapdss.h>
  39. #include <plat/clock.h>
  40. #include "dss.h"
  41. #include "dss_features.h"
  42. /*#define VERBOSE_IRQ*/
  43. #define DSI_CATCH_MISSING_TE
  44. struct dsi_reg { u16 idx; };
  45. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  46. #define DSI_SZ_REGS SZ_1K
  47. /* DSI Protocol Engine */
  48. #define DSI_REVISION DSI_REG(0x0000)
  49. #define DSI_SYSCONFIG DSI_REG(0x0010)
  50. #define DSI_SYSSTATUS DSI_REG(0x0014)
  51. #define DSI_IRQSTATUS DSI_REG(0x0018)
  52. #define DSI_IRQENABLE DSI_REG(0x001C)
  53. #define DSI_CTRL DSI_REG(0x0040)
  54. #define DSI_GNQ DSI_REG(0x0044)
  55. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  56. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  57. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  58. #define DSI_CLK_CTRL DSI_REG(0x0054)
  59. #define DSI_TIMING1 DSI_REG(0x0058)
  60. #define DSI_TIMING2 DSI_REG(0x005C)
  61. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  62. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  63. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  64. #define DSI_CLK_TIMING DSI_REG(0x006C)
  65. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  66. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  67. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  68. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  69. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  70. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  71. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  72. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  73. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  74. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  75. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  76. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  77. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  78. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  79. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  80. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  81. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  82. /* DSIPHY_SCP */
  83. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  84. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  85. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  86. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  87. #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
  88. /* DSI_PLL_CTRL_SCP */
  89. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  90. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  91. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  92. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  93. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  94. #define REG_GET(dsidev, idx, start, end) \
  95. FLD_GET(dsi_read_reg(dsidev, idx), start, end)
  96. #define REG_FLD_MOD(dsidev, idx, val, start, end) \
  97. dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
  98. /* Global interrupts */
  99. #define DSI_IRQ_VC0 (1 << 0)
  100. #define DSI_IRQ_VC1 (1 << 1)
  101. #define DSI_IRQ_VC2 (1 << 2)
  102. #define DSI_IRQ_VC3 (1 << 3)
  103. #define DSI_IRQ_WAKEUP (1 << 4)
  104. #define DSI_IRQ_RESYNC (1 << 5)
  105. #define DSI_IRQ_PLL_LOCK (1 << 7)
  106. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  107. #define DSI_IRQ_PLL_RECALL (1 << 9)
  108. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  109. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  110. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  111. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  112. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  113. #define DSI_IRQ_SYNC_LOST (1 << 18)
  114. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  115. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  116. #define DSI_IRQ_ERROR_MASK \
  117. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  118. DSI_IRQ_TA_TIMEOUT)
  119. #define DSI_IRQ_CHANNEL_MASK 0xf
  120. /* Virtual channel interrupts */
  121. #define DSI_VC_IRQ_CS (1 << 0)
  122. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  123. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  124. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  125. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  126. #define DSI_VC_IRQ_BTA (1 << 5)
  127. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  128. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  129. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  130. #define DSI_VC_IRQ_ERROR_MASK \
  131. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  132. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  133. DSI_VC_IRQ_FIFO_TX_UDF)
  134. /* ComplexIO interrupts */
  135. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  136. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  137. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  138. #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
  139. #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
  140. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  141. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  142. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  143. #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
  144. #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
  145. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  146. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  147. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  148. #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
  149. #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
  150. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  151. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  152. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  153. #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
  154. #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
  155. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  156. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  157. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  158. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  159. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  160. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  161. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
  162. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
  163. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
  164. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
  165. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  166. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  167. #define DSI_CIO_IRQ_ERROR_MASK \
  168. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  169. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
  170. DSI_CIO_IRQ_ERRSYNCESC5 | \
  171. DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  172. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
  173. DSI_CIO_IRQ_ERRESC5 | \
  174. DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
  175. DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
  176. DSI_CIO_IRQ_ERRCONTROL5 | \
  177. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  178. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  179. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
  180. DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
  181. DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
  182. #define DSI_DT_DCS_SHORT_WRITE_0 0x05
  183. #define DSI_DT_DCS_SHORT_WRITE_1 0x15
  184. #define DSI_DT_DCS_READ 0x06
  185. #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
  186. #define DSI_DT_NULL_PACKET 0x09
  187. #define DSI_DT_DCS_LONG_WRITE 0x39
  188. #define DSI_DT_RX_ACK_WITH_ERR 0x02
  189. #define DSI_DT_RX_DCS_LONG_READ 0x1c
  190. #define DSI_DT_RX_SHORT_READ_1 0x21
  191. #define DSI_DT_RX_SHORT_READ_2 0x22
  192. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  193. #define DSI_MAX_NR_ISRS 2
  194. struct dsi_isr_data {
  195. omap_dsi_isr_t isr;
  196. void *arg;
  197. u32 mask;
  198. };
  199. enum fifo_size {
  200. DSI_FIFO_SIZE_0 = 0,
  201. DSI_FIFO_SIZE_32 = 1,
  202. DSI_FIFO_SIZE_64 = 2,
  203. DSI_FIFO_SIZE_96 = 3,
  204. DSI_FIFO_SIZE_128 = 4,
  205. };
  206. enum dsi_vc_mode {
  207. DSI_VC_MODE_L4 = 0,
  208. DSI_VC_MODE_VP,
  209. };
  210. enum dsi_lane {
  211. DSI_CLK_P = 1 << 0,
  212. DSI_CLK_N = 1 << 1,
  213. DSI_DATA1_P = 1 << 2,
  214. DSI_DATA1_N = 1 << 3,
  215. DSI_DATA2_P = 1 << 4,
  216. DSI_DATA2_N = 1 << 5,
  217. DSI_DATA3_P = 1 << 6,
  218. DSI_DATA3_N = 1 << 7,
  219. DSI_DATA4_P = 1 << 8,
  220. DSI_DATA4_N = 1 << 9,
  221. };
  222. struct dsi_update_region {
  223. u16 x, y, w, h;
  224. struct omap_dss_device *device;
  225. };
  226. struct dsi_irq_stats {
  227. unsigned long last_reset;
  228. unsigned irq_count;
  229. unsigned dsi_irqs[32];
  230. unsigned vc_irqs[4][32];
  231. unsigned cio_irqs[32];
  232. };
  233. struct dsi_isr_tables {
  234. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  235. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  236. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  237. };
  238. struct dsi_data {
  239. struct platform_device *pdev;
  240. void __iomem *base;
  241. int irq;
  242. struct clk *dss_clk;
  243. struct clk *sys_clk;
  244. int (*enable_pads)(int dsi_id, unsigned lane_mask);
  245. void (*disable_pads)(int dsi_id, unsigned lane_mask);
  246. struct dsi_clock_info current_cinfo;
  247. bool vdds_dsi_enabled;
  248. struct regulator *vdds_dsi_reg;
  249. struct {
  250. enum dsi_vc_mode mode;
  251. struct omap_dss_device *dssdev;
  252. enum fifo_size fifo_size;
  253. int vc_id;
  254. } vc[4];
  255. struct mutex lock;
  256. struct semaphore bus_lock;
  257. unsigned pll_locked;
  258. spinlock_t irq_lock;
  259. struct dsi_isr_tables isr_tables;
  260. /* space for a copy used by the interrupt handler */
  261. struct dsi_isr_tables isr_tables_copy;
  262. int update_channel;
  263. struct dsi_update_region update_region;
  264. bool te_enabled;
  265. bool ulps_enabled;
  266. void (*framedone_callback)(int, void *);
  267. void *framedone_data;
  268. struct delayed_work framedone_timeout_work;
  269. #ifdef DSI_CATCH_MISSING_TE
  270. struct timer_list te_timer;
  271. #endif
  272. unsigned long cache_req_pck;
  273. unsigned long cache_clk_freq;
  274. struct dsi_clock_info cache_cinfo;
  275. u32 errors;
  276. spinlock_t errors_lock;
  277. #ifdef DEBUG
  278. ktime_t perf_setup_time;
  279. ktime_t perf_start_time;
  280. #endif
  281. int debug_read;
  282. int debug_write;
  283. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  284. spinlock_t irq_stats_lock;
  285. struct dsi_irq_stats irq_stats;
  286. #endif
  287. /* DSI PLL Parameter Ranges */
  288. unsigned long regm_max, regn_max;
  289. unsigned long regm_dispc_max, regm_dsi_max;
  290. unsigned long fint_min, fint_max;
  291. unsigned long lpdiv_max;
  292. int num_data_lanes;
  293. unsigned scp_clk_refcount;
  294. };
  295. struct dsi_packet_sent_handler_data {
  296. struct platform_device *dsidev;
  297. struct completion *completion;
  298. };
  299. static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
  300. #ifdef DEBUG
  301. static unsigned int dsi_perf;
  302. module_param_named(dsi_perf, dsi_perf, bool, 0644);
  303. #endif
  304. static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
  305. {
  306. return dev_get_drvdata(&dsidev->dev);
  307. }
  308. static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
  309. {
  310. return dsi_pdev_map[dssdev->phy.dsi.module];
  311. }
  312. struct platform_device *dsi_get_dsidev_from_id(int module)
  313. {
  314. return dsi_pdev_map[module];
  315. }
  316. static inline int dsi_get_dsidev_id(struct platform_device *dsidev)
  317. {
  318. return dsidev->id;
  319. }
  320. static inline void dsi_write_reg(struct platform_device *dsidev,
  321. const struct dsi_reg idx, u32 val)
  322. {
  323. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  324. __raw_writel(val, dsi->base + idx.idx);
  325. }
  326. static inline u32 dsi_read_reg(struct platform_device *dsidev,
  327. const struct dsi_reg idx)
  328. {
  329. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  330. return __raw_readl(dsi->base + idx.idx);
  331. }
  332. void dsi_bus_lock(struct omap_dss_device *dssdev)
  333. {
  334. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  335. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  336. down(&dsi->bus_lock);
  337. }
  338. EXPORT_SYMBOL(dsi_bus_lock);
  339. void dsi_bus_unlock(struct omap_dss_device *dssdev)
  340. {
  341. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  342. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  343. up(&dsi->bus_lock);
  344. }
  345. EXPORT_SYMBOL(dsi_bus_unlock);
  346. static bool dsi_bus_is_locked(struct platform_device *dsidev)
  347. {
  348. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  349. return dsi->bus_lock.count == 0;
  350. }
  351. static void dsi_completion_handler(void *data, u32 mask)
  352. {
  353. complete((struct completion *)data);
  354. }
  355. static inline int wait_for_bit_change(struct platform_device *dsidev,
  356. const struct dsi_reg idx, int bitnum, int value)
  357. {
  358. int t = 100000;
  359. while (REG_GET(dsidev, idx, bitnum, bitnum) != value) {
  360. if (--t == 0)
  361. return !value;
  362. }
  363. return value;
  364. }
  365. #ifdef DEBUG
  366. static void dsi_perf_mark_setup(struct platform_device *dsidev)
  367. {
  368. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  369. dsi->perf_setup_time = ktime_get();
  370. }
  371. static void dsi_perf_mark_start(struct platform_device *dsidev)
  372. {
  373. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  374. dsi->perf_start_time = ktime_get();
  375. }
  376. static void dsi_perf_show(struct platform_device *dsidev, const char *name)
  377. {
  378. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  379. ktime_t t, setup_time, trans_time;
  380. u32 total_bytes;
  381. u32 setup_us, trans_us, total_us;
  382. if (!dsi_perf)
  383. return;
  384. t = ktime_get();
  385. setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
  386. setup_us = (u32)ktime_to_us(setup_time);
  387. if (setup_us == 0)
  388. setup_us = 1;
  389. trans_time = ktime_sub(t, dsi->perf_start_time);
  390. trans_us = (u32)ktime_to_us(trans_time);
  391. if (trans_us == 0)
  392. trans_us = 1;
  393. total_us = setup_us + trans_us;
  394. total_bytes = dsi->update_region.w *
  395. dsi->update_region.h *
  396. dsi->update_region.device->ctrl.pixel_size / 8;
  397. printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
  398. "%u bytes, %u kbytes/sec\n",
  399. name,
  400. setup_us,
  401. trans_us,
  402. total_us,
  403. 1000*1000 / total_us,
  404. total_bytes,
  405. total_bytes * 1000 / total_us);
  406. }
  407. #else
  408. static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
  409. {
  410. }
  411. static inline void dsi_perf_mark_start(struct platform_device *dsidev)
  412. {
  413. }
  414. static inline void dsi_perf_show(struct platform_device *dsidev,
  415. const char *name)
  416. {
  417. }
  418. #endif
  419. static void print_irq_status(u32 status)
  420. {
  421. if (status == 0)
  422. return;
  423. #ifndef VERBOSE_IRQ
  424. if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  425. return;
  426. #endif
  427. printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
  428. #define PIS(x) \
  429. if (status & DSI_IRQ_##x) \
  430. printk(#x " ");
  431. #ifdef VERBOSE_IRQ
  432. PIS(VC0);
  433. PIS(VC1);
  434. PIS(VC2);
  435. PIS(VC3);
  436. #endif
  437. PIS(WAKEUP);
  438. PIS(RESYNC);
  439. PIS(PLL_LOCK);
  440. PIS(PLL_UNLOCK);
  441. PIS(PLL_RECALL);
  442. PIS(COMPLEXIO_ERR);
  443. PIS(HS_TX_TIMEOUT);
  444. PIS(LP_RX_TIMEOUT);
  445. PIS(TE_TRIGGER);
  446. PIS(ACK_TRIGGER);
  447. PIS(SYNC_LOST);
  448. PIS(LDO_POWER_GOOD);
  449. PIS(TA_TIMEOUT);
  450. #undef PIS
  451. printk("\n");
  452. }
  453. static void print_irq_status_vc(int channel, u32 status)
  454. {
  455. if (status == 0)
  456. return;
  457. #ifndef VERBOSE_IRQ
  458. if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  459. return;
  460. #endif
  461. printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
  462. #define PIS(x) \
  463. if (status & DSI_VC_IRQ_##x) \
  464. printk(#x " ");
  465. PIS(CS);
  466. PIS(ECC_CORR);
  467. #ifdef VERBOSE_IRQ
  468. PIS(PACKET_SENT);
  469. #endif
  470. PIS(FIFO_TX_OVF);
  471. PIS(FIFO_RX_OVF);
  472. PIS(BTA);
  473. PIS(ECC_NO_CORR);
  474. PIS(FIFO_TX_UDF);
  475. PIS(PP_BUSY_CHANGE);
  476. #undef PIS
  477. printk("\n");
  478. }
  479. static void print_irq_status_cio(u32 status)
  480. {
  481. if (status == 0)
  482. return;
  483. printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
  484. #define PIS(x) \
  485. if (status & DSI_CIO_IRQ_##x) \
  486. printk(#x " ");
  487. PIS(ERRSYNCESC1);
  488. PIS(ERRSYNCESC2);
  489. PIS(ERRSYNCESC3);
  490. PIS(ERRESC1);
  491. PIS(ERRESC2);
  492. PIS(ERRESC3);
  493. PIS(ERRCONTROL1);
  494. PIS(ERRCONTROL2);
  495. PIS(ERRCONTROL3);
  496. PIS(STATEULPS1);
  497. PIS(STATEULPS2);
  498. PIS(STATEULPS3);
  499. PIS(ERRCONTENTIONLP0_1);
  500. PIS(ERRCONTENTIONLP1_1);
  501. PIS(ERRCONTENTIONLP0_2);
  502. PIS(ERRCONTENTIONLP1_2);
  503. PIS(ERRCONTENTIONLP0_3);
  504. PIS(ERRCONTENTIONLP1_3);
  505. PIS(ULPSACTIVENOT_ALL0);
  506. PIS(ULPSACTIVENOT_ALL1);
  507. #undef PIS
  508. printk("\n");
  509. }
  510. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  511. static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
  512. u32 *vcstatus, u32 ciostatus)
  513. {
  514. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  515. int i;
  516. spin_lock(&dsi->irq_stats_lock);
  517. dsi->irq_stats.irq_count++;
  518. dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
  519. for (i = 0; i < 4; ++i)
  520. dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
  521. dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
  522. spin_unlock(&dsi->irq_stats_lock);
  523. }
  524. #else
  525. #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
  526. #endif
  527. static int debug_irq;
  528. static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
  529. u32 *vcstatus, u32 ciostatus)
  530. {
  531. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  532. int i;
  533. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  534. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  535. print_irq_status(irqstatus);
  536. spin_lock(&dsi->errors_lock);
  537. dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  538. spin_unlock(&dsi->errors_lock);
  539. } else if (debug_irq) {
  540. print_irq_status(irqstatus);
  541. }
  542. for (i = 0; i < 4; ++i) {
  543. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  544. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  545. i, vcstatus[i]);
  546. print_irq_status_vc(i, vcstatus[i]);
  547. } else if (debug_irq) {
  548. print_irq_status_vc(i, vcstatus[i]);
  549. }
  550. }
  551. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  552. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  553. print_irq_status_cio(ciostatus);
  554. } else if (debug_irq) {
  555. print_irq_status_cio(ciostatus);
  556. }
  557. }
  558. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  559. unsigned isr_array_size, u32 irqstatus)
  560. {
  561. struct dsi_isr_data *isr_data;
  562. int i;
  563. for (i = 0; i < isr_array_size; i++) {
  564. isr_data = &isr_array[i];
  565. if (isr_data->isr && isr_data->mask & irqstatus)
  566. isr_data->isr(isr_data->arg, irqstatus);
  567. }
  568. }
  569. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  570. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  571. {
  572. int i;
  573. dsi_call_isrs(isr_tables->isr_table,
  574. ARRAY_SIZE(isr_tables->isr_table),
  575. irqstatus);
  576. for (i = 0; i < 4; ++i) {
  577. if (vcstatus[i] == 0)
  578. continue;
  579. dsi_call_isrs(isr_tables->isr_table_vc[i],
  580. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  581. vcstatus[i]);
  582. }
  583. if (ciostatus != 0)
  584. dsi_call_isrs(isr_tables->isr_table_cio,
  585. ARRAY_SIZE(isr_tables->isr_table_cio),
  586. ciostatus);
  587. }
  588. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  589. {
  590. struct platform_device *dsidev;
  591. struct dsi_data *dsi;
  592. u32 irqstatus, vcstatus[4], ciostatus;
  593. int i;
  594. dsidev = (struct platform_device *) arg;
  595. dsi = dsi_get_dsidrv_data(dsidev);
  596. spin_lock(&dsi->irq_lock);
  597. irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
  598. /* IRQ is not for us */
  599. if (!irqstatus) {
  600. spin_unlock(&dsi->irq_lock);
  601. return IRQ_NONE;
  602. }
  603. dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  604. /* flush posted write */
  605. dsi_read_reg(dsidev, DSI_IRQSTATUS);
  606. for (i = 0; i < 4; ++i) {
  607. if ((irqstatus & (1 << i)) == 0) {
  608. vcstatus[i] = 0;
  609. continue;
  610. }
  611. vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  612. dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
  613. /* flush posted write */
  614. dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  615. }
  616. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  617. ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  618. dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  619. /* flush posted write */
  620. dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  621. } else {
  622. ciostatus = 0;
  623. }
  624. #ifdef DSI_CATCH_MISSING_TE
  625. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  626. del_timer(&dsi->te_timer);
  627. #endif
  628. /* make a copy and unlock, so that isrs can unregister
  629. * themselves */
  630. memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
  631. sizeof(dsi->isr_tables));
  632. spin_unlock(&dsi->irq_lock);
  633. dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
  634. dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
  635. dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
  636. return IRQ_HANDLED;
  637. }
  638. /* dsi->irq_lock has to be locked by the caller */
  639. static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
  640. struct dsi_isr_data *isr_array,
  641. unsigned isr_array_size, u32 default_mask,
  642. const struct dsi_reg enable_reg,
  643. const struct dsi_reg status_reg)
  644. {
  645. struct dsi_isr_data *isr_data;
  646. u32 mask;
  647. u32 old_mask;
  648. int i;
  649. mask = default_mask;
  650. for (i = 0; i < isr_array_size; i++) {
  651. isr_data = &isr_array[i];
  652. if (isr_data->isr == NULL)
  653. continue;
  654. mask |= isr_data->mask;
  655. }
  656. old_mask = dsi_read_reg(dsidev, enable_reg);
  657. /* clear the irqstatus for newly enabled irqs */
  658. dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
  659. dsi_write_reg(dsidev, enable_reg, mask);
  660. /* flush posted writes */
  661. dsi_read_reg(dsidev, enable_reg);
  662. dsi_read_reg(dsidev, status_reg);
  663. }
  664. /* dsi->irq_lock has to be locked by the caller */
  665. static void _omap_dsi_set_irqs(struct platform_device *dsidev)
  666. {
  667. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  668. u32 mask = DSI_IRQ_ERROR_MASK;
  669. #ifdef DSI_CATCH_MISSING_TE
  670. mask |= DSI_IRQ_TE_TRIGGER;
  671. #endif
  672. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
  673. ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
  674. DSI_IRQENABLE, DSI_IRQSTATUS);
  675. }
  676. /* dsi->irq_lock has to be locked by the caller */
  677. static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
  678. {
  679. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  680. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
  681. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
  682. DSI_VC_IRQ_ERROR_MASK,
  683. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  684. }
  685. /* dsi->irq_lock has to be locked by the caller */
  686. static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
  687. {
  688. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  689. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
  690. ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
  691. DSI_CIO_IRQ_ERROR_MASK,
  692. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  693. }
  694. static void _dsi_initialize_irq(struct platform_device *dsidev)
  695. {
  696. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  697. unsigned long flags;
  698. int vc;
  699. spin_lock_irqsave(&dsi->irq_lock, flags);
  700. memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
  701. _omap_dsi_set_irqs(dsidev);
  702. for (vc = 0; vc < 4; ++vc)
  703. _omap_dsi_set_irqs_vc(dsidev, vc);
  704. _omap_dsi_set_irqs_cio(dsidev);
  705. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  706. }
  707. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  708. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  709. {
  710. struct dsi_isr_data *isr_data;
  711. int free_idx;
  712. int i;
  713. BUG_ON(isr == NULL);
  714. /* check for duplicate entry and find a free slot */
  715. free_idx = -1;
  716. for (i = 0; i < isr_array_size; i++) {
  717. isr_data = &isr_array[i];
  718. if (isr_data->isr == isr && isr_data->arg == arg &&
  719. isr_data->mask == mask) {
  720. return -EINVAL;
  721. }
  722. if (isr_data->isr == NULL && free_idx == -1)
  723. free_idx = i;
  724. }
  725. if (free_idx == -1)
  726. return -EBUSY;
  727. isr_data = &isr_array[free_idx];
  728. isr_data->isr = isr;
  729. isr_data->arg = arg;
  730. isr_data->mask = mask;
  731. return 0;
  732. }
  733. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  734. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  735. {
  736. struct dsi_isr_data *isr_data;
  737. int i;
  738. for (i = 0; i < isr_array_size; i++) {
  739. isr_data = &isr_array[i];
  740. if (isr_data->isr != isr || isr_data->arg != arg ||
  741. isr_data->mask != mask)
  742. continue;
  743. isr_data->isr = NULL;
  744. isr_data->arg = NULL;
  745. isr_data->mask = 0;
  746. return 0;
  747. }
  748. return -EINVAL;
  749. }
  750. static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
  751. void *arg, u32 mask)
  752. {
  753. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  754. unsigned long flags;
  755. int r;
  756. spin_lock_irqsave(&dsi->irq_lock, flags);
  757. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  758. ARRAY_SIZE(dsi->isr_tables.isr_table));
  759. if (r == 0)
  760. _omap_dsi_set_irqs(dsidev);
  761. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  762. return r;
  763. }
  764. static int dsi_unregister_isr(struct platform_device *dsidev,
  765. omap_dsi_isr_t isr, void *arg, u32 mask)
  766. {
  767. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  768. unsigned long flags;
  769. int r;
  770. spin_lock_irqsave(&dsi->irq_lock, flags);
  771. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  772. ARRAY_SIZE(dsi->isr_tables.isr_table));
  773. if (r == 0)
  774. _omap_dsi_set_irqs(dsidev);
  775. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  776. return r;
  777. }
  778. static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
  779. omap_dsi_isr_t isr, void *arg, u32 mask)
  780. {
  781. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  782. unsigned long flags;
  783. int r;
  784. spin_lock_irqsave(&dsi->irq_lock, flags);
  785. r = _dsi_register_isr(isr, arg, mask,
  786. dsi->isr_tables.isr_table_vc[channel],
  787. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  788. if (r == 0)
  789. _omap_dsi_set_irqs_vc(dsidev, channel);
  790. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  791. return r;
  792. }
  793. static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
  794. omap_dsi_isr_t isr, void *arg, u32 mask)
  795. {
  796. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  797. unsigned long flags;
  798. int r;
  799. spin_lock_irqsave(&dsi->irq_lock, flags);
  800. r = _dsi_unregister_isr(isr, arg, mask,
  801. dsi->isr_tables.isr_table_vc[channel],
  802. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  803. if (r == 0)
  804. _omap_dsi_set_irqs_vc(dsidev, channel);
  805. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  806. return r;
  807. }
  808. static int dsi_register_isr_cio(struct platform_device *dsidev,
  809. omap_dsi_isr_t isr, void *arg, u32 mask)
  810. {
  811. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  812. unsigned long flags;
  813. int r;
  814. spin_lock_irqsave(&dsi->irq_lock, flags);
  815. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  816. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  817. if (r == 0)
  818. _omap_dsi_set_irqs_cio(dsidev);
  819. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  820. return r;
  821. }
  822. static int dsi_unregister_isr_cio(struct platform_device *dsidev,
  823. omap_dsi_isr_t isr, void *arg, u32 mask)
  824. {
  825. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  826. unsigned long flags;
  827. int r;
  828. spin_lock_irqsave(&dsi->irq_lock, flags);
  829. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  830. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  831. if (r == 0)
  832. _omap_dsi_set_irqs_cio(dsidev);
  833. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  834. return r;
  835. }
  836. static u32 dsi_get_errors(struct platform_device *dsidev)
  837. {
  838. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  839. unsigned long flags;
  840. u32 e;
  841. spin_lock_irqsave(&dsi->errors_lock, flags);
  842. e = dsi->errors;
  843. dsi->errors = 0;
  844. spin_unlock_irqrestore(&dsi->errors_lock, flags);
  845. return e;
  846. }
  847. int dsi_runtime_get(struct platform_device *dsidev)
  848. {
  849. int r;
  850. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  851. DSSDBG("dsi_runtime_get\n");
  852. r = pm_runtime_get_sync(&dsi->pdev->dev);
  853. WARN_ON(r < 0);
  854. return r < 0 ? r : 0;
  855. }
  856. void dsi_runtime_put(struct platform_device *dsidev)
  857. {
  858. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  859. int r;
  860. DSSDBG("dsi_runtime_put\n");
  861. r = pm_runtime_put(&dsi->pdev->dev);
  862. WARN_ON(r < 0);
  863. }
  864. /* source clock for DSI PLL. this could also be PCLKFREE */
  865. static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
  866. bool enable)
  867. {
  868. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  869. if (enable)
  870. clk_enable(dsi->sys_clk);
  871. else
  872. clk_disable(dsi->sys_clk);
  873. if (enable && dsi->pll_locked) {
  874. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
  875. DSSERR("cannot lock PLL when enabling clocks\n");
  876. }
  877. }
  878. #ifdef DEBUG
  879. static void _dsi_print_reset_status(struct platform_device *dsidev)
  880. {
  881. u32 l;
  882. int b0, b1, b2;
  883. if (!dss_debug)
  884. return;
  885. /* A dummy read using the SCP interface to any DSIPHY register is
  886. * required after DSIPHY reset to complete the reset of the DSI complex
  887. * I/O. */
  888. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  889. printk(KERN_DEBUG "DSI resets: ");
  890. l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
  891. printk("PLL (%d) ", FLD_GET(l, 0, 0));
  892. l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  893. printk("CIO (%d) ", FLD_GET(l, 29, 29));
  894. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  895. b0 = 28;
  896. b1 = 27;
  897. b2 = 26;
  898. } else {
  899. b0 = 24;
  900. b1 = 25;
  901. b2 = 26;
  902. }
  903. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  904. printk("PHY (%x%x%x, %d, %d, %d)\n",
  905. FLD_GET(l, b0, b0),
  906. FLD_GET(l, b1, b1),
  907. FLD_GET(l, b2, b2),
  908. FLD_GET(l, 29, 29),
  909. FLD_GET(l, 30, 30),
  910. FLD_GET(l, 31, 31));
  911. }
  912. #else
  913. #define _dsi_print_reset_status(x)
  914. #endif
  915. static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
  916. {
  917. DSSDBG("dsi_if_enable(%d)\n", enable);
  918. enable = enable ? 1 : 0;
  919. REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
  920. if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
  921. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  922. return -EIO;
  923. }
  924. return 0;
  925. }
  926. unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
  927. {
  928. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  929. return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
  930. }
  931. static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
  932. {
  933. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  934. return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
  935. }
  936. static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
  937. {
  938. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  939. return dsi->current_cinfo.clkin4ddr / 16;
  940. }
  941. static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
  942. {
  943. unsigned long r;
  944. int dsi_module = dsi_get_dsidev_id(dsidev);
  945. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  946. if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
  947. /* DSI FCLK source is DSS_CLK_FCK */
  948. r = clk_get_rate(dsi->dss_clk);
  949. } else {
  950. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  951. r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
  952. }
  953. return r;
  954. }
  955. static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
  956. {
  957. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  958. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  959. unsigned long dsi_fclk;
  960. unsigned lp_clk_div;
  961. unsigned long lp_clk;
  962. lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
  963. if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
  964. return -EINVAL;
  965. dsi_fclk = dsi_fclk_rate(dsidev);
  966. lp_clk = dsi_fclk / 2 / lp_clk_div;
  967. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  968. dsi->current_cinfo.lp_clk = lp_clk;
  969. dsi->current_cinfo.lp_clk_div = lp_clk_div;
  970. /* LP_CLK_DIVISOR */
  971. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
  972. /* LP_RX_SYNCHRO_ENABLE */
  973. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
  974. return 0;
  975. }
  976. static void dsi_enable_scp_clk(struct platform_device *dsidev)
  977. {
  978. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  979. if (dsi->scp_clk_refcount++ == 0)
  980. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
  981. }
  982. static void dsi_disable_scp_clk(struct platform_device *dsidev)
  983. {
  984. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  985. WARN_ON(dsi->scp_clk_refcount == 0);
  986. if (--dsi->scp_clk_refcount == 0)
  987. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
  988. }
  989. enum dsi_pll_power_state {
  990. DSI_PLL_POWER_OFF = 0x0,
  991. DSI_PLL_POWER_ON_HSCLK = 0x1,
  992. DSI_PLL_POWER_ON_ALL = 0x2,
  993. DSI_PLL_POWER_ON_DIV = 0x3,
  994. };
  995. static int dsi_pll_power(struct platform_device *dsidev,
  996. enum dsi_pll_power_state state)
  997. {
  998. int t = 0;
  999. /* DSI-PLL power command 0x3 is not working */
  1000. if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
  1001. state == DSI_PLL_POWER_ON_DIV)
  1002. state = DSI_PLL_POWER_ON_ALL;
  1003. /* PLL_PWR_CMD */
  1004. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
  1005. /* PLL_PWR_STATUS */
  1006. while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
  1007. if (++t > 1000) {
  1008. DSSERR("Failed to set DSI PLL power mode to %d\n",
  1009. state);
  1010. return -ENODEV;
  1011. }
  1012. udelay(1);
  1013. }
  1014. return 0;
  1015. }
  1016. /* calculate clock rates using dividers in cinfo */
  1017. static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
  1018. struct dsi_clock_info *cinfo)
  1019. {
  1020. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1021. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1022. if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
  1023. return -EINVAL;
  1024. if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
  1025. return -EINVAL;
  1026. if (cinfo->regm_dispc > dsi->regm_dispc_max)
  1027. return -EINVAL;
  1028. if (cinfo->regm_dsi > dsi->regm_dsi_max)
  1029. return -EINVAL;
  1030. if (cinfo->use_sys_clk) {
  1031. cinfo->clkin = clk_get_rate(dsi->sys_clk);
  1032. /* XXX it is unclear if highfreq should be used
  1033. * with DSS_SYS_CLK source also */
  1034. cinfo->highfreq = 0;
  1035. } else {
  1036. cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
  1037. if (cinfo->clkin < 32000000)
  1038. cinfo->highfreq = 0;
  1039. else
  1040. cinfo->highfreq = 1;
  1041. }
  1042. cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
  1043. if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
  1044. return -EINVAL;
  1045. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  1046. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  1047. return -EINVAL;
  1048. if (cinfo->regm_dispc > 0)
  1049. cinfo->dsi_pll_hsdiv_dispc_clk =
  1050. cinfo->clkin4ddr / cinfo->regm_dispc;
  1051. else
  1052. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  1053. if (cinfo->regm_dsi > 0)
  1054. cinfo->dsi_pll_hsdiv_dsi_clk =
  1055. cinfo->clkin4ddr / cinfo->regm_dsi;
  1056. else
  1057. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  1058. return 0;
  1059. }
  1060. int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
  1061. unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
  1062. struct dispc_clock_info *dispc_cinfo)
  1063. {
  1064. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1065. struct dsi_clock_info cur, best;
  1066. struct dispc_clock_info best_dispc;
  1067. int min_fck_per_pck;
  1068. int match = 0;
  1069. unsigned long dss_sys_clk, max_dss_fck;
  1070. dss_sys_clk = clk_get_rate(dsi->sys_clk);
  1071. max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  1072. if (req_pck == dsi->cache_req_pck &&
  1073. dsi->cache_cinfo.clkin == dss_sys_clk) {
  1074. DSSDBG("DSI clock info found from cache\n");
  1075. *dsi_cinfo = dsi->cache_cinfo;
  1076. dispc_find_clk_divs(is_tft, req_pck,
  1077. dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
  1078. return 0;
  1079. }
  1080. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  1081. if (min_fck_per_pck &&
  1082. req_pck * min_fck_per_pck > max_dss_fck) {
  1083. DSSERR("Requested pixel clock not possible with the current "
  1084. "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
  1085. "the constraint off.\n");
  1086. min_fck_per_pck = 0;
  1087. }
  1088. DSSDBG("dsi_pll_calc\n");
  1089. retry:
  1090. memset(&best, 0, sizeof(best));
  1091. memset(&best_dispc, 0, sizeof(best_dispc));
  1092. memset(&cur, 0, sizeof(cur));
  1093. cur.clkin = dss_sys_clk;
  1094. cur.use_sys_clk = 1;
  1095. cur.highfreq = 0;
  1096. /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
  1097. /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
  1098. /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
  1099. for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
  1100. if (cur.highfreq == 0)
  1101. cur.fint = cur.clkin / cur.regn;
  1102. else
  1103. cur.fint = cur.clkin / (2 * cur.regn);
  1104. if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
  1105. continue;
  1106. /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
  1107. for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
  1108. unsigned long a, b;
  1109. a = 2 * cur.regm * (cur.clkin/1000);
  1110. b = cur.regn * (cur.highfreq + 1);
  1111. cur.clkin4ddr = a / b * 1000;
  1112. if (cur.clkin4ddr > 1800 * 1000 * 1000)
  1113. break;
  1114. /* dsi_pll_hsdiv_dispc_clk(MHz) =
  1115. * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
  1116. for (cur.regm_dispc = 1; cur.regm_dispc <
  1117. dsi->regm_dispc_max; ++cur.regm_dispc) {
  1118. struct dispc_clock_info cur_dispc;
  1119. cur.dsi_pll_hsdiv_dispc_clk =
  1120. cur.clkin4ddr / cur.regm_dispc;
  1121. /* this will narrow down the search a bit,
  1122. * but still give pixclocks below what was
  1123. * requested */
  1124. if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
  1125. break;
  1126. if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
  1127. continue;
  1128. if (min_fck_per_pck &&
  1129. cur.dsi_pll_hsdiv_dispc_clk <
  1130. req_pck * min_fck_per_pck)
  1131. continue;
  1132. match = 1;
  1133. dispc_find_clk_divs(is_tft, req_pck,
  1134. cur.dsi_pll_hsdiv_dispc_clk,
  1135. &cur_dispc);
  1136. if (abs(cur_dispc.pck - req_pck) <
  1137. abs(best_dispc.pck - req_pck)) {
  1138. best = cur;
  1139. best_dispc = cur_dispc;
  1140. if (cur_dispc.pck == req_pck)
  1141. goto found;
  1142. }
  1143. }
  1144. }
  1145. }
  1146. found:
  1147. if (!match) {
  1148. if (min_fck_per_pck) {
  1149. DSSERR("Could not find suitable clock settings.\n"
  1150. "Turning FCK/PCK constraint off and"
  1151. "trying again.\n");
  1152. min_fck_per_pck = 0;
  1153. goto retry;
  1154. }
  1155. DSSERR("Could not find suitable clock settings.\n");
  1156. return -EINVAL;
  1157. }
  1158. /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
  1159. best.regm_dsi = 0;
  1160. best.dsi_pll_hsdiv_dsi_clk = 0;
  1161. if (dsi_cinfo)
  1162. *dsi_cinfo = best;
  1163. if (dispc_cinfo)
  1164. *dispc_cinfo = best_dispc;
  1165. dsi->cache_req_pck = req_pck;
  1166. dsi->cache_clk_freq = 0;
  1167. dsi->cache_cinfo = best;
  1168. return 0;
  1169. }
  1170. int dsi_pll_set_clock_div(struct platform_device *dsidev,
  1171. struct dsi_clock_info *cinfo)
  1172. {
  1173. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1174. int r = 0;
  1175. u32 l;
  1176. int f = 0;
  1177. u8 regn_start, regn_end, regm_start, regm_end;
  1178. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1179. DSSDBGF();
  1180. dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk;
  1181. dsi->current_cinfo.highfreq = cinfo->highfreq;
  1182. dsi->current_cinfo.fint = cinfo->fint;
  1183. dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1184. dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1185. cinfo->dsi_pll_hsdiv_dispc_clk;
  1186. dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1187. cinfo->dsi_pll_hsdiv_dsi_clk;
  1188. dsi->current_cinfo.regn = cinfo->regn;
  1189. dsi->current_cinfo.regm = cinfo->regm;
  1190. dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
  1191. dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
  1192. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1193. DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
  1194. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
  1195. cinfo->clkin,
  1196. cinfo->highfreq);
  1197. /* DSIPHY == CLKIN4DDR */
  1198. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
  1199. cinfo->regm,
  1200. cinfo->regn,
  1201. cinfo->clkin,
  1202. cinfo->highfreq + 1,
  1203. cinfo->clkin4ddr);
  1204. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1205. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1206. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1207. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1208. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1209. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1210. cinfo->dsi_pll_hsdiv_dispc_clk);
  1211. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1212. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1213. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1214. cinfo->dsi_pll_hsdiv_dsi_clk);
  1215. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1216. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1217. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1218. &regm_dispc_end);
  1219. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1220. &regm_dsi_end);
  1221. /* DSI_PLL_AUTOMODE = manual */
  1222. REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
  1223. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
  1224. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1225. /* DSI_PLL_REGN */
  1226. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1227. /* DSI_PLL_REGM */
  1228. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1229. /* DSI_CLOCK_DIV */
  1230. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1231. regm_dispc_start, regm_dispc_end);
  1232. /* DSIPROTO_CLOCK_DIV */
  1233. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1234. regm_dsi_start, regm_dsi_end);
  1235. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
  1236. BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
  1237. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
  1238. f = cinfo->fint < 1000000 ? 0x3 :
  1239. cinfo->fint < 1250000 ? 0x4 :
  1240. cinfo->fint < 1500000 ? 0x5 :
  1241. cinfo->fint < 1750000 ? 0x6 :
  1242. 0x7;
  1243. }
  1244. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1245. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
  1246. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1247. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1248. 11, 11); /* DSI_PLL_CLKSEL */
  1249. l = FLD_MOD(l, cinfo->highfreq,
  1250. 12, 12); /* DSI_PLL_HIGHFREQ */
  1251. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1252. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1253. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1254. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1255. REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1256. if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
  1257. DSSERR("dsi pll go bit not going down.\n");
  1258. r = -EIO;
  1259. goto err;
  1260. }
  1261. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
  1262. DSSERR("cannot lock PLL\n");
  1263. r = -EIO;
  1264. goto err;
  1265. }
  1266. dsi->pll_locked = 1;
  1267. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1268. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1269. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1270. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1271. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1272. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1273. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1274. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1275. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1276. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1277. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1278. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1279. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1280. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1281. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1282. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1283. DSSDBG("PLL config done\n");
  1284. err:
  1285. return r;
  1286. }
  1287. int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
  1288. bool enable_hsdiv)
  1289. {
  1290. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1291. int r = 0;
  1292. enum dsi_pll_power_state pwstate;
  1293. DSSDBG("PLL init\n");
  1294. if (dsi->vdds_dsi_reg == NULL) {
  1295. struct regulator *vdds_dsi;
  1296. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  1297. if (IS_ERR(vdds_dsi)) {
  1298. DSSERR("can't get VDDS_DSI regulator\n");
  1299. return PTR_ERR(vdds_dsi);
  1300. }
  1301. dsi->vdds_dsi_reg = vdds_dsi;
  1302. }
  1303. dsi_enable_pll_clock(dsidev, 1);
  1304. /*
  1305. * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
  1306. */
  1307. dsi_enable_scp_clk(dsidev);
  1308. if (!dsi->vdds_dsi_enabled) {
  1309. r = regulator_enable(dsi->vdds_dsi_reg);
  1310. if (r)
  1311. goto err0;
  1312. dsi->vdds_dsi_enabled = true;
  1313. }
  1314. /* XXX PLL does not come out of reset without this... */
  1315. dispc_pck_free_enable(1);
  1316. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
  1317. DSSERR("PLL not coming out of reset.\n");
  1318. r = -ENODEV;
  1319. dispc_pck_free_enable(0);
  1320. goto err1;
  1321. }
  1322. /* XXX ... but if left on, we get problems when planes do not
  1323. * fill the whole display. No idea about this */
  1324. dispc_pck_free_enable(0);
  1325. if (enable_hsclk && enable_hsdiv)
  1326. pwstate = DSI_PLL_POWER_ON_ALL;
  1327. else if (enable_hsclk)
  1328. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1329. else if (enable_hsdiv)
  1330. pwstate = DSI_PLL_POWER_ON_DIV;
  1331. else
  1332. pwstate = DSI_PLL_POWER_OFF;
  1333. r = dsi_pll_power(dsidev, pwstate);
  1334. if (r)
  1335. goto err1;
  1336. DSSDBG("PLL init done\n");
  1337. return 0;
  1338. err1:
  1339. if (dsi->vdds_dsi_enabled) {
  1340. regulator_disable(dsi->vdds_dsi_reg);
  1341. dsi->vdds_dsi_enabled = false;
  1342. }
  1343. err0:
  1344. dsi_disable_scp_clk(dsidev);
  1345. dsi_enable_pll_clock(dsidev, 0);
  1346. return r;
  1347. }
  1348. void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
  1349. {
  1350. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1351. dsi->pll_locked = 0;
  1352. dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
  1353. if (disconnect_lanes) {
  1354. WARN_ON(!dsi->vdds_dsi_enabled);
  1355. regulator_disable(dsi->vdds_dsi_reg);
  1356. dsi->vdds_dsi_enabled = false;
  1357. }
  1358. dsi_disable_scp_clk(dsidev);
  1359. dsi_enable_pll_clock(dsidev, 0);
  1360. DSSDBG("PLL uninit done\n");
  1361. }
  1362. static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
  1363. struct seq_file *s)
  1364. {
  1365. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1366. struct dsi_clock_info *cinfo = &dsi->current_cinfo;
  1367. enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
  1368. int dsi_module = dsi_get_dsidev_id(dsidev);
  1369. dispc_clk_src = dss_get_dispc_clk_source();
  1370. dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
  1371. if (dsi_runtime_get(dsidev))
  1372. return;
  1373. seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
  1374. seq_printf(s, "dsi pll source = %s\n",
  1375. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
  1376. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1377. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1378. cinfo->clkin4ddr, cinfo->regm);
  1379. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1380. dss_get_generic_clk_source_name(dispc_clk_src),
  1381. dss_feat_get_clk_source_name(dispc_clk_src),
  1382. cinfo->dsi_pll_hsdiv_dispc_clk,
  1383. cinfo->regm_dispc,
  1384. dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1385. "off" : "on");
  1386. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1387. dss_get_generic_clk_source_name(dsi_clk_src),
  1388. dss_feat_get_clk_source_name(dsi_clk_src),
  1389. cinfo->dsi_pll_hsdiv_dsi_clk,
  1390. cinfo->regm_dsi,
  1391. dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1392. "off" : "on");
  1393. seq_printf(s, "- DSI%d -\n", dsi_module + 1);
  1394. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1395. dss_get_generic_clk_source_name(dsi_clk_src),
  1396. dss_feat_get_clk_source_name(dsi_clk_src));
  1397. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
  1398. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1399. cinfo->clkin4ddr / 4);
  1400. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
  1401. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1402. dsi_runtime_put(dsidev);
  1403. }
  1404. void dsi_dump_clocks(struct seq_file *s)
  1405. {
  1406. struct platform_device *dsidev;
  1407. int i;
  1408. for (i = 0; i < MAX_NUM_DSI; i++) {
  1409. dsidev = dsi_get_dsidev_from_id(i);
  1410. if (dsidev)
  1411. dsi_dump_dsidev_clocks(dsidev, s);
  1412. }
  1413. }
  1414. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1415. static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
  1416. struct seq_file *s)
  1417. {
  1418. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1419. unsigned long flags;
  1420. struct dsi_irq_stats stats;
  1421. int dsi_module = dsi_get_dsidev_id(dsidev);
  1422. spin_lock_irqsave(&dsi->irq_stats_lock, flags);
  1423. stats = dsi->irq_stats;
  1424. memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
  1425. dsi->irq_stats.last_reset = jiffies;
  1426. spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
  1427. seq_printf(s, "period %u ms\n",
  1428. jiffies_to_msecs(jiffies - stats.last_reset));
  1429. seq_printf(s, "irqs %d\n", stats.irq_count);
  1430. #define PIS(x) \
  1431. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1432. seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1);
  1433. PIS(VC0);
  1434. PIS(VC1);
  1435. PIS(VC2);
  1436. PIS(VC3);
  1437. PIS(WAKEUP);
  1438. PIS(RESYNC);
  1439. PIS(PLL_LOCK);
  1440. PIS(PLL_UNLOCK);
  1441. PIS(PLL_RECALL);
  1442. PIS(COMPLEXIO_ERR);
  1443. PIS(HS_TX_TIMEOUT);
  1444. PIS(LP_RX_TIMEOUT);
  1445. PIS(TE_TRIGGER);
  1446. PIS(ACK_TRIGGER);
  1447. PIS(SYNC_LOST);
  1448. PIS(LDO_POWER_GOOD);
  1449. PIS(TA_TIMEOUT);
  1450. #undef PIS
  1451. #define PIS(x) \
  1452. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1453. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1454. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1455. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1456. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1457. seq_printf(s, "-- VC interrupts --\n");
  1458. PIS(CS);
  1459. PIS(ECC_CORR);
  1460. PIS(PACKET_SENT);
  1461. PIS(FIFO_TX_OVF);
  1462. PIS(FIFO_RX_OVF);
  1463. PIS(BTA);
  1464. PIS(ECC_NO_CORR);
  1465. PIS(FIFO_TX_UDF);
  1466. PIS(PP_BUSY_CHANGE);
  1467. #undef PIS
  1468. #define PIS(x) \
  1469. seq_printf(s, "%-20s %10d\n", #x, \
  1470. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1471. seq_printf(s, "-- CIO interrupts --\n");
  1472. PIS(ERRSYNCESC1);
  1473. PIS(ERRSYNCESC2);
  1474. PIS(ERRSYNCESC3);
  1475. PIS(ERRESC1);
  1476. PIS(ERRESC2);
  1477. PIS(ERRESC3);
  1478. PIS(ERRCONTROL1);
  1479. PIS(ERRCONTROL2);
  1480. PIS(ERRCONTROL3);
  1481. PIS(STATEULPS1);
  1482. PIS(STATEULPS2);
  1483. PIS(STATEULPS3);
  1484. PIS(ERRCONTENTIONLP0_1);
  1485. PIS(ERRCONTENTIONLP1_1);
  1486. PIS(ERRCONTENTIONLP0_2);
  1487. PIS(ERRCONTENTIONLP1_2);
  1488. PIS(ERRCONTENTIONLP0_3);
  1489. PIS(ERRCONTENTIONLP1_3);
  1490. PIS(ULPSACTIVENOT_ALL0);
  1491. PIS(ULPSACTIVENOT_ALL1);
  1492. #undef PIS
  1493. }
  1494. static void dsi1_dump_irqs(struct seq_file *s)
  1495. {
  1496. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1497. dsi_dump_dsidev_irqs(dsidev, s);
  1498. }
  1499. static void dsi2_dump_irqs(struct seq_file *s)
  1500. {
  1501. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1502. dsi_dump_dsidev_irqs(dsidev, s);
  1503. }
  1504. void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
  1505. const struct file_operations *debug_fops)
  1506. {
  1507. struct platform_device *dsidev;
  1508. dsidev = dsi_get_dsidev_from_id(0);
  1509. if (dsidev)
  1510. debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
  1511. &dsi1_dump_irqs, debug_fops);
  1512. dsidev = dsi_get_dsidev_from_id(1);
  1513. if (dsidev)
  1514. debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
  1515. &dsi2_dump_irqs, debug_fops);
  1516. }
  1517. #endif
  1518. static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
  1519. struct seq_file *s)
  1520. {
  1521. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
  1522. if (dsi_runtime_get(dsidev))
  1523. return;
  1524. dsi_enable_scp_clk(dsidev);
  1525. DUMPREG(DSI_REVISION);
  1526. DUMPREG(DSI_SYSCONFIG);
  1527. DUMPREG(DSI_SYSSTATUS);
  1528. DUMPREG(DSI_IRQSTATUS);
  1529. DUMPREG(DSI_IRQENABLE);
  1530. DUMPREG(DSI_CTRL);
  1531. DUMPREG(DSI_COMPLEXIO_CFG1);
  1532. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1533. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1534. DUMPREG(DSI_CLK_CTRL);
  1535. DUMPREG(DSI_TIMING1);
  1536. DUMPREG(DSI_TIMING2);
  1537. DUMPREG(DSI_VM_TIMING1);
  1538. DUMPREG(DSI_VM_TIMING2);
  1539. DUMPREG(DSI_VM_TIMING3);
  1540. DUMPREG(DSI_CLK_TIMING);
  1541. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1542. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1543. DUMPREG(DSI_COMPLEXIO_CFG2);
  1544. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1545. DUMPREG(DSI_VM_TIMING4);
  1546. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1547. DUMPREG(DSI_VM_TIMING5);
  1548. DUMPREG(DSI_VM_TIMING6);
  1549. DUMPREG(DSI_VM_TIMING7);
  1550. DUMPREG(DSI_STOPCLK_TIMING);
  1551. DUMPREG(DSI_VC_CTRL(0));
  1552. DUMPREG(DSI_VC_TE(0));
  1553. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1554. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1555. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1556. DUMPREG(DSI_VC_IRQSTATUS(0));
  1557. DUMPREG(DSI_VC_IRQENABLE(0));
  1558. DUMPREG(DSI_VC_CTRL(1));
  1559. DUMPREG(DSI_VC_TE(1));
  1560. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1561. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1562. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1563. DUMPREG(DSI_VC_IRQSTATUS(1));
  1564. DUMPREG(DSI_VC_IRQENABLE(1));
  1565. DUMPREG(DSI_VC_CTRL(2));
  1566. DUMPREG(DSI_VC_TE(2));
  1567. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1568. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1569. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1570. DUMPREG(DSI_VC_IRQSTATUS(2));
  1571. DUMPREG(DSI_VC_IRQENABLE(2));
  1572. DUMPREG(DSI_VC_CTRL(3));
  1573. DUMPREG(DSI_VC_TE(3));
  1574. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1575. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1576. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1577. DUMPREG(DSI_VC_IRQSTATUS(3));
  1578. DUMPREG(DSI_VC_IRQENABLE(3));
  1579. DUMPREG(DSI_DSIPHY_CFG0);
  1580. DUMPREG(DSI_DSIPHY_CFG1);
  1581. DUMPREG(DSI_DSIPHY_CFG2);
  1582. DUMPREG(DSI_DSIPHY_CFG5);
  1583. DUMPREG(DSI_PLL_CONTROL);
  1584. DUMPREG(DSI_PLL_STATUS);
  1585. DUMPREG(DSI_PLL_GO);
  1586. DUMPREG(DSI_PLL_CONFIGURATION1);
  1587. DUMPREG(DSI_PLL_CONFIGURATION2);
  1588. dsi_disable_scp_clk(dsidev);
  1589. dsi_runtime_put(dsidev);
  1590. #undef DUMPREG
  1591. }
  1592. static void dsi1_dump_regs(struct seq_file *s)
  1593. {
  1594. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1595. dsi_dump_dsidev_regs(dsidev, s);
  1596. }
  1597. static void dsi2_dump_regs(struct seq_file *s)
  1598. {
  1599. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1600. dsi_dump_dsidev_regs(dsidev, s);
  1601. }
  1602. void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
  1603. const struct file_operations *debug_fops)
  1604. {
  1605. struct platform_device *dsidev;
  1606. dsidev = dsi_get_dsidev_from_id(0);
  1607. if (dsidev)
  1608. debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
  1609. &dsi1_dump_regs, debug_fops);
  1610. dsidev = dsi_get_dsidev_from_id(1);
  1611. if (dsidev)
  1612. debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
  1613. &dsi2_dump_regs, debug_fops);
  1614. }
  1615. enum dsi_cio_power_state {
  1616. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1617. DSI_COMPLEXIO_POWER_ON = 0x1,
  1618. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1619. };
  1620. static int dsi_cio_power(struct platform_device *dsidev,
  1621. enum dsi_cio_power_state state)
  1622. {
  1623. int t = 0;
  1624. /* PWR_CMD */
  1625. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
  1626. /* PWR_STATUS */
  1627. while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
  1628. 26, 25) != state) {
  1629. if (++t > 1000) {
  1630. DSSERR("failed to set complexio power state to "
  1631. "%d\n", state);
  1632. return -ENODEV;
  1633. }
  1634. udelay(1);
  1635. }
  1636. return 0;
  1637. }
  1638. /* Number of data lanes present on DSI interface */
  1639. static inline int dsi_get_num_data_lanes(struct platform_device *dsidev)
  1640. {
  1641. /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
  1642. * of data lanes as 2 by default */
  1643. if (dss_has_feature(FEAT_DSI_GNQ))
  1644. return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */
  1645. else
  1646. return 2;
  1647. }
  1648. /* Number of data lanes used by the dss device */
  1649. static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev)
  1650. {
  1651. int num_data_lanes = 0;
  1652. if (dssdev->phy.dsi.data1_lane != 0)
  1653. num_data_lanes++;
  1654. if (dssdev->phy.dsi.data2_lane != 0)
  1655. num_data_lanes++;
  1656. if (dssdev->phy.dsi.data3_lane != 0)
  1657. num_data_lanes++;
  1658. if (dssdev->phy.dsi.data4_lane != 0)
  1659. num_data_lanes++;
  1660. return num_data_lanes;
  1661. }
  1662. static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
  1663. {
  1664. int val;
  1665. /* line buffer on OMAP3 is 1024 x 24bits */
  1666. /* XXX: for some reason using full buffer size causes
  1667. * considerable TX slowdown with update sizes that fill the
  1668. * whole buffer */
  1669. if (!dss_has_feature(FEAT_DSI_GNQ))
  1670. return 1023 * 3;
  1671. val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
  1672. switch (val) {
  1673. case 1:
  1674. return 512 * 3; /* 512x24 bits */
  1675. case 2:
  1676. return 682 * 3; /* 682x24 bits */
  1677. case 3:
  1678. return 853 * 3; /* 853x24 bits */
  1679. case 4:
  1680. return 1024 * 3; /* 1024x24 bits */
  1681. case 5:
  1682. return 1194 * 3; /* 1194x24 bits */
  1683. case 6:
  1684. return 1365 * 3; /* 1365x24 bits */
  1685. default:
  1686. BUG();
  1687. }
  1688. }
  1689. static void dsi_set_lane_config(struct omap_dss_device *dssdev)
  1690. {
  1691. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1692. u32 r;
  1693. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1694. int clk_lane = dssdev->phy.dsi.clk_lane;
  1695. int data1_lane = dssdev->phy.dsi.data1_lane;
  1696. int data2_lane = dssdev->phy.dsi.data2_lane;
  1697. int clk_pol = dssdev->phy.dsi.clk_pol;
  1698. int data1_pol = dssdev->phy.dsi.data1_pol;
  1699. int data2_pol = dssdev->phy.dsi.data2_pol;
  1700. r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  1701. r = FLD_MOD(r, clk_lane, 2, 0);
  1702. r = FLD_MOD(r, clk_pol, 3, 3);
  1703. r = FLD_MOD(r, data1_lane, 6, 4);
  1704. r = FLD_MOD(r, data1_pol, 7, 7);
  1705. r = FLD_MOD(r, data2_lane, 10, 8);
  1706. r = FLD_MOD(r, data2_pol, 11, 11);
  1707. if (num_data_lanes_dssdev > 2) {
  1708. int data3_lane = dssdev->phy.dsi.data3_lane;
  1709. int data3_pol = dssdev->phy.dsi.data3_pol;
  1710. r = FLD_MOD(r, data3_lane, 14, 12);
  1711. r = FLD_MOD(r, data3_pol, 15, 15);
  1712. }
  1713. if (num_data_lanes_dssdev > 3) {
  1714. int data4_lane = dssdev->phy.dsi.data4_lane;
  1715. int data4_pol = dssdev->phy.dsi.data4_pol;
  1716. r = FLD_MOD(r, data4_lane, 18, 16);
  1717. r = FLD_MOD(r, data4_pol, 19, 19);
  1718. }
  1719. dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
  1720. /* The configuration of the DSI complex I/O (number of data lanes,
  1721. position, differential order) should not be changed while
  1722. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1723. the hardware to take into account a new configuration of the complex
  1724. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1725. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1726. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1727. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1728. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1729. DSI complex I/O configuration is unknown. */
  1730. /*
  1731. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1732. REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0);
  1733. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20);
  1734. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1735. */
  1736. }
  1737. static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
  1738. {
  1739. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1740. /* convert time in ns to ddr ticks, rounding up */
  1741. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1742. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1743. }
  1744. static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
  1745. {
  1746. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1747. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1748. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1749. }
  1750. static void dsi_cio_timings(struct platform_device *dsidev)
  1751. {
  1752. u32 r;
  1753. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1754. u32 tlpx_half, tclk_trail, tclk_zero;
  1755. u32 tclk_prepare;
  1756. /* calculate timings */
  1757. /* 1 * DDR_CLK = 2 * UI */
  1758. /* min 40ns + 4*UI max 85ns + 6*UI */
  1759. ths_prepare = ns2ddr(dsidev, 70) + 2;
  1760. /* min 145ns + 10*UI */
  1761. ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
  1762. /* min max(8*UI, 60ns+4*UI) */
  1763. ths_trail = ns2ddr(dsidev, 60) + 5;
  1764. /* min 100ns */
  1765. ths_exit = ns2ddr(dsidev, 145);
  1766. /* tlpx min 50n */
  1767. tlpx_half = ns2ddr(dsidev, 25);
  1768. /* min 60ns */
  1769. tclk_trail = ns2ddr(dsidev, 60) + 2;
  1770. /* min 38ns, max 95ns */
  1771. tclk_prepare = ns2ddr(dsidev, 65);
  1772. /* min tclk-prepare + tclk-zero = 300ns */
  1773. tclk_zero = ns2ddr(dsidev, 260);
  1774. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1775. ths_prepare, ddr2ns(dsidev, ths_prepare),
  1776. ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
  1777. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1778. ths_trail, ddr2ns(dsidev, ths_trail),
  1779. ths_exit, ddr2ns(dsidev, ths_exit));
  1780. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1781. "tclk_zero %u (%uns)\n",
  1782. tlpx_half, ddr2ns(dsidev, tlpx_half),
  1783. tclk_trail, ddr2ns(dsidev, tclk_trail),
  1784. tclk_zero, ddr2ns(dsidev, tclk_zero));
  1785. DSSDBG("tclk_prepare %u (%uns)\n",
  1786. tclk_prepare, ddr2ns(dsidev, tclk_prepare));
  1787. /* program timings */
  1788. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  1789. r = FLD_MOD(r, ths_prepare, 31, 24);
  1790. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1791. r = FLD_MOD(r, ths_trail, 15, 8);
  1792. r = FLD_MOD(r, ths_exit, 7, 0);
  1793. dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
  1794. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  1795. r = FLD_MOD(r, tlpx_half, 22, 16);
  1796. r = FLD_MOD(r, tclk_trail, 15, 8);
  1797. r = FLD_MOD(r, tclk_zero, 7, 0);
  1798. dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
  1799. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  1800. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1801. dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
  1802. }
  1803. static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
  1804. enum dsi_lane lanes)
  1805. {
  1806. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1807. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1808. int clk_lane = dssdev->phy.dsi.clk_lane;
  1809. int data1_lane = dssdev->phy.dsi.data1_lane;
  1810. int data2_lane = dssdev->phy.dsi.data2_lane;
  1811. int data3_lane = dssdev->phy.dsi.data3_lane;
  1812. int data4_lane = dssdev->phy.dsi.data4_lane;
  1813. int clk_pol = dssdev->phy.dsi.clk_pol;
  1814. int data1_pol = dssdev->phy.dsi.data1_pol;
  1815. int data2_pol = dssdev->phy.dsi.data2_pol;
  1816. int data3_pol = dssdev->phy.dsi.data3_pol;
  1817. int data4_pol = dssdev->phy.dsi.data4_pol;
  1818. u32 l = 0;
  1819. u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26;
  1820. if (lanes & DSI_CLK_P)
  1821. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1));
  1822. if (lanes & DSI_CLK_N)
  1823. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0));
  1824. if (lanes & DSI_DATA1_P)
  1825. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1));
  1826. if (lanes & DSI_DATA1_N)
  1827. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0));
  1828. if (lanes & DSI_DATA2_P)
  1829. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1));
  1830. if (lanes & DSI_DATA2_N)
  1831. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0));
  1832. if (lanes & DSI_DATA3_P)
  1833. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1));
  1834. if (lanes & DSI_DATA3_N)
  1835. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0));
  1836. if (lanes & DSI_DATA4_P)
  1837. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1));
  1838. if (lanes & DSI_DATA4_N)
  1839. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0));
  1840. /*
  1841. * Bits in REGLPTXSCPDAT4TO0DXDY:
  1842. * 17: DY0 18: DX0
  1843. * 19: DY1 20: DX1
  1844. * 21: DY2 22: DX2
  1845. * 23: DY3 24: DX3
  1846. * 25: DY4 26: DX4
  1847. */
  1848. /* Set the lane override configuration */
  1849. /* REGLPTXSCPDAT4TO0DXDY */
  1850. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
  1851. /* Enable lane override */
  1852. /* ENLPTXSCPDAT */
  1853. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
  1854. }
  1855. static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
  1856. {
  1857. /* Disable lane override */
  1858. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
  1859. /* Reset the lane override configuration */
  1860. /* REGLPTXSCPDAT4TO0DXDY */
  1861. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
  1862. }
  1863. static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
  1864. {
  1865. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1866. int t;
  1867. int bits[3];
  1868. bool in_use[3];
  1869. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  1870. bits[0] = 28;
  1871. bits[1] = 27;
  1872. bits[2] = 26;
  1873. } else {
  1874. bits[0] = 24;
  1875. bits[1] = 25;
  1876. bits[2] = 26;
  1877. }
  1878. in_use[0] = false;
  1879. in_use[1] = false;
  1880. in_use[2] = false;
  1881. if (dssdev->phy.dsi.clk_lane != 0)
  1882. in_use[dssdev->phy.dsi.clk_lane - 1] = true;
  1883. if (dssdev->phy.dsi.data1_lane != 0)
  1884. in_use[dssdev->phy.dsi.data1_lane - 1] = true;
  1885. if (dssdev->phy.dsi.data2_lane != 0)
  1886. in_use[dssdev->phy.dsi.data2_lane - 1] = true;
  1887. t = 100000;
  1888. while (true) {
  1889. u32 l;
  1890. int i;
  1891. int ok;
  1892. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1893. ok = 0;
  1894. for (i = 0; i < 3; ++i) {
  1895. if (!in_use[i] || (l & (1 << bits[i])))
  1896. ok++;
  1897. }
  1898. if (ok == 3)
  1899. break;
  1900. if (--t == 0) {
  1901. for (i = 0; i < 3; ++i) {
  1902. if (!in_use[i] || (l & (1 << bits[i])))
  1903. continue;
  1904. DSSERR("CIO TXCLKESC%d domain not coming " \
  1905. "out of reset\n", i);
  1906. }
  1907. return -EIO;
  1908. }
  1909. }
  1910. return 0;
  1911. }
  1912. static unsigned dsi_get_lane_mask(struct omap_dss_device *dssdev)
  1913. {
  1914. unsigned lanes = 0;
  1915. if (dssdev->phy.dsi.clk_lane != 0)
  1916. lanes |= 1 << (dssdev->phy.dsi.clk_lane - 1);
  1917. if (dssdev->phy.dsi.data1_lane != 0)
  1918. lanes |= 1 << (dssdev->phy.dsi.data1_lane - 1);
  1919. if (dssdev->phy.dsi.data2_lane != 0)
  1920. lanes |= 1 << (dssdev->phy.dsi.data2_lane - 1);
  1921. if (dssdev->phy.dsi.data3_lane != 0)
  1922. lanes |= 1 << (dssdev->phy.dsi.data3_lane - 1);
  1923. if (dssdev->phy.dsi.data4_lane != 0)
  1924. lanes |= 1 << (dssdev->phy.dsi.data4_lane - 1);
  1925. return lanes;
  1926. }
  1927. static int dsi_cio_init(struct omap_dss_device *dssdev)
  1928. {
  1929. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1930. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1931. int r;
  1932. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1933. u32 l;
  1934. DSSDBGF();
  1935. r = dsi->enable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
  1936. if (r)
  1937. return r;
  1938. dsi_enable_scp_clk(dsidev);
  1939. /* A dummy read using the SCP interface to any DSIPHY register is
  1940. * required after DSIPHY reset to complete the reset of the DSI complex
  1941. * I/O. */
  1942. dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1943. if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1944. DSSERR("CIO SCP Clock domain not coming out of reset.\n");
  1945. r = -EIO;
  1946. goto err_scp_clk_dom;
  1947. }
  1948. dsi_set_lane_config(dssdev);
  1949. /* set TX STOP MODE timer to maximum for this operation */
  1950. l = dsi_read_reg(dsidev, DSI_TIMING1);
  1951. l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1952. l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
  1953. l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
  1954. l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
  1955. dsi_write_reg(dsidev, DSI_TIMING1, l);
  1956. if (dsi->ulps_enabled) {
  1957. u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P;
  1958. DSSDBG("manual ulps exit\n");
  1959. /* ULPS is exited by Mark-1 state for 1ms, followed by
  1960. * stop state. DSS HW cannot do this via the normal
  1961. * ULPS exit sequence, as after reset the DSS HW thinks
  1962. * that we are not in ULPS mode, and refuses to send the
  1963. * sequence. So we need to send the ULPS exit sequence
  1964. * manually.
  1965. */
  1966. if (num_data_lanes_dssdev > 2)
  1967. lane_mask |= DSI_DATA3_P;
  1968. if (num_data_lanes_dssdev > 3)
  1969. lane_mask |= DSI_DATA4_P;
  1970. dsi_cio_enable_lane_override(dssdev, lane_mask);
  1971. }
  1972. r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
  1973. if (r)
  1974. goto err_cio_pwr;
  1975. if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1976. DSSERR("CIO PWR clock domain not coming out of reset.\n");
  1977. r = -ENODEV;
  1978. goto err_cio_pwr_dom;
  1979. }
  1980. dsi_if_enable(dsidev, true);
  1981. dsi_if_enable(dsidev, false);
  1982. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1983. r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
  1984. if (r)
  1985. goto err_tx_clk_esc_rst;
  1986. if (dsi->ulps_enabled) {
  1987. /* Keep Mark-1 state for 1ms (as per DSI spec) */
  1988. ktime_t wait = ns_to_ktime(1000 * 1000);
  1989. set_current_state(TASK_UNINTERRUPTIBLE);
  1990. schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
  1991. /* Disable the override. The lanes should be set to Mark-11
  1992. * state by the HW */
  1993. dsi_cio_disable_lane_override(dsidev);
  1994. }
  1995. /* FORCE_TX_STOP_MODE_IO */
  1996. REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
  1997. dsi_cio_timings(dsidev);
  1998. dsi->ulps_enabled = false;
  1999. DSSDBG("CIO init done\n");
  2000. return 0;
  2001. err_tx_clk_esc_rst:
  2002. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
  2003. err_cio_pwr_dom:
  2004. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  2005. err_cio_pwr:
  2006. if (dsi->ulps_enabled)
  2007. dsi_cio_disable_lane_override(dsidev);
  2008. err_scp_clk_dom:
  2009. dsi_disable_scp_clk(dsidev);
  2010. dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
  2011. return r;
  2012. }
  2013. static void dsi_cio_uninit(struct omap_dss_device *dssdev)
  2014. {
  2015. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2016. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2017. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  2018. dsi_disable_scp_clk(dsidev);
  2019. dsi->disable_pads(dsidev->id, dsi_get_lane_mask(dssdev));
  2020. }
  2021. static void dsi_config_tx_fifo(struct platform_device *dsidev,
  2022. enum fifo_size size1, enum fifo_size size2,
  2023. enum fifo_size size3, enum fifo_size size4)
  2024. {
  2025. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2026. u32 r = 0;
  2027. int add = 0;
  2028. int i;
  2029. dsi->vc[0].fifo_size = size1;
  2030. dsi->vc[1].fifo_size = size2;
  2031. dsi->vc[2].fifo_size = size3;
  2032. dsi->vc[3].fifo_size = size4;
  2033. for (i = 0; i < 4; i++) {
  2034. u8 v;
  2035. int size = dsi->vc[i].fifo_size;
  2036. if (add + size > 4) {
  2037. DSSERR("Illegal FIFO configuration\n");
  2038. BUG();
  2039. }
  2040. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  2041. r |= v << (8 * i);
  2042. /*DSSDBG("TX FIFO vc %d: size %d, add %d\n", i, size, add); */
  2043. add += size;
  2044. }
  2045. dsi_write_reg(dsidev, DSI_TX_FIFO_VC_SIZE, r);
  2046. }
  2047. static void dsi_config_rx_fifo(struct platform_device *dsidev,
  2048. enum fifo_size size1, enum fifo_size size2,
  2049. enum fifo_size size3, enum fifo_size size4)
  2050. {
  2051. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2052. u32 r = 0;
  2053. int add = 0;
  2054. int i;
  2055. dsi->vc[0].fifo_size = size1;
  2056. dsi->vc[1].fifo_size = size2;
  2057. dsi->vc[2].fifo_size = size3;
  2058. dsi->vc[3].fifo_size = size4;
  2059. for (i = 0; i < 4; i++) {
  2060. u8 v;
  2061. int size = dsi->vc[i].fifo_size;
  2062. if (add + size > 4) {
  2063. DSSERR("Illegal FIFO configuration\n");
  2064. BUG();
  2065. }
  2066. v = FLD_VAL(add, 2, 0) | FLD_VAL(size, 7, 4);
  2067. r |= v << (8 * i);
  2068. /*DSSDBG("RX FIFO vc %d: size %d, add %d\n", i, size, add); */
  2069. add += size;
  2070. }
  2071. dsi_write_reg(dsidev, DSI_RX_FIFO_VC_SIZE, r);
  2072. }
  2073. static int dsi_force_tx_stop_mode_io(struct platform_device *dsidev)
  2074. {
  2075. u32 r;
  2076. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2077. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2078. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2079. if (wait_for_bit_change(dsidev, DSI_TIMING1, 15, 0) != 0) {
  2080. DSSERR("TX_STOP bit not going down\n");
  2081. return -EIO;
  2082. }
  2083. return 0;
  2084. }
  2085. static bool dsi_vc_is_enabled(struct platform_device *dsidev, int channel)
  2086. {
  2087. return REG_GET(dsidev, DSI_VC_CTRL(channel), 0, 0);
  2088. }
  2089. static void dsi_packet_sent_handler_vp(void *data, u32 mask)
  2090. {
  2091. struct dsi_packet_sent_handler_data *vp_data =
  2092. (struct dsi_packet_sent_handler_data *) data;
  2093. struct dsi_data *dsi = dsi_get_dsidrv_data(vp_data->dsidev);
  2094. const int channel = dsi->update_channel;
  2095. u8 bit = dsi->te_enabled ? 30 : 31;
  2096. if (REG_GET(vp_data->dsidev, DSI_VC_TE(channel), bit, bit) == 0)
  2097. complete(vp_data->completion);
  2098. }
  2099. static int dsi_sync_vc_vp(struct platform_device *dsidev, int channel)
  2100. {
  2101. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2102. DECLARE_COMPLETION_ONSTACK(completion);
  2103. struct dsi_packet_sent_handler_data vp_data = { dsidev, &completion };
  2104. int r = 0;
  2105. u8 bit;
  2106. bit = dsi->te_enabled ? 30 : 31;
  2107. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2108. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2109. if (r)
  2110. goto err0;
  2111. /* Wait for completion only if TE_EN/TE_START is still set */
  2112. if (REG_GET(dsidev, DSI_VC_TE(channel), bit, bit)) {
  2113. if (wait_for_completion_timeout(&completion,
  2114. msecs_to_jiffies(10)) == 0) {
  2115. DSSERR("Failed to complete previous frame transfer\n");
  2116. r = -EIO;
  2117. goto err1;
  2118. }
  2119. }
  2120. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2121. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2122. return 0;
  2123. err1:
  2124. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_vp,
  2125. &vp_data, DSI_VC_IRQ_PACKET_SENT);
  2126. err0:
  2127. return r;
  2128. }
  2129. static void dsi_packet_sent_handler_l4(void *data, u32 mask)
  2130. {
  2131. struct dsi_packet_sent_handler_data *l4_data =
  2132. (struct dsi_packet_sent_handler_data *) data;
  2133. struct dsi_data *dsi = dsi_get_dsidrv_data(l4_data->dsidev);
  2134. const int channel = dsi->update_channel;
  2135. if (REG_GET(l4_data->dsidev, DSI_VC_CTRL(channel), 5, 5) == 0)
  2136. complete(l4_data->completion);
  2137. }
  2138. static int dsi_sync_vc_l4(struct platform_device *dsidev, int channel)
  2139. {
  2140. DECLARE_COMPLETION_ONSTACK(completion);
  2141. struct dsi_packet_sent_handler_data l4_data = { dsidev, &completion };
  2142. int r = 0;
  2143. r = dsi_register_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2144. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2145. if (r)
  2146. goto err0;
  2147. /* Wait for completion only if TX_FIFO_NOT_EMPTY is still set */
  2148. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 5, 5)) {
  2149. if (wait_for_completion_timeout(&completion,
  2150. msecs_to_jiffies(10)) == 0) {
  2151. DSSERR("Failed to complete previous l4 transfer\n");
  2152. r = -EIO;
  2153. goto err1;
  2154. }
  2155. }
  2156. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2157. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2158. return 0;
  2159. err1:
  2160. dsi_unregister_isr_vc(dsidev, channel, dsi_packet_sent_handler_l4,
  2161. &l4_data, DSI_VC_IRQ_PACKET_SENT);
  2162. err0:
  2163. return r;
  2164. }
  2165. static int dsi_sync_vc(struct platform_device *dsidev, int channel)
  2166. {
  2167. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2168. WARN_ON(!dsi_bus_is_locked(dsidev));
  2169. WARN_ON(in_interrupt());
  2170. if (!dsi_vc_is_enabled(dsidev, channel))
  2171. return 0;
  2172. switch (dsi->vc[channel].mode) {
  2173. case DSI_VC_MODE_VP:
  2174. return dsi_sync_vc_vp(dsidev, channel);
  2175. case DSI_VC_MODE_L4:
  2176. return dsi_sync_vc_l4(dsidev, channel);
  2177. default:
  2178. BUG();
  2179. }
  2180. }
  2181. static int dsi_vc_enable(struct platform_device *dsidev, int channel,
  2182. bool enable)
  2183. {
  2184. DSSDBG("dsi_vc_enable channel %d, enable %d\n",
  2185. channel, enable);
  2186. enable = enable ? 1 : 0;
  2187. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 0, 0);
  2188. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel),
  2189. 0, enable) != enable) {
  2190. DSSERR("Failed to set dsi_vc_enable to %d\n", enable);
  2191. return -EIO;
  2192. }
  2193. return 0;
  2194. }
  2195. static void dsi_vc_initial_config(struct platform_device *dsidev, int channel)
  2196. {
  2197. u32 r;
  2198. DSSDBGF("%d", channel);
  2199. r = dsi_read_reg(dsidev, DSI_VC_CTRL(channel));
  2200. if (FLD_GET(r, 15, 15)) /* VC_BUSY */
  2201. DSSERR("VC(%d) busy when trying to configure it!\n",
  2202. channel);
  2203. r = FLD_MOD(r, 0, 1, 1); /* SOURCE, 0 = L4 */
  2204. r = FLD_MOD(r, 0, 2, 2); /* BTA_SHORT_EN */
  2205. r = FLD_MOD(r, 0, 3, 3); /* BTA_LONG_EN */
  2206. r = FLD_MOD(r, 0, 4, 4); /* MODE, 0 = command */
  2207. r = FLD_MOD(r, 1, 7, 7); /* CS_TX_EN */
  2208. r = FLD_MOD(r, 1, 8, 8); /* ECC_TX_EN */
  2209. r = FLD_MOD(r, 0, 9, 9); /* MODE_SPEED, high speed on/off */
  2210. if (dss_has_feature(FEAT_DSI_VC_OCP_WIDTH))
  2211. r = FLD_MOD(r, 3, 11, 10); /* OCP_WIDTH = 32 bit */
  2212. r = FLD_MOD(r, 4, 29, 27); /* DMA_RX_REQ_NB = no dma */
  2213. r = FLD_MOD(r, 4, 23, 21); /* DMA_TX_REQ_NB = no dma */
  2214. dsi_write_reg(dsidev, DSI_VC_CTRL(channel), r);
  2215. }
  2216. static int dsi_vc_config_l4(struct platform_device *dsidev, int channel)
  2217. {
  2218. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2219. if (dsi->vc[channel].mode == DSI_VC_MODE_L4)
  2220. return 0;
  2221. DSSDBGF("%d", channel);
  2222. dsi_sync_vc(dsidev, channel);
  2223. dsi_vc_enable(dsidev, channel, 0);
  2224. /* VC_BUSY */
  2225. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
  2226. DSSERR("vc(%d) busy when trying to config for L4\n", channel);
  2227. return -EIO;
  2228. }
  2229. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 1, 1); /* SOURCE, 0 = L4 */
  2230. /* DCS_CMD_ENABLE */
  2231. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
  2232. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 0, 30, 30);
  2233. dsi_vc_enable(dsidev, channel, 1);
  2234. dsi->vc[channel].mode = DSI_VC_MODE_L4;
  2235. return 0;
  2236. }
  2237. static int dsi_vc_config_vp(struct platform_device *dsidev, int channel)
  2238. {
  2239. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2240. if (dsi->vc[channel].mode == DSI_VC_MODE_VP)
  2241. return 0;
  2242. DSSDBGF("%d", channel);
  2243. dsi_sync_vc(dsidev, channel);
  2244. dsi_vc_enable(dsidev, channel, 0);
  2245. /* VC_BUSY */
  2246. if (wait_for_bit_change(dsidev, DSI_VC_CTRL(channel), 15, 0) != 0) {
  2247. DSSERR("vc(%d) busy when trying to config for VP\n", channel);
  2248. return -EIO;
  2249. }
  2250. /* SOURCE, 1 = video port */
  2251. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 1, 1);
  2252. /* DCS_CMD_ENABLE */
  2253. if (dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC))
  2254. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 30, 30);
  2255. dsi_vc_enable(dsidev, channel, 1);
  2256. dsi->vc[channel].mode = DSI_VC_MODE_VP;
  2257. return 0;
  2258. }
  2259. void omapdss_dsi_vc_enable_hs(struct omap_dss_device *dssdev, int channel,
  2260. bool enable)
  2261. {
  2262. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2263. DSSDBG("dsi_vc_enable_hs(%d, %d)\n", channel, enable);
  2264. WARN_ON(!dsi_bus_is_locked(dsidev));
  2265. dsi_vc_enable(dsidev, channel, 0);
  2266. dsi_if_enable(dsidev, 0);
  2267. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), enable, 9, 9);
  2268. dsi_vc_enable(dsidev, channel, 1);
  2269. dsi_if_enable(dsidev, 1);
  2270. dsi_force_tx_stop_mode_io(dsidev);
  2271. }
  2272. EXPORT_SYMBOL(omapdss_dsi_vc_enable_hs);
  2273. static void dsi_vc_flush_long_data(struct platform_device *dsidev, int channel)
  2274. {
  2275. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2276. u32 val;
  2277. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2278. DSSDBG("\t\tb1 %#02x b2 %#02x b3 %#02x b4 %#02x\n",
  2279. (val >> 0) & 0xff,
  2280. (val >> 8) & 0xff,
  2281. (val >> 16) & 0xff,
  2282. (val >> 24) & 0xff);
  2283. }
  2284. }
  2285. static void dsi_show_rx_ack_with_err(u16 err)
  2286. {
  2287. DSSERR("\tACK with ERROR (%#x):\n", err);
  2288. if (err & (1 << 0))
  2289. DSSERR("\t\tSoT Error\n");
  2290. if (err & (1 << 1))
  2291. DSSERR("\t\tSoT Sync Error\n");
  2292. if (err & (1 << 2))
  2293. DSSERR("\t\tEoT Sync Error\n");
  2294. if (err & (1 << 3))
  2295. DSSERR("\t\tEscape Mode Entry Command Error\n");
  2296. if (err & (1 << 4))
  2297. DSSERR("\t\tLP Transmit Sync Error\n");
  2298. if (err & (1 << 5))
  2299. DSSERR("\t\tHS Receive Timeout Error\n");
  2300. if (err & (1 << 6))
  2301. DSSERR("\t\tFalse Control Error\n");
  2302. if (err & (1 << 7))
  2303. DSSERR("\t\t(reserved7)\n");
  2304. if (err & (1 << 8))
  2305. DSSERR("\t\tECC Error, single-bit (corrected)\n");
  2306. if (err & (1 << 9))
  2307. DSSERR("\t\tECC Error, multi-bit (not corrected)\n");
  2308. if (err & (1 << 10))
  2309. DSSERR("\t\tChecksum Error\n");
  2310. if (err & (1 << 11))
  2311. DSSERR("\t\tData type not recognized\n");
  2312. if (err & (1 << 12))
  2313. DSSERR("\t\tInvalid VC ID\n");
  2314. if (err & (1 << 13))
  2315. DSSERR("\t\tInvalid Transmission Length\n");
  2316. if (err & (1 << 14))
  2317. DSSERR("\t\t(reserved14)\n");
  2318. if (err & (1 << 15))
  2319. DSSERR("\t\tDSI Protocol Violation\n");
  2320. }
  2321. static u16 dsi_vc_flush_receive_data(struct platform_device *dsidev,
  2322. int channel)
  2323. {
  2324. /* RX_FIFO_NOT_EMPTY */
  2325. while (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2326. u32 val;
  2327. u8 dt;
  2328. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2329. DSSERR("\trawval %#08x\n", val);
  2330. dt = FLD_GET(val, 5, 0);
  2331. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2332. u16 err = FLD_GET(val, 23, 8);
  2333. dsi_show_rx_ack_with_err(err);
  2334. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2335. DSSERR("\tDCS short response, 1 byte: %#x\n",
  2336. FLD_GET(val, 23, 8));
  2337. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2338. DSSERR("\tDCS short response, 2 byte: %#x\n",
  2339. FLD_GET(val, 23, 8));
  2340. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  2341. DSSERR("\tDCS long response, len %d\n",
  2342. FLD_GET(val, 23, 8));
  2343. dsi_vc_flush_long_data(dsidev, channel);
  2344. } else {
  2345. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2346. }
  2347. }
  2348. return 0;
  2349. }
  2350. static int dsi_vc_send_bta(struct platform_device *dsidev, int channel)
  2351. {
  2352. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2353. if (dsi->debug_write || dsi->debug_read)
  2354. DSSDBG("dsi_vc_send_bta %d\n", channel);
  2355. WARN_ON(!dsi_bus_is_locked(dsidev));
  2356. /* RX_FIFO_NOT_EMPTY */
  2357. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2358. DSSERR("rx fifo not empty when sending BTA, dumping data:\n");
  2359. dsi_vc_flush_receive_data(dsidev, channel);
  2360. }
  2361. REG_FLD_MOD(dsidev, DSI_VC_CTRL(channel), 1, 6, 6); /* BTA_EN */
  2362. return 0;
  2363. }
  2364. int dsi_vc_send_bta_sync(struct omap_dss_device *dssdev, int channel)
  2365. {
  2366. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2367. DECLARE_COMPLETION_ONSTACK(completion);
  2368. int r = 0;
  2369. u32 err;
  2370. r = dsi_register_isr_vc(dsidev, channel, dsi_completion_handler,
  2371. &completion, DSI_VC_IRQ_BTA);
  2372. if (r)
  2373. goto err0;
  2374. r = dsi_register_isr(dsidev, dsi_completion_handler, &completion,
  2375. DSI_IRQ_ERROR_MASK);
  2376. if (r)
  2377. goto err1;
  2378. r = dsi_vc_send_bta(dsidev, channel);
  2379. if (r)
  2380. goto err2;
  2381. if (wait_for_completion_timeout(&completion,
  2382. msecs_to_jiffies(500)) == 0) {
  2383. DSSERR("Failed to receive BTA\n");
  2384. r = -EIO;
  2385. goto err2;
  2386. }
  2387. err = dsi_get_errors(dsidev);
  2388. if (err) {
  2389. DSSERR("Error while sending BTA: %x\n", err);
  2390. r = -EIO;
  2391. goto err2;
  2392. }
  2393. err2:
  2394. dsi_unregister_isr(dsidev, dsi_completion_handler, &completion,
  2395. DSI_IRQ_ERROR_MASK);
  2396. err1:
  2397. dsi_unregister_isr_vc(dsidev, channel, dsi_completion_handler,
  2398. &completion, DSI_VC_IRQ_BTA);
  2399. err0:
  2400. return r;
  2401. }
  2402. EXPORT_SYMBOL(dsi_vc_send_bta_sync);
  2403. static inline void dsi_vc_write_long_header(struct platform_device *dsidev,
  2404. int channel, u8 data_type, u16 len, u8 ecc)
  2405. {
  2406. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2407. u32 val;
  2408. u8 data_id;
  2409. WARN_ON(!dsi_bus_is_locked(dsidev));
  2410. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2411. val = FLD_VAL(data_id, 7, 0) | FLD_VAL(len, 23, 8) |
  2412. FLD_VAL(ecc, 31, 24);
  2413. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_HEADER(channel), val);
  2414. }
  2415. static inline void dsi_vc_write_long_payload(struct platform_device *dsidev,
  2416. int channel, u8 b1, u8 b2, u8 b3, u8 b4)
  2417. {
  2418. u32 val;
  2419. val = b4 << 24 | b3 << 16 | b2 << 8 | b1 << 0;
  2420. /* DSSDBG("\twriting %02x, %02x, %02x, %02x (%#010x)\n",
  2421. b1, b2, b3, b4, val); */
  2422. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(channel), val);
  2423. }
  2424. static int dsi_vc_send_long(struct platform_device *dsidev, int channel,
  2425. u8 data_type, u8 *data, u16 len, u8 ecc)
  2426. {
  2427. /*u32 val; */
  2428. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2429. int i;
  2430. u8 *p;
  2431. int r = 0;
  2432. u8 b1, b2, b3, b4;
  2433. if (dsi->debug_write)
  2434. DSSDBG("dsi_vc_send_long, %d bytes\n", len);
  2435. /* len + header */
  2436. if (dsi->vc[channel].fifo_size * 32 * 4 < len + 4) {
  2437. DSSERR("unable to send long packet: packet too long.\n");
  2438. return -EINVAL;
  2439. }
  2440. dsi_vc_config_l4(dsidev, channel);
  2441. dsi_vc_write_long_header(dsidev, channel, data_type, len, ecc);
  2442. p = data;
  2443. for (i = 0; i < len >> 2; i++) {
  2444. if (dsi->debug_write)
  2445. DSSDBG("\tsending full packet %d\n", i);
  2446. b1 = *p++;
  2447. b2 = *p++;
  2448. b3 = *p++;
  2449. b4 = *p++;
  2450. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, b4);
  2451. }
  2452. i = len % 4;
  2453. if (i) {
  2454. b1 = 0; b2 = 0; b3 = 0;
  2455. if (dsi->debug_write)
  2456. DSSDBG("\tsending remainder bytes %d\n", i);
  2457. switch (i) {
  2458. case 3:
  2459. b1 = *p++;
  2460. b2 = *p++;
  2461. b3 = *p++;
  2462. break;
  2463. case 2:
  2464. b1 = *p++;
  2465. b2 = *p++;
  2466. break;
  2467. case 1:
  2468. b1 = *p++;
  2469. break;
  2470. }
  2471. dsi_vc_write_long_payload(dsidev, channel, b1, b2, b3, 0);
  2472. }
  2473. return r;
  2474. }
  2475. static int dsi_vc_send_short(struct platform_device *dsidev, int channel,
  2476. u8 data_type, u16 data, u8 ecc)
  2477. {
  2478. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2479. u32 r;
  2480. u8 data_id;
  2481. WARN_ON(!dsi_bus_is_locked(dsidev));
  2482. if (dsi->debug_write)
  2483. DSSDBG("dsi_vc_send_short(ch%d, dt %#x, b1 %#x, b2 %#x)\n",
  2484. channel,
  2485. data_type, data & 0xff, (data >> 8) & 0xff);
  2486. dsi_vc_config_l4(dsidev, channel);
  2487. if (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(channel)), 16, 16)) {
  2488. DSSERR("ERROR FIFO FULL, aborting transfer\n");
  2489. return -EINVAL;
  2490. }
  2491. data_id = data_type | dsi->vc[channel].vc_id << 6;
  2492. r = (data_id << 0) | (data << 8) | (ecc << 24);
  2493. dsi_write_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel), r);
  2494. return 0;
  2495. }
  2496. int dsi_vc_send_null(struct omap_dss_device *dssdev, int channel)
  2497. {
  2498. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2499. u8 nullpkg[] = {0, 0, 0, 0};
  2500. return dsi_vc_send_long(dsidev, channel, DSI_DT_NULL_PACKET, nullpkg,
  2501. 4, 0);
  2502. }
  2503. EXPORT_SYMBOL(dsi_vc_send_null);
  2504. int dsi_vc_dcs_write_nosync(struct omap_dss_device *dssdev, int channel,
  2505. u8 *data, int len)
  2506. {
  2507. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2508. int r;
  2509. BUG_ON(len == 0);
  2510. if (len == 1) {
  2511. r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_0,
  2512. data[0], 0);
  2513. } else if (len == 2) {
  2514. r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_SHORT_WRITE_1,
  2515. data[0] | (data[1] << 8), 0);
  2516. } else {
  2517. /* 0x39 = DCS Long Write */
  2518. r = dsi_vc_send_long(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
  2519. data, len, 0);
  2520. }
  2521. return r;
  2522. }
  2523. EXPORT_SYMBOL(dsi_vc_dcs_write_nosync);
  2524. int dsi_vc_dcs_write(struct omap_dss_device *dssdev, int channel, u8 *data,
  2525. int len)
  2526. {
  2527. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2528. int r;
  2529. r = dsi_vc_dcs_write_nosync(dssdev, channel, data, len);
  2530. if (r)
  2531. goto err;
  2532. r = dsi_vc_send_bta_sync(dssdev, channel);
  2533. if (r)
  2534. goto err;
  2535. /* RX_FIFO_NOT_EMPTY */
  2536. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20)) {
  2537. DSSERR("rx fifo not empty after write, dumping data:\n");
  2538. dsi_vc_flush_receive_data(dsidev, channel);
  2539. r = -EIO;
  2540. goto err;
  2541. }
  2542. return 0;
  2543. err:
  2544. DSSERR("dsi_vc_dcs_write(ch %d, cmd 0x%02x, len %d) failed\n",
  2545. channel, data[0], len);
  2546. return r;
  2547. }
  2548. EXPORT_SYMBOL(dsi_vc_dcs_write);
  2549. int dsi_vc_dcs_write_0(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd)
  2550. {
  2551. return dsi_vc_dcs_write(dssdev, channel, &dcs_cmd, 1);
  2552. }
  2553. EXPORT_SYMBOL(dsi_vc_dcs_write_0);
  2554. int dsi_vc_dcs_write_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2555. u8 param)
  2556. {
  2557. u8 buf[2];
  2558. buf[0] = dcs_cmd;
  2559. buf[1] = param;
  2560. return dsi_vc_dcs_write(dssdev, channel, buf, 2);
  2561. }
  2562. EXPORT_SYMBOL(dsi_vc_dcs_write_1);
  2563. int dsi_vc_dcs_read(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2564. u8 *buf, int buflen)
  2565. {
  2566. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2567. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2568. u32 val;
  2569. u8 dt;
  2570. int r;
  2571. if (dsi->debug_read)
  2572. DSSDBG("dsi_vc_dcs_read(ch%d, dcs_cmd %x)\n", channel, dcs_cmd);
  2573. r = dsi_vc_send_short(dsidev, channel, DSI_DT_DCS_READ, dcs_cmd, 0);
  2574. if (r)
  2575. goto err;
  2576. r = dsi_vc_send_bta_sync(dssdev, channel);
  2577. if (r)
  2578. goto err;
  2579. /* RX_FIFO_NOT_EMPTY */
  2580. if (REG_GET(dsidev, DSI_VC_CTRL(channel), 20, 20) == 0) {
  2581. DSSERR("RX fifo empty when trying to read.\n");
  2582. r = -EIO;
  2583. goto err;
  2584. }
  2585. val = dsi_read_reg(dsidev, DSI_VC_SHORT_PACKET_HEADER(channel));
  2586. if (dsi->debug_read)
  2587. DSSDBG("\theader: %08x\n", val);
  2588. dt = FLD_GET(val, 5, 0);
  2589. if (dt == DSI_DT_RX_ACK_WITH_ERR) {
  2590. u16 err = FLD_GET(val, 23, 8);
  2591. dsi_show_rx_ack_with_err(err);
  2592. r = -EIO;
  2593. goto err;
  2594. } else if (dt == DSI_DT_RX_SHORT_READ_1) {
  2595. u8 data = FLD_GET(val, 15, 8);
  2596. if (dsi->debug_read)
  2597. DSSDBG("\tDCS short response, 1 byte: %02x\n", data);
  2598. if (buflen < 1) {
  2599. r = -EIO;
  2600. goto err;
  2601. }
  2602. buf[0] = data;
  2603. return 1;
  2604. } else if (dt == DSI_DT_RX_SHORT_READ_2) {
  2605. u16 data = FLD_GET(val, 23, 8);
  2606. if (dsi->debug_read)
  2607. DSSDBG("\tDCS short response, 2 byte: %04x\n", data);
  2608. if (buflen < 2) {
  2609. r = -EIO;
  2610. goto err;
  2611. }
  2612. buf[0] = data & 0xff;
  2613. buf[1] = (data >> 8) & 0xff;
  2614. return 2;
  2615. } else if (dt == DSI_DT_RX_DCS_LONG_READ) {
  2616. int w;
  2617. int len = FLD_GET(val, 23, 8);
  2618. if (dsi->debug_read)
  2619. DSSDBG("\tDCS long response, len %d\n", len);
  2620. if (len > buflen) {
  2621. r = -EIO;
  2622. goto err;
  2623. }
  2624. /* two byte checksum ends the packet, not included in len */
  2625. for (w = 0; w < len + 2;) {
  2626. int b;
  2627. val = dsi_read_reg(dsidev,
  2628. DSI_VC_SHORT_PACKET_HEADER(channel));
  2629. if (dsi->debug_read)
  2630. DSSDBG("\t\t%02x %02x %02x %02x\n",
  2631. (val >> 0) & 0xff,
  2632. (val >> 8) & 0xff,
  2633. (val >> 16) & 0xff,
  2634. (val >> 24) & 0xff);
  2635. for (b = 0; b < 4; ++b) {
  2636. if (w < len)
  2637. buf[w] = (val >> (b * 8)) & 0xff;
  2638. /* we discard the 2 byte checksum */
  2639. ++w;
  2640. }
  2641. }
  2642. return len;
  2643. } else {
  2644. DSSERR("\tunknown datatype 0x%02x\n", dt);
  2645. r = -EIO;
  2646. goto err;
  2647. }
  2648. BUG();
  2649. err:
  2650. DSSERR("dsi_vc_dcs_read(ch %d, cmd 0x%02x) failed\n",
  2651. channel, dcs_cmd);
  2652. return r;
  2653. }
  2654. EXPORT_SYMBOL(dsi_vc_dcs_read);
  2655. int dsi_vc_dcs_read_1(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2656. u8 *data)
  2657. {
  2658. int r;
  2659. r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, data, 1);
  2660. if (r < 0)
  2661. return r;
  2662. if (r != 1)
  2663. return -EIO;
  2664. return 0;
  2665. }
  2666. EXPORT_SYMBOL(dsi_vc_dcs_read_1);
  2667. int dsi_vc_dcs_read_2(struct omap_dss_device *dssdev, int channel, u8 dcs_cmd,
  2668. u8 *data1, u8 *data2)
  2669. {
  2670. u8 buf[2];
  2671. int r;
  2672. r = dsi_vc_dcs_read(dssdev, channel, dcs_cmd, buf, 2);
  2673. if (r < 0)
  2674. return r;
  2675. if (r != 2)
  2676. return -EIO;
  2677. *data1 = buf[0];
  2678. *data2 = buf[1];
  2679. return 0;
  2680. }
  2681. EXPORT_SYMBOL(dsi_vc_dcs_read_2);
  2682. int dsi_vc_set_max_rx_packet_size(struct omap_dss_device *dssdev, int channel,
  2683. u16 len)
  2684. {
  2685. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2686. return dsi_vc_send_short(dsidev, channel, DSI_DT_SET_MAX_RET_PKG_SIZE,
  2687. len, 0);
  2688. }
  2689. EXPORT_SYMBOL(dsi_vc_set_max_rx_packet_size);
  2690. static int dsi_enter_ulps(struct platform_device *dsidev)
  2691. {
  2692. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2693. DECLARE_COMPLETION_ONSTACK(completion);
  2694. int r;
  2695. DSSDBGF();
  2696. WARN_ON(!dsi_bus_is_locked(dsidev));
  2697. WARN_ON(dsi->ulps_enabled);
  2698. if (dsi->ulps_enabled)
  2699. return 0;
  2700. if (REG_GET(dsidev, DSI_CLK_CTRL, 13, 13)) {
  2701. DSSERR("DDR_CLK_ALWAYS_ON enabled when entering ULPS\n");
  2702. return -EIO;
  2703. }
  2704. dsi_sync_vc(dsidev, 0);
  2705. dsi_sync_vc(dsidev, 1);
  2706. dsi_sync_vc(dsidev, 2);
  2707. dsi_sync_vc(dsidev, 3);
  2708. dsi_force_tx_stop_mode_io(dsidev);
  2709. dsi_vc_enable(dsidev, 0, false);
  2710. dsi_vc_enable(dsidev, 1, false);
  2711. dsi_vc_enable(dsidev, 2, false);
  2712. dsi_vc_enable(dsidev, 3, false);
  2713. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 16, 16)) { /* HS_BUSY */
  2714. DSSERR("HS busy when enabling ULPS\n");
  2715. return -EIO;
  2716. }
  2717. if (REG_GET(dsidev, DSI_COMPLEXIO_CFG2, 17, 17)) { /* LP_BUSY */
  2718. DSSERR("LP busy when enabling ULPS\n");
  2719. return -EIO;
  2720. }
  2721. r = dsi_register_isr_cio(dsidev, dsi_completion_handler, &completion,
  2722. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2723. if (r)
  2724. return r;
  2725. /* Assert TxRequestEsc for data lanes and TxUlpsClk for clk lane */
  2726. /* LANEx_ULPS_SIG2 */
  2727. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (1 << 0) | (1 << 1) | (1 << 2),
  2728. 7, 5);
  2729. if (wait_for_completion_timeout(&completion,
  2730. msecs_to_jiffies(1000)) == 0) {
  2731. DSSERR("ULPS enable timeout\n");
  2732. r = -EIO;
  2733. goto err;
  2734. }
  2735. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2736. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2737. /* Reset LANEx_ULPS_SIG2 */
  2738. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG2, (0 << 0) | (0 << 1) | (0 << 2),
  2739. 7, 5);
  2740. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ULPS);
  2741. dsi_if_enable(dsidev, false);
  2742. dsi->ulps_enabled = true;
  2743. return 0;
  2744. err:
  2745. dsi_unregister_isr_cio(dsidev, dsi_completion_handler, &completion,
  2746. DSI_CIO_IRQ_ULPSACTIVENOT_ALL0);
  2747. return r;
  2748. }
  2749. static void dsi_set_lp_rx_timeout(struct platform_device *dsidev,
  2750. unsigned ticks, bool x4, bool x16)
  2751. {
  2752. unsigned long fck;
  2753. unsigned long total_ticks;
  2754. u32 r;
  2755. BUG_ON(ticks > 0x1fff);
  2756. /* ticks in DSI_FCK */
  2757. fck = dsi_fclk_rate(dsidev);
  2758. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2759. r = FLD_MOD(r, 1, 15, 15); /* LP_RX_TO */
  2760. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* LP_RX_TO_X16 */
  2761. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* LP_RX_TO_X4 */
  2762. r = FLD_MOD(r, ticks, 12, 0); /* LP_RX_COUNTER */
  2763. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2764. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2765. DSSDBG("LP_RX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2766. total_ticks,
  2767. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2768. (total_ticks * 1000) / (fck / 1000 / 1000));
  2769. }
  2770. static void dsi_set_ta_timeout(struct platform_device *dsidev, unsigned ticks,
  2771. bool x8, bool x16)
  2772. {
  2773. unsigned long fck;
  2774. unsigned long total_ticks;
  2775. u32 r;
  2776. BUG_ON(ticks > 0x1fff);
  2777. /* ticks in DSI_FCK */
  2778. fck = dsi_fclk_rate(dsidev);
  2779. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2780. r = FLD_MOD(r, 1, 31, 31); /* TA_TO */
  2781. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* TA_TO_X16 */
  2782. r = FLD_MOD(r, x8 ? 1 : 0, 29, 29); /* TA_TO_X8 */
  2783. r = FLD_MOD(r, ticks, 28, 16); /* TA_TO_COUNTER */
  2784. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2785. total_ticks = ticks * (x16 ? 16 : 1) * (x8 ? 8 : 1);
  2786. DSSDBG("TA_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2787. total_ticks,
  2788. ticks, x8 ? " x8" : "", x16 ? " x16" : "",
  2789. (total_ticks * 1000) / (fck / 1000 / 1000));
  2790. }
  2791. static void dsi_set_stop_state_counter(struct platform_device *dsidev,
  2792. unsigned ticks, bool x4, bool x16)
  2793. {
  2794. unsigned long fck;
  2795. unsigned long total_ticks;
  2796. u32 r;
  2797. BUG_ON(ticks > 0x1fff);
  2798. /* ticks in DSI_FCK */
  2799. fck = dsi_fclk_rate(dsidev);
  2800. r = dsi_read_reg(dsidev, DSI_TIMING1);
  2801. r = FLD_MOD(r, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  2802. r = FLD_MOD(r, x16 ? 1 : 0, 14, 14); /* STOP_STATE_X16_IO */
  2803. r = FLD_MOD(r, x4 ? 1 : 0, 13, 13); /* STOP_STATE_X4_IO */
  2804. r = FLD_MOD(r, ticks, 12, 0); /* STOP_STATE_COUNTER_IO */
  2805. dsi_write_reg(dsidev, DSI_TIMING1, r);
  2806. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2807. DSSDBG("STOP_STATE_COUNTER %lu ticks (%#x%s%s) = %lu ns\n",
  2808. total_ticks,
  2809. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2810. (total_ticks * 1000) / (fck / 1000 / 1000));
  2811. }
  2812. static void dsi_set_hs_tx_timeout(struct platform_device *dsidev,
  2813. unsigned ticks, bool x4, bool x16)
  2814. {
  2815. unsigned long fck;
  2816. unsigned long total_ticks;
  2817. u32 r;
  2818. BUG_ON(ticks > 0x1fff);
  2819. /* ticks in TxByteClkHS */
  2820. fck = dsi_get_txbyteclkhs(dsidev);
  2821. r = dsi_read_reg(dsidev, DSI_TIMING2);
  2822. r = FLD_MOD(r, 1, 31, 31); /* HS_TX_TO */
  2823. r = FLD_MOD(r, x16 ? 1 : 0, 30, 30); /* HS_TX_TO_X16 */
  2824. r = FLD_MOD(r, x4 ? 1 : 0, 29, 29); /* HS_TX_TO_X8 (4 really) */
  2825. r = FLD_MOD(r, ticks, 28, 16); /* HS_TX_TO_COUNTER */
  2826. dsi_write_reg(dsidev, DSI_TIMING2, r);
  2827. total_ticks = ticks * (x16 ? 16 : 1) * (x4 ? 4 : 1);
  2828. DSSDBG("HS_TX_TO %lu ticks (%#x%s%s) = %lu ns\n",
  2829. total_ticks,
  2830. ticks, x4 ? " x4" : "", x16 ? " x16" : "",
  2831. (total_ticks * 1000) / (fck / 1000 / 1000));
  2832. }
  2833. static int dsi_proto_config(struct omap_dss_device *dssdev)
  2834. {
  2835. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2836. u32 r;
  2837. int buswidth = 0;
  2838. dsi_config_tx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2839. DSI_FIFO_SIZE_32,
  2840. DSI_FIFO_SIZE_32,
  2841. DSI_FIFO_SIZE_32);
  2842. dsi_config_rx_fifo(dsidev, DSI_FIFO_SIZE_32,
  2843. DSI_FIFO_SIZE_32,
  2844. DSI_FIFO_SIZE_32,
  2845. DSI_FIFO_SIZE_32);
  2846. /* XXX what values for the timeouts? */
  2847. dsi_set_stop_state_counter(dsidev, 0x1000, false, false);
  2848. dsi_set_ta_timeout(dsidev, 0x1fff, true, true);
  2849. dsi_set_lp_rx_timeout(dsidev, 0x1fff, true, true);
  2850. dsi_set_hs_tx_timeout(dsidev, 0x1fff, true, true);
  2851. switch (dssdev->ctrl.pixel_size) {
  2852. case 16:
  2853. buswidth = 0;
  2854. break;
  2855. case 18:
  2856. buswidth = 1;
  2857. break;
  2858. case 24:
  2859. buswidth = 2;
  2860. break;
  2861. default:
  2862. BUG();
  2863. }
  2864. r = dsi_read_reg(dsidev, DSI_CTRL);
  2865. r = FLD_MOD(r, 1, 1, 1); /* CS_RX_EN */
  2866. r = FLD_MOD(r, 1, 2, 2); /* ECC_RX_EN */
  2867. r = FLD_MOD(r, 1, 3, 3); /* TX_FIFO_ARBITRATION */
  2868. r = FLD_MOD(r, 1, 4, 4); /* VP_CLK_RATIO, always 1, see errata*/
  2869. r = FLD_MOD(r, buswidth, 7, 6); /* VP_DATA_BUS_WIDTH */
  2870. r = FLD_MOD(r, 0, 8, 8); /* VP_CLK_POL */
  2871. r = FLD_MOD(r, 2, 13, 12); /* LINE_BUFFER, 2 lines */
  2872. r = FLD_MOD(r, 1, 14, 14); /* TRIGGER_RESET_MODE */
  2873. r = FLD_MOD(r, 1, 19, 19); /* EOT_ENABLE */
  2874. if (!dss_has_feature(FEAT_DSI_DCS_CMD_CONFIG_VC)) {
  2875. r = FLD_MOD(r, 1, 24, 24); /* DCS_CMD_ENABLE */
  2876. /* DCS_CMD_CODE, 1=start, 0=continue */
  2877. r = FLD_MOD(r, 0, 25, 25);
  2878. }
  2879. dsi_write_reg(dsidev, DSI_CTRL, r);
  2880. dsi_vc_initial_config(dsidev, 0);
  2881. dsi_vc_initial_config(dsidev, 1);
  2882. dsi_vc_initial_config(dsidev, 2);
  2883. dsi_vc_initial_config(dsidev, 3);
  2884. return 0;
  2885. }
  2886. static void dsi_proto_timings(struct omap_dss_device *dssdev)
  2887. {
  2888. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2889. unsigned tlpx, tclk_zero, tclk_prepare, tclk_trail;
  2890. unsigned tclk_pre, tclk_post;
  2891. unsigned ths_prepare, ths_prepare_ths_zero, ths_zero;
  2892. unsigned ths_trail, ths_exit;
  2893. unsigned ddr_clk_pre, ddr_clk_post;
  2894. unsigned enter_hs_mode_lat, exit_hs_mode_lat;
  2895. unsigned ths_eot;
  2896. u32 r;
  2897. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  2898. ths_prepare = FLD_GET(r, 31, 24);
  2899. ths_prepare_ths_zero = FLD_GET(r, 23, 16);
  2900. ths_zero = ths_prepare_ths_zero - ths_prepare;
  2901. ths_trail = FLD_GET(r, 15, 8);
  2902. ths_exit = FLD_GET(r, 7, 0);
  2903. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  2904. tlpx = FLD_GET(r, 22, 16) * 2;
  2905. tclk_trail = FLD_GET(r, 15, 8);
  2906. tclk_zero = FLD_GET(r, 7, 0);
  2907. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  2908. tclk_prepare = FLD_GET(r, 7, 0);
  2909. /* min 8*UI */
  2910. tclk_pre = 20;
  2911. /* min 60ns + 52*UI */
  2912. tclk_post = ns2ddr(dsidev, 60) + 26;
  2913. ths_eot = DIV_ROUND_UP(4, dsi_get_num_data_lanes_dssdev(dssdev));
  2914. ddr_clk_pre = DIV_ROUND_UP(tclk_pre + tlpx + tclk_zero + tclk_prepare,
  2915. 4);
  2916. ddr_clk_post = DIV_ROUND_UP(tclk_post + ths_trail, 4) + ths_eot;
  2917. BUG_ON(ddr_clk_pre == 0 || ddr_clk_pre > 255);
  2918. BUG_ON(ddr_clk_post == 0 || ddr_clk_post > 255);
  2919. r = dsi_read_reg(dsidev, DSI_CLK_TIMING);
  2920. r = FLD_MOD(r, ddr_clk_pre, 15, 8);
  2921. r = FLD_MOD(r, ddr_clk_post, 7, 0);
  2922. dsi_write_reg(dsidev, DSI_CLK_TIMING, r);
  2923. DSSDBG("ddr_clk_pre %u, ddr_clk_post %u\n",
  2924. ddr_clk_pre,
  2925. ddr_clk_post);
  2926. enter_hs_mode_lat = 1 + DIV_ROUND_UP(tlpx, 4) +
  2927. DIV_ROUND_UP(ths_prepare, 4) +
  2928. DIV_ROUND_UP(ths_zero + 3, 4);
  2929. exit_hs_mode_lat = DIV_ROUND_UP(ths_trail + ths_exit, 4) + 1 + ths_eot;
  2930. r = FLD_VAL(enter_hs_mode_lat, 31, 16) |
  2931. FLD_VAL(exit_hs_mode_lat, 15, 0);
  2932. dsi_write_reg(dsidev, DSI_VM_TIMING7, r);
  2933. DSSDBG("enter_hs_mode_lat %u, exit_hs_mode_lat %u\n",
  2934. enter_hs_mode_lat, exit_hs_mode_lat);
  2935. }
  2936. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  2937. u16 x, u16 y, u16 w, u16 h)
  2938. {
  2939. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2940. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2941. unsigned bytespp;
  2942. unsigned bytespl;
  2943. unsigned bytespf;
  2944. unsigned total_len;
  2945. unsigned packet_payload;
  2946. unsigned packet_len;
  2947. u32 l;
  2948. int r;
  2949. const unsigned channel = dsi->update_channel;
  2950. const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
  2951. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  2952. x, y, w, h);
  2953. dsi_vc_config_vp(dsidev, channel);
  2954. bytespp = dssdev->ctrl.pixel_size / 8;
  2955. bytespl = w * bytespp;
  2956. bytespf = bytespl * h;
  2957. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  2958. * number of lines in a packet. See errata about VP_CLK_RATIO */
  2959. if (bytespf < line_buf_size)
  2960. packet_payload = bytespf;
  2961. else
  2962. packet_payload = (line_buf_size) / bytespl * bytespl;
  2963. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  2964. total_len = (bytespf / packet_payload) * packet_len;
  2965. if (bytespf % packet_payload)
  2966. total_len += (bytespf % packet_payload) + 1;
  2967. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  2968. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  2969. dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
  2970. packet_len, 0);
  2971. if (dsi->te_enabled)
  2972. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  2973. else
  2974. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  2975. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  2976. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  2977. * because DSS interrupts are not capable of waking up the CPU and the
  2978. * framedone interrupt could be delayed for quite a long time. I think
  2979. * the same goes for any DSS interrupts, but for some reason I have not
  2980. * seen the problem anywhere else than here.
  2981. */
  2982. dispc_disable_sidle();
  2983. dsi_perf_mark_start(dsidev);
  2984. r = schedule_delayed_work(&dsi->framedone_timeout_work,
  2985. msecs_to_jiffies(250));
  2986. BUG_ON(r == 0);
  2987. dss_start_update(dssdev);
  2988. if (dsi->te_enabled) {
  2989. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  2990. * for TE is longer than the timer allows */
  2991. REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  2992. dsi_vc_send_bta(dsidev, channel);
  2993. #ifdef DSI_CATCH_MISSING_TE
  2994. mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
  2995. #endif
  2996. }
  2997. }
  2998. #ifdef DSI_CATCH_MISSING_TE
  2999. static void dsi_te_timeout(unsigned long arg)
  3000. {
  3001. DSSERR("TE not received for 250ms!\n");
  3002. }
  3003. #endif
  3004. static void dsi_handle_framedone(struct platform_device *dsidev, int error)
  3005. {
  3006. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3007. /* SIDLEMODE back to smart-idle */
  3008. dispc_enable_sidle();
  3009. if (dsi->te_enabled) {
  3010. /* enable LP_RX_TO again after the TE */
  3011. REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  3012. }
  3013. dsi->framedone_callback(error, dsi->framedone_data);
  3014. if (!error)
  3015. dsi_perf_show(dsidev, "DISPC");
  3016. }
  3017. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  3018. {
  3019. struct dsi_data *dsi = container_of(work, struct dsi_data,
  3020. framedone_timeout_work.work);
  3021. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  3022. * 250ms which would conflict with this timeout work. What should be
  3023. * done is first cancel the transfer on the HW, and then cancel the
  3024. * possibly scheduled framedone work. However, cancelling the transfer
  3025. * on the HW is buggy, and would probably require resetting the whole
  3026. * DSI */
  3027. DSSERR("Framedone not received for 250ms!\n");
  3028. dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
  3029. }
  3030. static void dsi_framedone_irq_callback(void *data, u32 mask)
  3031. {
  3032. struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
  3033. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3034. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3035. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  3036. * turns itself off. However, DSI still has the pixels in its buffers,
  3037. * and is sending the data.
  3038. */
  3039. __cancel_delayed_work(&dsi->framedone_timeout_work);
  3040. dsi_handle_framedone(dsidev, 0);
  3041. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  3042. dispc_fake_vsync_irq();
  3043. #endif
  3044. }
  3045. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  3046. u16 *x, u16 *y, u16 *w, u16 *h,
  3047. bool enlarge_update_area)
  3048. {
  3049. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3050. u16 dw, dh;
  3051. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  3052. if (*x > dw || *y > dh)
  3053. return -EINVAL;
  3054. if (*x + *w > dw)
  3055. return -EINVAL;
  3056. if (*y + *h > dh)
  3057. return -EINVAL;
  3058. if (*w == 1)
  3059. return -EINVAL;
  3060. if (*w == 0 || *h == 0)
  3061. return -EINVAL;
  3062. dsi_perf_mark_setup(dsidev);
  3063. dss_setup_partial_planes(dssdev, x, y, w, h,
  3064. enlarge_update_area);
  3065. dispc_set_lcd_size(dssdev->manager->id, *w, *h);
  3066. return 0;
  3067. }
  3068. EXPORT_SYMBOL(omap_dsi_prepare_update);
  3069. int omap_dsi_update(struct omap_dss_device *dssdev,
  3070. int channel,
  3071. u16 x, u16 y, u16 w, u16 h,
  3072. void (*callback)(int, void *), void *data)
  3073. {
  3074. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3075. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3076. dsi->update_channel = channel;
  3077. /* OMAP DSS cannot send updates of odd widths.
  3078. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  3079. * here to make sure we catch erroneous updates. Otherwise we'll only
  3080. * see rather obscure HW error happening, as DSS halts. */
  3081. BUG_ON(x % 2 == 1);
  3082. dsi->framedone_callback = callback;
  3083. dsi->framedone_data = data;
  3084. dsi->update_region.x = x;
  3085. dsi->update_region.y = y;
  3086. dsi->update_region.w = w;
  3087. dsi->update_region.h = h;
  3088. dsi->update_region.device = dssdev;
  3089. dsi_update_screen_dispc(dssdev, x, y, w, h);
  3090. return 0;
  3091. }
  3092. EXPORT_SYMBOL(omap_dsi_update);
  3093. /* Display funcs */
  3094. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  3095. {
  3096. int r;
  3097. u32 irq;
  3098. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3099. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3100. r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3101. irq);
  3102. if (r) {
  3103. DSSERR("can't get FRAMEDONE irq\n");
  3104. return r;
  3105. }
  3106. dispc_set_lcd_display_type(dssdev->manager->id,
  3107. OMAP_DSS_LCD_DISPLAY_TFT);
  3108. dispc_set_parallel_interface_mode(dssdev->manager->id,
  3109. OMAP_DSS_PARALLELMODE_DSI);
  3110. dispc_enable_fifohandcheck(dssdev->manager->id, 1);
  3111. dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
  3112. {
  3113. struct omap_video_timings timings = {
  3114. .hsw = 1,
  3115. .hfp = 1,
  3116. .hbp = 1,
  3117. .vsw = 1,
  3118. .vfp = 0,
  3119. .vbp = 0,
  3120. };
  3121. dispc_set_lcd_timings(dssdev->manager->id, &timings);
  3122. }
  3123. return 0;
  3124. }
  3125. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  3126. {
  3127. u32 irq;
  3128. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3129. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3130. omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3131. irq);
  3132. }
  3133. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  3134. {
  3135. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3136. struct dsi_clock_info cinfo;
  3137. int r;
  3138. /* we always use DSS_CLK_SYSCK as input clock */
  3139. cinfo.use_sys_clk = true;
  3140. cinfo.regn = dssdev->clocks.dsi.regn;
  3141. cinfo.regm = dssdev->clocks.dsi.regm;
  3142. cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
  3143. cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
  3144. r = dsi_calc_clock_rates(dssdev, &cinfo);
  3145. if (r) {
  3146. DSSERR("Failed to calc dsi clocks\n");
  3147. return r;
  3148. }
  3149. r = dsi_pll_set_clock_div(dsidev, &cinfo);
  3150. if (r) {
  3151. DSSERR("Failed to set dsi clocks\n");
  3152. return r;
  3153. }
  3154. return 0;
  3155. }
  3156. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  3157. {
  3158. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3159. struct dispc_clock_info dispc_cinfo;
  3160. int r;
  3161. unsigned long long fck;
  3162. fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  3163. dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
  3164. dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
  3165. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  3166. if (r) {
  3167. DSSERR("Failed to calc dispc clocks\n");
  3168. return r;
  3169. }
  3170. r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  3171. if (r) {
  3172. DSSERR("Failed to set dispc clocks\n");
  3173. return r;
  3174. }
  3175. return 0;
  3176. }
  3177. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  3178. {
  3179. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3180. int dsi_module = dsi_get_dsidev_id(dsidev);
  3181. int r;
  3182. r = dsi_pll_init(dsidev, true, true);
  3183. if (r)
  3184. goto err0;
  3185. r = dsi_configure_dsi_clocks(dssdev);
  3186. if (r)
  3187. goto err1;
  3188. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  3189. dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src);
  3190. dss_select_lcd_clk_source(dssdev->manager->id,
  3191. dssdev->clocks.dispc.channel.lcd_clk_src);
  3192. DSSDBG("PLL OK\n");
  3193. r = dsi_configure_dispc_clocks(dssdev);
  3194. if (r)
  3195. goto err2;
  3196. r = dsi_cio_init(dssdev);
  3197. if (r)
  3198. goto err2;
  3199. _dsi_print_reset_status(dsidev);
  3200. dsi_proto_timings(dssdev);
  3201. dsi_set_lp_clk_divisor(dssdev);
  3202. if (1)
  3203. _dsi_print_reset_status(dsidev);
  3204. r = dsi_proto_config(dssdev);
  3205. if (r)
  3206. goto err3;
  3207. /* enable interface */
  3208. dsi_vc_enable(dsidev, 0, 1);
  3209. dsi_vc_enable(dsidev, 1, 1);
  3210. dsi_vc_enable(dsidev, 2, 1);
  3211. dsi_vc_enable(dsidev, 3, 1);
  3212. dsi_if_enable(dsidev, 1);
  3213. dsi_force_tx_stop_mode_io(dsidev);
  3214. return 0;
  3215. err3:
  3216. dsi_cio_uninit(dssdev);
  3217. err2:
  3218. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3219. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3220. dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
  3221. err1:
  3222. dsi_pll_uninit(dsidev, true);
  3223. err0:
  3224. return r;
  3225. }
  3226. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
  3227. bool disconnect_lanes, bool enter_ulps)
  3228. {
  3229. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3230. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3231. int dsi_module = dsi_get_dsidev_id(dsidev);
  3232. if (enter_ulps && !dsi->ulps_enabled)
  3233. dsi_enter_ulps(dsidev);
  3234. /* disable interface */
  3235. dsi_if_enable(dsidev, 0);
  3236. dsi_vc_enable(dsidev, 0, 0);
  3237. dsi_vc_enable(dsidev, 1, 0);
  3238. dsi_vc_enable(dsidev, 2, 0);
  3239. dsi_vc_enable(dsidev, 3, 0);
  3240. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3241. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3242. dss_select_lcd_clk_source(dssdev->manager->id, OMAP_DSS_CLK_SRC_FCK);
  3243. dsi_cio_uninit(dssdev);
  3244. dsi_pll_uninit(dsidev, disconnect_lanes);
  3245. }
  3246. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  3247. {
  3248. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3249. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3250. int r = 0;
  3251. DSSDBG("dsi_display_enable\n");
  3252. WARN_ON(!dsi_bus_is_locked(dsidev));
  3253. mutex_lock(&dsi->lock);
  3254. if (dssdev->manager == NULL) {
  3255. DSSERR("failed to enable display: no manager\n");
  3256. r = -ENODEV;
  3257. goto err_start_dev;
  3258. }
  3259. r = omap_dss_start_device(dssdev);
  3260. if (r) {
  3261. DSSERR("failed to start device\n");
  3262. goto err_start_dev;
  3263. }
  3264. r = dsi_runtime_get(dsidev);
  3265. if (r)
  3266. goto err_get_dsi;
  3267. dsi_enable_pll_clock(dsidev, 1);
  3268. _dsi_initialize_irq(dsidev);
  3269. r = dsi_display_init_dispc(dssdev);
  3270. if (r)
  3271. goto err_init_dispc;
  3272. r = dsi_display_init_dsi(dssdev);
  3273. if (r)
  3274. goto err_init_dsi;
  3275. mutex_unlock(&dsi->lock);
  3276. return 0;
  3277. err_init_dsi:
  3278. dsi_display_uninit_dispc(dssdev);
  3279. err_init_dispc:
  3280. dsi_enable_pll_clock(dsidev, 0);
  3281. dsi_runtime_put(dsidev);
  3282. err_get_dsi:
  3283. omap_dss_stop_device(dssdev);
  3284. err_start_dev:
  3285. mutex_unlock(&dsi->lock);
  3286. DSSDBG("dsi_display_enable FAILED\n");
  3287. return r;
  3288. }
  3289. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  3290. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
  3291. bool disconnect_lanes, bool enter_ulps)
  3292. {
  3293. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3294. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3295. DSSDBG("dsi_display_disable\n");
  3296. WARN_ON(!dsi_bus_is_locked(dsidev));
  3297. mutex_lock(&dsi->lock);
  3298. dsi_sync_vc(dsidev, 0);
  3299. dsi_sync_vc(dsidev, 1);
  3300. dsi_sync_vc(dsidev, 2);
  3301. dsi_sync_vc(dsidev, 3);
  3302. dsi_display_uninit_dispc(dssdev);
  3303. dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
  3304. dsi_runtime_put(dsidev);
  3305. dsi_enable_pll_clock(dsidev, 0);
  3306. omap_dss_stop_device(dssdev);
  3307. mutex_unlock(&dsi->lock);
  3308. }
  3309. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  3310. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  3311. {
  3312. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3313. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3314. dsi->te_enabled = enable;
  3315. return 0;
  3316. }
  3317. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  3318. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  3319. u32 fifo_size, u32 burst_size,
  3320. u32 *fifo_low, u32 *fifo_high)
  3321. {
  3322. *fifo_high = fifo_size - burst_size;
  3323. *fifo_low = fifo_size - burst_size * 2;
  3324. }
  3325. int dsi_init_display(struct omap_dss_device *dssdev)
  3326. {
  3327. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3328. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3329. int dsi_module = dsi_get_dsidev_id(dsidev);
  3330. DSSDBG("DSI init\n");
  3331. /* XXX these should be figured out dynamically */
  3332. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  3333. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  3334. if (dsi->vdds_dsi_reg == NULL) {
  3335. struct regulator *vdds_dsi;
  3336. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  3337. if (IS_ERR(vdds_dsi)) {
  3338. DSSERR("can't get VDDS_DSI regulator\n");
  3339. return PTR_ERR(vdds_dsi);
  3340. }
  3341. dsi->vdds_dsi_reg = vdds_dsi;
  3342. }
  3343. if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) {
  3344. DSSERR("DSI%d can't support more than %d data lanes\n",
  3345. dsi_module + 1, dsi->num_data_lanes);
  3346. return -EINVAL;
  3347. }
  3348. return 0;
  3349. }
  3350. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  3351. {
  3352. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3353. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3354. int i;
  3355. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3356. if (!dsi->vc[i].dssdev) {
  3357. dsi->vc[i].dssdev = dssdev;
  3358. *channel = i;
  3359. return 0;
  3360. }
  3361. }
  3362. DSSERR("cannot get VC for display %s", dssdev->name);
  3363. return -ENOSPC;
  3364. }
  3365. EXPORT_SYMBOL(omap_dsi_request_vc);
  3366. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  3367. {
  3368. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3369. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3370. if (vc_id < 0 || vc_id > 3) {
  3371. DSSERR("VC ID out of range\n");
  3372. return -EINVAL;
  3373. }
  3374. if (channel < 0 || channel > 3) {
  3375. DSSERR("Virtual Channel out of range\n");
  3376. return -EINVAL;
  3377. }
  3378. if (dsi->vc[channel].dssdev != dssdev) {
  3379. DSSERR("Virtual Channel not allocated to display %s\n",
  3380. dssdev->name);
  3381. return -EINVAL;
  3382. }
  3383. dsi->vc[channel].vc_id = vc_id;
  3384. return 0;
  3385. }
  3386. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  3387. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  3388. {
  3389. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3390. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3391. if ((channel >= 0 && channel <= 3) &&
  3392. dsi->vc[channel].dssdev == dssdev) {
  3393. dsi->vc[channel].dssdev = NULL;
  3394. dsi->vc[channel].vc_id = 0;
  3395. }
  3396. }
  3397. EXPORT_SYMBOL(omap_dsi_release_vc);
  3398. void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
  3399. {
  3400. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
  3401. DSSERR("%s (%s) not active\n",
  3402. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  3403. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  3404. }
  3405. void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
  3406. {
  3407. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
  3408. DSSERR("%s (%s) not active\n",
  3409. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  3410. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  3411. }
  3412. static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
  3413. {
  3414. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3415. dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  3416. dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  3417. dsi->regm_dispc_max =
  3418. dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  3419. dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  3420. dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  3421. dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  3422. dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  3423. }
  3424. static int dsi_get_clocks(struct platform_device *dsidev)
  3425. {
  3426. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3427. struct clk *clk;
  3428. clk = clk_get(&dsidev->dev, "fck");
  3429. if (IS_ERR(clk)) {
  3430. DSSERR("can't get fck\n");
  3431. return PTR_ERR(clk);
  3432. }
  3433. dsi->dss_clk = clk;
  3434. clk = clk_get(&dsidev->dev, "sys_clk");
  3435. if (IS_ERR(clk)) {
  3436. DSSERR("can't get sys_clk\n");
  3437. clk_put(dsi->dss_clk);
  3438. dsi->dss_clk = NULL;
  3439. return PTR_ERR(clk);
  3440. }
  3441. dsi->sys_clk = clk;
  3442. return 0;
  3443. }
  3444. static void dsi_put_clocks(struct platform_device *dsidev)
  3445. {
  3446. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3447. if (dsi->dss_clk)
  3448. clk_put(dsi->dss_clk);
  3449. if (dsi->sys_clk)
  3450. clk_put(dsi->sys_clk);
  3451. }
  3452. /* DSI1 HW IP initialisation */
  3453. static int omap_dsihw_probe(struct platform_device *dsidev)
  3454. {
  3455. struct omap_display_platform_data *dss_plat_data;
  3456. struct omap_dss_board_info *board_info;
  3457. u32 rev;
  3458. int r, i, dsi_module = dsi_get_dsidev_id(dsidev);
  3459. struct resource *dsi_mem;
  3460. struct dsi_data *dsi;
  3461. dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
  3462. if (!dsi) {
  3463. r = -ENOMEM;
  3464. goto err_alloc;
  3465. }
  3466. dsi->pdev = dsidev;
  3467. dsi_pdev_map[dsi_module] = dsidev;
  3468. dev_set_drvdata(&dsidev->dev, dsi);
  3469. dss_plat_data = dsidev->dev.platform_data;
  3470. board_info = dss_plat_data->board_data;
  3471. dsi->enable_pads = board_info->dsi_enable_pads;
  3472. dsi->disable_pads = board_info->dsi_disable_pads;
  3473. spin_lock_init(&dsi->irq_lock);
  3474. spin_lock_init(&dsi->errors_lock);
  3475. dsi->errors = 0;
  3476. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3477. spin_lock_init(&dsi->irq_stats_lock);
  3478. dsi->irq_stats.last_reset = jiffies;
  3479. #endif
  3480. mutex_init(&dsi->lock);
  3481. sema_init(&dsi->bus_lock, 1);
  3482. r = dsi_get_clocks(dsidev);
  3483. if (r)
  3484. goto err_get_clk;
  3485. pm_runtime_enable(&dsidev->dev);
  3486. INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
  3487. dsi_framedone_timeout_work_callback);
  3488. #ifdef DSI_CATCH_MISSING_TE
  3489. init_timer(&dsi->te_timer);
  3490. dsi->te_timer.function = dsi_te_timeout;
  3491. dsi->te_timer.data = 0;
  3492. #endif
  3493. dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
  3494. if (!dsi_mem) {
  3495. DSSERR("can't get IORESOURCE_MEM DSI\n");
  3496. r = -EINVAL;
  3497. goto err_ioremap;
  3498. }
  3499. dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  3500. if (!dsi->base) {
  3501. DSSERR("can't ioremap DSI\n");
  3502. r = -ENOMEM;
  3503. goto err_ioremap;
  3504. }
  3505. dsi->irq = platform_get_irq(dsi->pdev, 0);
  3506. if (dsi->irq < 0) {
  3507. DSSERR("platform_get_irq failed\n");
  3508. r = -ENODEV;
  3509. goto err_get_irq;
  3510. }
  3511. r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
  3512. dev_name(&dsidev->dev), dsi->pdev);
  3513. if (r < 0) {
  3514. DSSERR("request_irq failed\n");
  3515. goto err_get_irq;
  3516. }
  3517. /* DSI VCs initialization */
  3518. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3519. dsi->vc[i].mode = DSI_VC_MODE_L4;
  3520. dsi->vc[i].dssdev = NULL;
  3521. dsi->vc[i].vc_id = 0;
  3522. }
  3523. dsi_calc_clock_param_ranges(dsidev);
  3524. r = dsi_runtime_get(dsidev);
  3525. if (r)
  3526. goto err_get_dsi;
  3527. rev = dsi_read_reg(dsidev, DSI_REVISION);
  3528. dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
  3529. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3530. dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
  3531. dsi_runtime_put(dsidev);
  3532. return 0;
  3533. err_get_dsi:
  3534. free_irq(dsi->irq, dsi->pdev);
  3535. err_get_irq:
  3536. iounmap(dsi->base);
  3537. err_ioremap:
  3538. pm_runtime_disable(&dsidev->dev);
  3539. err_get_clk:
  3540. kfree(dsi);
  3541. err_alloc:
  3542. return r;
  3543. }
  3544. static int omap_dsihw_remove(struct platform_device *dsidev)
  3545. {
  3546. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3547. WARN_ON(dsi->scp_clk_refcount > 0);
  3548. pm_runtime_disable(&dsidev->dev);
  3549. dsi_put_clocks(dsidev);
  3550. if (dsi->vdds_dsi_reg != NULL) {
  3551. if (dsi->vdds_dsi_enabled) {
  3552. regulator_disable(dsi->vdds_dsi_reg);
  3553. dsi->vdds_dsi_enabled = false;
  3554. }
  3555. regulator_put(dsi->vdds_dsi_reg);
  3556. dsi->vdds_dsi_reg = NULL;
  3557. }
  3558. free_irq(dsi->irq, dsi->pdev);
  3559. iounmap(dsi->base);
  3560. kfree(dsi);
  3561. return 0;
  3562. }
  3563. static int dsi_runtime_suspend(struct device *dev)
  3564. {
  3565. dispc_runtime_put();
  3566. dss_runtime_put();
  3567. return 0;
  3568. }
  3569. static int dsi_runtime_resume(struct device *dev)
  3570. {
  3571. int r;
  3572. r = dss_runtime_get();
  3573. if (r)
  3574. goto err_get_dss;
  3575. r = dispc_runtime_get();
  3576. if (r)
  3577. goto err_get_dispc;
  3578. return 0;
  3579. err_get_dispc:
  3580. dss_runtime_put();
  3581. err_get_dss:
  3582. return r;
  3583. }
  3584. static const struct dev_pm_ops dsi_pm_ops = {
  3585. .runtime_suspend = dsi_runtime_suspend,
  3586. .runtime_resume = dsi_runtime_resume,
  3587. };
  3588. static struct platform_driver omap_dsihw_driver = {
  3589. .probe = omap_dsihw_probe,
  3590. .remove = omap_dsihw_remove,
  3591. .driver = {
  3592. .name = "omapdss_dsi",
  3593. .owner = THIS_MODULE,
  3594. .pm = &dsi_pm_ops,
  3595. },
  3596. };
  3597. int dsi_init_platform_driver(void)
  3598. {
  3599. return platform_driver_register(&omap_dsihw_driver);
  3600. }
  3601. void dsi_uninit_platform_driver(void)
  3602. {
  3603. return platform_driver_unregister(&omap_dsihw_driver);
  3604. }