dsi.c 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612
  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 <video/omapdss.h>
  38. #include <plat/clock.h>
  39. #include "dss.h"
  40. #include "dss_features.h"
  41. /*#define VERBOSE_IRQ*/
  42. #define DSI_CATCH_MISSING_TE
  43. struct dsi_reg { u16 idx; };
  44. #define DSI_REG(idx) ((const struct dsi_reg) { idx })
  45. #define DSI_SZ_REGS SZ_1K
  46. /* DSI Protocol Engine */
  47. #define DSI_REVISION DSI_REG(0x0000)
  48. #define DSI_SYSCONFIG DSI_REG(0x0010)
  49. #define DSI_SYSSTATUS DSI_REG(0x0014)
  50. #define DSI_IRQSTATUS DSI_REG(0x0018)
  51. #define DSI_IRQENABLE DSI_REG(0x001C)
  52. #define DSI_CTRL DSI_REG(0x0040)
  53. #define DSI_GNQ DSI_REG(0x0044)
  54. #define DSI_COMPLEXIO_CFG1 DSI_REG(0x0048)
  55. #define DSI_COMPLEXIO_IRQ_STATUS DSI_REG(0x004C)
  56. #define DSI_COMPLEXIO_IRQ_ENABLE DSI_REG(0x0050)
  57. #define DSI_CLK_CTRL DSI_REG(0x0054)
  58. #define DSI_TIMING1 DSI_REG(0x0058)
  59. #define DSI_TIMING2 DSI_REG(0x005C)
  60. #define DSI_VM_TIMING1 DSI_REG(0x0060)
  61. #define DSI_VM_TIMING2 DSI_REG(0x0064)
  62. #define DSI_VM_TIMING3 DSI_REG(0x0068)
  63. #define DSI_CLK_TIMING DSI_REG(0x006C)
  64. #define DSI_TX_FIFO_VC_SIZE DSI_REG(0x0070)
  65. #define DSI_RX_FIFO_VC_SIZE DSI_REG(0x0074)
  66. #define DSI_COMPLEXIO_CFG2 DSI_REG(0x0078)
  67. #define DSI_RX_FIFO_VC_FULLNESS DSI_REG(0x007C)
  68. #define DSI_VM_TIMING4 DSI_REG(0x0080)
  69. #define DSI_TX_FIFO_VC_EMPTINESS DSI_REG(0x0084)
  70. #define DSI_VM_TIMING5 DSI_REG(0x0088)
  71. #define DSI_VM_TIMING6 DSI_REG(0x008C)
  72. #define DSI_VM_TIMING7 DSI_REG(0x0090)
  73. #define DSI_STOPCLK_TIMING DSI_REG(0x0094)
  74. #define DSI_VC_CTRL(n) DSI_REG(0x0100 + (n * 0x20))
  75. #define DSI_VC_TE(n) DSI_REG(0x0104 + (n * 0x20))
  76. #define DSI_VC_LONG_PACKET_HEADER(n) DSI_REG(0x0108 + (n * 0x20))
  77. #define DSI_VC_LONG_PACKET_PAYLOAD(n) DSI_REG(0x010C + (n * 0x20))
  78. #define DSI_VC_SHORT_PACKET_HEADER(n) DSI_REG(0x0110 + (n * 0x20))
  79. #define DSI_VC_IRQSTATUS(n) DSI_REG(0x0118 + (n * 0x20))
  80. #define DSI_VC_IRQENABLE(n) DSI_REG(0x011C + (n * 0x20))
  81. /* DSIPHY_SCP */
  82. #define DSI_DSIPHY_CFG0 DSI_REG(0x200 + 0x0000)
  83. #define DSI_DSIPHY_CFG1 DSI_REG(0x200 + 0x0004)
  84. #define DSI_DSIPHY_CFG2 DSI_REG(0x200 + 0x0008)
  85. #define DSI_DSIPHY_CFG5 DSI_REG(0x200 + 0x0014)
  86. #define DSI_DSIPHY_CFG10 DSI_REG(0x200 + 0x0028)
  87. /* DSI_PLL_CTRL_SCP */
  88. #define DSI_PLL_CONTROL DSI_REG(0x300 + 0x0000)
  89. #define DSI_PLL_STATUS DSI_REG(0x300 + 0x0004)
  90. #define DSI_PLL_GO DSI_REG(0x300 + 0x0008)
  91. #define DSI_PLL_CONFIGURATION1 DSI_REG(0x300 + 0x000C)
  92. #define DSI_PLL_CONFIGURATION2 DSI_REG(0x300 + 0x0010)
  93. #define REG_GET(dsidev, idx, start, end) \
  94. FLD_GET(dsi_read_reg(dsidev, idx), start, end)
  95. #define REG_FLD_MOD(dsidev, idx, val, start, end) \
  96. dsi_write_reg(dsidev, idx, FLD_MOD(dsi_read_reg(dsidev, idx), val, start, end))
  97. /* Global interrupts */
  98. #define DSI_IRQ_VC0 (1 << 0)
  99. #define DSI_IRQ_VC1 (1 << 1)
  100. #define DSI_IRQ_VC2 (1 << 2)
  101. #define DSI_IRQ_VC3 (1 << 3)
  102. #define DSI_IRQ_WAKEUP (1 << 4)
  103. #define DSI_IRQ_RESYNC (1 << 5)
  104. #define DSI_IRQ_PLL_LOCK (1 << 7)
  105. #define DSI_IRQ_PLL_UNLOCK (1 << 8)
  106. #define DSI_IRQ_PLL_RECALL (1 << 9)
  107. #define DSI_IRQ_COMPLEXIO_ERR (1 << 10)
  108. #define DSI_IRQ_HS_TX_TIMEOUT (1 << 14)
  109. #define DSI_IRQ_LP_RX_TIMEOUT (1 << 15)
  110. #define DSI_IRQ_TE_TRIGGER (1 << 16)
  111. #define DSI_IRQ_ACK_TRIGGER (1 << 17)
  112. #define DSI_IRQ_SYNC_LOST (1 << 18)
  113. #define DSI_IRQ_LDO_POWER_GOOD (1 << 19)
  114. #define DSI_IRQ_TA_TIMEOUT (1 << 20)
  115. #define DSI_IRQ_ERROR_MASK \
  116. (DSI_IRQ_HS_TX_TIMEOUT | DSI_IRQ_LP_RX_TIMEOUT | DSI_IRQ_SYNC_LOST | \
  117. DSI_IRQ_TA_TIMEOUT)
  118. #define DSI_IRQ_CHANNEL_MASK 0xf
  119. /* Virtual channel interrupts */
  120. #define DSI_VC_IRQ_CS (1 << 0)
  121. #define DSI_VC_IRQ_ECC_CORR (1 << 1)
  122. #define DSI_VC_IRQ_PACKET_SENT (1 << 2)
  123. #define DSI_VC_IRQ_FIFO_TX_OVF (1 << 3)
  124. #define DSI_VC_IRQ_FIFO_RX_OVF (1 << 4)
  125. #define DSI_VC_IRQ_BTA (1 << 5)
  126. #define DSI_VC_IRQ_ECC_NO_CORR (1 << 6)
  127. #define DSI_VC_IRQ_FIFO_TX_UDF (1 << 7)
  128. #define DSI_VC_IRQ_PP_BUSY_CHANGE (1 << 8)
  129. #define DSI_VC_IRQ_ERROR_MASK \
  130. (DSI_VC_IRQ_CS | DSI_VC_IRQ_ECC_CORR | DSI_VC_IRQ_FIFO_TX_OVF | \
  131. DSI_VC_IRQ_FIFO_RX_OVF | DSI_VC_IRQ_ECC_NO_CORR | \
  132. DSI_VC_IRQ_FIFO_TX_UDF)
  133. /* ComplexIO interrupts */
  134. #define DSI_CIO_IRQ_ERRSYNCESC1 (1 << 0)
  135. #define DSI_CIO_IRQ_ERRSYNCESC2 (1 << 1)
  136. #define DSI_CIO_IRQ_ERRSYNCESC3 (1 << 2)
  137. #define DSI_CIO_IRQ_ERRSYNCESC4 (1 << 3)
  138. #define DSI_CIO_IRQ_ERRSYNCESC5 (1 << 4)
  139. #define DSI_CIO_IRQ_ERRESC1 (1 << 5)
  140. #define DSI_CIO_IRQ_ERRESC2 (1 << 6)
  141. #define DSI_CIO_IRQ_ERRESC3 (1 << 7)
  142. #define DSI_CIO_IRQ_ERRESC4 (1 << 8)
  143. #define DSI_CIO_IRQ_ERRESC5 (1 << 9)
  144. #define DSI_CIO_IRQ_ERRCONTROL1 (1 << 10)
  145. #define DSI_CIO_IRQ_ERRCONTROL2 (1 << 11)
  146. #define DSI_CIO_IRQ_ERRCONTROL3 (1 << 12)
  147. #define DSI_CIO_IRQ_ERRCONTROL4 (1 << 13)
  148. #define DSI_CIO_IRQ_ERRCONTROL5 (1 << 14)
  149. #define DSI_CIO_IRQ_STATEULPS1 (1 << 15)
  150. #define DSI_CIO_IRQ_STATEULPS2 (1 << 16)
  151. #define DSI_CIO_IRQ_STATEULPS3 (1 << 17)
  152. #define DSI_CIO_IRQ_STATEULPS4 (1 << 18)
  153. #define DSI_CIO_IRQ_STATEULPS5 (1 << 19)
  154. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_1 (1 << 20)
  155. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_1 (1 << 21)
  156. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_2 (1 << 22)
  157. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_2 (1 << 23)
  158. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_3 (1 << 24)
  159. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_3 (1 << 25)
  160. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_4 (1 << 26)
  161. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_4 (1 << 27)
  162. #define DSI_CIO_IRQ_ERRCONTENTIONLP0_5 (1 << 28)
  163. #define DSI_CIO_IRQ_ERRCONTENTIONLP1_5 (1 << 29)
  164. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL0 (1 << 30)
  165. #define DSI_CIO_IRQ_ULPSACTIVENOT_ALL1 (1 << 31)
  166. #define DSI_CIO_IRQ_ERROR_MASK \
  167. (DSI_CIO_IRQ_ERRSYNCESC1 | DSI_CIO_IRQ_ERRSYNCESC2 | \
  168. DSI_CIO_IRQ_ERRSYNCESC3 | DSI_CIO_IRQ_ERRSYNCESC4 | \
  169. DSI_CIO_IRQ_ERRSYNCESC5 | \
  170. DSI_CIO_IRQ_ERRESC1 | DSI_CIO_IRQ_ERRESC2 | \
  171. DSI_CIO_IRQ_ERRESC3 | DSI_CIO_IRQ_ERRESC4 | \
  172. DSI_CIO_IRQ_ERRESC5 | \
  173. DSI_CIO_IRQ_ERRCONTROL1 | DSI_CIO_IRQ_ERRCONTROL2 | \
  174. DSI_CIO_IRQ_ERRCONTROL3 | DSI_CIO_IRQ_ERRCONTROL4 | \
  175. DSI_CIO_IRQ_ERRCONTROL5 | \
  176. DSI_CIO_IRQ_ERRCONTENTIONLP0_1 | DSI_CIO_IRQ_ERRCONTENTIONLP1_1 | \
  177. DSI_CIO_IRQ_ERRCONTENTIONLP0_2 | DSI_CIO_IRQ_ERRCONTENTIONLP1_2 | \
  178. DSI_CIO_IRQ_ERRCONTENTIONLP0_3 | DSI_CIO_IRQ_ERRCONTENTIONLP1_3 | \
  179. DSI_CIO_IRQ_ERRCONTENTIONLP0_4 | DSI_CIO_IRQ_ERRCONTENTIONLP1_4 | \
  180. DSI_CIO_IRQ_ERRCONTENTIONLP0_5 | DSI_CIO_IRQ_ERRCONTENTIONLP1_5)
  181. #define DSI_DT_DCS_SHORT_WRITE_0 0x05
  182. #define DSI_DT_DCS_SHORT_WRITE_1 0x15
  183. #define DSI_DT_DCS_READ 0x06
  184. #define DSI_DT_SET_MAX_RET_PKG_SIZE 0x37
  185. #define DSI_DT_NULL_PACKET 0x09
  186. #define DSI_DT_DCS_LONG_WRITE 0x39
  187. #define DSI_DT_RX_ACK_WITH_ERR 0x02
  188. #define DSI_DT_RX_DCS_LONG_READ 0x1c
  189. #define DSI_DT_RX_SHORT_READ_1 0x21
  190. #define DSI_DT_RX_SHORT_READ_2 0x22
  191. typedef void (*omap_dsi_isr_t) (void *arg, u32 mask);
  192. #define DSI_MAX_NR_ISRS 2
  193. struct dsi_isr_data {
  194. omap_dsi_isr_t isr;
  195. void *arg;
  196. u32 mask;
  197. };
  198. enum fifo_size {
  199. DSI_FIFO_SIZE_0 = 0,
  200. DSI_FIFO_SIZE_32 = 1,
  201. DSI_FIFO_SIZE_64 = 2,
  202. DSI_FIFO_SIZE_96 = 3,
  203. DSI_FIFO_SIZE_128 = 4,
  204. };
  205. enum dsi_vc_mode {
  206. DSI_VC_MODE_L4 = 0,
  207. DSI_VC_MODE_VP,
  208. };
  209. enum dsi_lane {
  210. DSI_CLK_P = 1 << 0,
  211. DSI_CLK_N = 1 << 1,
  212. DSI_DATA1_P = 1 << 2,
  213. DSI_DATA1_N = 1 << 3,
  214. DSI_DATA2_P = 1 << 4,
  215. DSI_DATA2_N = 1 << 5,
  216. DSI_DATA3_P = 1 << 6,
  217. DSI_DATA3_N = 1 << 7,
  218. DSI_DATA4_P = 1 << 8,
  219. DSI_DATA4_N = 1 << 9,
  220. };
  221. struct dsi_update_region {
  222. u16 x, y, w, h;
  223. struct omap_dss_device *device;
  224. };
  225. struct dsi_irq_stats {
  226. unsigned long last_reset;
  227. unsigned irq_count;
  228. unsigned dsi_irqs[32];
  229. unsigned vc_irqs[4][32];
  230. unsigned cio_irqs[32];
  231. };
  232. struct dsi_isr_tables {
  233. struct dsi_isr_data isr_table[DSI_MAX_NR_ISRS];
  234. struct dsi_isr_data isr_table_vc[4][DSI_MAX_NR_ISRS];
  235. struct dsi_isr_data isr_table_cio[DSI_MAX_NR_ISRS];
  236. };
  237. struct dsi_data {
  238. struct platform_device *pdev;
  239. void __iomem *base;
  240. int irq;
  241. void (*dsi_mux_pads)(bool enable);
  242. struct dsi_clock_info current_cinfo;
  243. bool vdds_dsi_enabled;
  244. struct regulator *vdds_dsi_reg;
  245. struct {
  246. enum dsi_vc_mode mode;
  247. struct omap_dss_device *dssdev;
  248. enum fifo_size fifo_size;
  249. int vc_id;
  250. } vc[4];
  251. struct mutex lock;
  252. struct semaphore bus_lock;
  253. unsigned pll_locked;
  254. spinlock_t irq_lock;
  255. struct dsi_isr_tables isr_tables;
  256. /* space for a copy used by the interrupt handler */
  257. struct dsi_isr_tables isr_tables_copy;
  258. int update_channel;
  259. struct dsi_update_region update_region;
  260. bool te_enabled;
  261. bool ulps_enabled;
  262. void (*framedone_callback)(int, void *);
  263. void *framedone_data;
  264. struct delayed_work framedone_timeout_work;
  265. #ifdef DSI_CATCH_MISSING_TE
  266. struct timer_list te_timer;
  267. #endif
  268. unsigned long cache_req_pck;
  269. unsigned long cache_clk_freq;
  270. struct dsi_clock_info cache_cinfo;
  271. u32 errors;
  272. spinlock_t errors_lock;
  273. #ifdef DEBUG
  274. ktime_t perf_setup_time;
  275. ktime_t perf_start_time;
  276. #endif
  277. int debug_read;
  278. int debug_write;
  279. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  280. spinlock_t irq_stats_lock;
  281. struct dsi_irq_stats irq_stats;
  282. #endif
  283. /* DSI PLL Parameter Ranges */
  284. unsigned long regm_max, regn_max;
  285. unsigned long regm_dispc_max, regm_dsi_max;
  286. unsigned long fint_min, fint_max;
  287. unsigned long lpdiv_max;
  288. int num_data_lanes;
  289. unsigned scp_clk_refcount;
  290. };
  291. struct dsi_packet_sent_handler_data {
  292. struct platform_device *dsidev;
  293. struct completion *completion;
  294. };
  295. static struct platform_device *dsi_pdev_map[MAX_NUM_DSI];
  296. #ifdef DEBUG
  297. static unsigned int dsi_perf;
  298. module_param_named(dsi_perf, dsi_perf, bool, 0644);
  299. #endif
  300. static inline struct dsi_data *dsi_get_dsidrv_data(struct platform_device *dsidev)
  301. {
  302. return dev_get_drvdata(&dsidev->dev);
  303. }
  304. static inline struct platform_device *dsi_get_dsidev_from_dssdev(struct omap_dss_device *dssdev)
  305. {
  306. return dsi_pdev_map[dssdev->phy.dsi.module];
  307. }
  308. struct platform_device *dsi_get_dsidev_from_id(int module)
  309. {
  310. return dsi_pdev_map[module];
  311. }
  312. static int dsi_get_dsidev_id(struct platform_device *dsidev)
  313. {
  314. /* TEMP: Pass 0 as the dsi module index till the time the dsi platform
  315. * device names aren't changed to the form "omapdss_dsi.0",
  316. * "omapdss_dsi.1" and so on */
  317. BUG_ON(dsidev->id != -1);
  318. return 0;
  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_save_context(void)
  333. {
  334. }
  335. void dsi_restore_context(void)
  336. {
  337. }
  338. void dsi_bus_lock(struct omap_dss_device *dssdev)
  339. {
  340. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  341. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  342. down(&dsi->bus_lock);
  343. }
  344. EXPORT_SYMBOL(dsi_bus_lock);
  345. void dsi_bus_unlock(struct omap_dss_device *dssdev)
  346. {
  347. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  348. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  349. up(&dsi->bus_lock);
  350. }
  351. EXPORT_SYMBOL(dsi_bus_unlock);
  352. static bool dsi_bus_is_locked(struct platform_device *dsidev)
  353. {
  354. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  355. return dsi->bus_lock.count == 0;
  356. }
  357. static void dsi_completion_handler(void *data, u32 mask)
  358. {
  359. complete((struct completion *)data);
  360. }
  361. static inline int wait_for_bit_change(struct platform_device *dsidev,
  362. const struct dsi_reg idx, int bitnum, int value)
  363. {
  364. int t = 100000;
  365. while (REG_GET(dsidev, idx, bitnum, bitnum) != value) {
  366. if (--t == 0)
  367. return !value;
  368. }
  369. return value;
  370. }
  371. #ifdef DEBUG
  372. static void dsi_perf_mark_setup(struct platform_device *dsidev)
  373. {
  374. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  375. dsi->perf_setup_time = ktime_get();
  376. }
  377. static void dsi_perf_mark_start(struct platform_device *dsidev)
  378. {
  379. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  380. dsi->perf_start_time = ktime_get();
  381. }
  382. static void dsi_perf_show(struct platform_device *dsidev, const char *name)
  383. {
  384. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  385. ktime_t t, setup_time, trans_time;
  386. u32 total_bytes;
  387. u32 setup_us, trans_us, total_us;
  388. if (!dsi_perf)
  389. return;
  390. t = ktime_get();
  391. setup_time = ktime_sub(dsi->perf_start_time, dsi->perf_setup_time);
  392. setup_us = (u32)ktime_to_us(setup_time);
  393. if (setup_us == 0)
  394. setup_us = 1;
  395. trans_time = ktime_sub(t, dsi->perf_start_time);
  396. trans_us = (u32)ktime_to_us(trans_time);
  397. if (trans_us == 0)
  398. trans_us = 1;
  399. total_us = setup_us + trans_us;
  400. total_bytes = dsi->update_region.w *
  401. dsi->update_region.h *
  402. dsi->update_region.device->ctrl.pixel_size / 8;
  403. printk(KERN_INFO "DSI(%s): %u us + %u us = %u us (%uHz), "
  404. "%u bytes, %u kbytes/sec\n",
  405. name,
  406. setup_us,
  407. trans_us,
  408. total_us,
  409. 1000*1000 / total_us,
  410. total_bytes,
  411. total_bytes * 1000 / total_us);
  412. }
  413. #else
  414. static inline void dsi_perf_mark_setup(struct platform_device *dsidev)
  415. {
  416. }
  417. static inline void dsi_perf_mark_start(struct platform_device *dsidev)
  418. {
  419. }
  420. static inline void dsi_perf_show(struct platform_device *dsidev,
  421. const char *name)
  422. {
  423. }
  424. #endif
  425. static void print_irq_status(u32 status)
  426. {
  427. if (status == 0)
  428. return;
  429. #ifndef VERBOSE_IRQ
  430. if ((status & ~DSI_IRQ_CHANNEL_MASK) == 0)
  431. return;
  432. #endif
  433. printk(KERN_DEBUG "DSI IRQ: 0x%x: ", status);
  434. #define PIS(x) \
  435. if (status & DSI_IRQ_##x) \
  436. printk(#x " ");
  437. #ifdef VERBOSE_IRQ
  438. PIS(VC0);
  439. PIS(VC1);
  440. PIS(VC2);
  441. PIS(VC3);
  442. #endif
  443. PIS(WAKEUP);
  444. PIS(RESYNC);
  445. PIS(PLL_LOCK);
  446. PIS(PLL_UNLOCK);
  447. PIS(PLL_RECALL);
  448. PIS(COMPLEXIO_ERR);
  449. PIS(HS_TX_TIMEOUT);
  450. PIS(LP_RX_TIMEOUT);
  451. PIS(TE_TRIGGER);
  452. PIS(ACK_TRIGGER);
  453. PIS(SYNC_LOST);
  454. PIS(LDO_POWER_GOOD);
  455. PIS(TA_TIMEOUT);
  456. #undef PIS
  457. printk("\n");
  458. }
  459. static void print_irq_status_vc(int channel, u32 status)
  460. {
  461. if (status == 0)
  462. return;
  463. #ifndef VERBOSE_IRQ
  464. if ((status & ~DSI_VC_IRQ_PACKET_SENT) == 0)
  465. return;
  466. #endif
  467. printk(KERN_DEBUG "DSI VC(%d) IRQ 0x%x: ", channel, status);
  468. #define PIS(x) \
  469. if (status & DSI_VC_IRQ_##x) \
  470. printk(#x " ");
  471. PIS(CS);
  472. PIS(ECC_CORR);
  473. #ifdef VERBOSE_IRQ
  474. PIS(PACKET_SENT);
  475. #endif
  476. PIS(FIFO_TX_OVF);
  477. PIS(FIFO_RX_OVF);
  478. PIS(BTA);
  479. PIS(ECC_NO_CORR);
  480. PIS(FIFO_TX_UDF);
  481. PIS(PP_BUSY_CHANGE);
  482. #undef PIS
  483. printk("\n");
  484. }
  485. static void print_irq_status_cio(u32 status)
  486. {
  487. if (status == 0)
  488. return;
  489. printk(KERN_DEBUG "DSI CIO IRQ 0x%x: ", status);
  490. #define PIS(x) \
  491. if (status & DSI_CIO_IRQ_##x) \
  492. printk(#x " ");
  493. PIS(ERRSYNCESC1);
  494. PIS(ERRSYNCESC2);
  495. PIS(ERRSYNCESC3);
  496. PIS(ERRESC1);
  497. PIS(ERRESC2);
  498. PIS(ERRESC3);
  499. PIS(ERRCONTROL1);
  500. PIS(ERRCONTROL2);
  501. PIS(ERRCONTROL3);
  502. PIS(STATEULPS1);
  503. PIS(STATEULPS2);
  504. PIS(STATEULPS3);
  505. PIS(ERRCONTENTIONLP0_1);
  506. PIS(ERRCONTENTIONLP1_1);
  507. PIS(ERRCONTENTIONLP0_2);
  508. PIS(ERRCONTENTIONLP1_2);
  509. PIS(ERRCONTENTIONLP0_3);
  510. PIS(ERRCONTENTIONLP1_3);
  511. PIS(ULPSACTIVENOT_ALL0);
  512. PIS(ULPSACTIVENOT_ALL1);
  513. #undef PIS
  514. printk("\n");
  515. }
  516. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  517. static void dsi_collect_irq_stats(struct platform_device *dsidev, u32 irqstatus,
  518. u32 *vcstatus, u32 ciostatus)
  519. {
  520. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  521. int i;
  522. spin_lock(&dsi->irq_stats_lock);
  523. dsi->irq_stats.irq_count++;
  524. dss_collect_irq_stats(irqstatus, dsi->irq_stats.dsi_irqs);
  525. for (i = 0; i < 4; ++i)
  526. dss_collect_irq_stats(vcstatus[i], dsi->irq_stats.vc_irqs[i]);
  527. dss_collect_irq_stats(ciostatus, dsi->irq_stats.cio_irqs);
  528. spin_unlock(&dsi->irq_stats_lock);
  529. }
  530. #else
  531. #define dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus)
  532. #endif
  533. static int debug_irq;
  534. static void dsi_handle_irq_errors(struct platform_device *dsidev, u32 irqstatus,
  535. u32 *vcstatus, u32 ciostatus)
  536. {
  537. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  538. int i;
  539. if (irqstatus & DSI_IRQ_ERROR_MASK) {
  540. DSSERR("DSI error, irqstatus %x\n", irqstatus);
  541. print_irq_status(irqstatus);
  542. spin_lock(&dsi->errors_lock);
  543. dsi->errors |= irqstatus & DSI_IRQ_ERROR_MASK;
  544. spin_unlock(&dsi->errors_lock);
  545. } else if (debug_irq) {
  546. print_irq_status(irqstatus);
  547. }
  548. for (i = 0; i < 4; ++i) {
  549. if (vcstatus[i] & DSI_VC_IRQ_ERROR_MASK) {
  550. DSSERR("DSI VC(%d) error, vc irqstatus %x\n",
  551. i, vcstatus[i]);
  552. print_irq_status_vc(i, vcstatus[i]);
  553. } else if (debug_irq) {
  554. print_irq_status_vc(i, vcstatus[i]);
  555. }
  556. }
  557. if (ciostatus & DSI_CIO_IRQ_ERROR_MASK) {
  558. DSSERR("DSI CIO error, cio irqstatus %x\n", ciostatus);
  559. print_irq_status_cio(ciostatus);
  560. } else if (debug_irq) {
  561. print_irq_status_cio(ciostatus);
  562. }
  563. }
  564. static void dsi_call_isrs(struct dsi_isr_data *isr_array,
  565. unsigned isr_array_size, u32 irqstatus)
  566. {
  567. struct dsi_isr_data *isr_data;
  568. int i;
  569. for (i = 0; i < isr_array_size; i++) {
  570. isr_data = &isr_array[i];
  571. if (isr_data->isr && isr_data->mask & irqstatus)
  572. isr_data->isr(isr_data->arg, irqstatus);
  573. }
  574. }
  575. static void dsi_handle_isrs(struct dsi_isr_tables *isr_tables,
  576. u32 irqstatus, u32 *vcstatus, u32 ciostatus)
  577. {
  578. int i;
  579. dsi_call_isrs(isr_tables->isr_table,
  580. ARRAY_SIZE(isr_tables->isr_table),
  581. irqstatus);
  582. for (i = 0; i < 4; ++i) {
  583. if (vcstatus[i] == 0)
  584. continue;
  585. dsi_call_isrs(isr_tables->isr_table_vc[i],
  586. ARRAY_SIZE(isr_tables->isr_table_vc[i]),
  587. vcstatus[i]);
  588. }
  589. if (ciostatus != 0)
  590. dsi_call_isrs(isr_tables->isr_table_cio,
  591. ARRAY_SIZE(isr_tables->isr_table_cio),
  592. ciostatus);
  593. }
  594. static irqreturn_t omap_dsi_irq_handler(int irq, void *arg)
  595. {
  596. struct platform_device *dsidev;
  597. struct dsi_data *dsi;
  598. u32 irqstatus, vcstatus[4], ciostatus;
  599. int i;
  600. dsidev = (struct platform_device *) arg;
  601. dsi = dsi_get_dsidrv_data(dsidev);
  602. spin_lock(&dsi->irq_lock);
  603. irqstatus = dsi_read_reg(dsidev, DSI_IRQSTATUS);
  604. /* IRQ is not for us */
  605. if (!irqstatus) {
  606. spin_unlock(&dsi->irq_lock);
  607. return IRQ_NONE;
  608. }
  609. dsi_write_reg(dsidev, DSI_IRQSTATUS, irqstatus & ~DSI_IRQ_CHANNEL_MASK);
  610. /* flush posted write */
  611. dsi_read_reg(dsidev, DSI_IRQSTATUS);
  612. for (i = 0; i < 4; ++i) {
  613. if ((irqstatus & (1 << i)) == 0) {
  614. vcstatus[i] = 0;
  615. continue;
  616. }
  617. vcstatus[i] = dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  618. dsi_write_reg(dsidev, DSI_VC_IRQSTATUS(i), vcstatus[i]);
  619. /* flush posted write */
  620. dsi_read_reg(dsidev, DSI_VC_IRQSTATUS(i));
  621. }
  622. if (irqstatus & DSI_IRQ_COMPLEXIO_ERR) {
  623. ciostatus = dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  624. dsi_write_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS, ciostatus);
  625. /* flush posted write */
  626. dsi_read_reg(dsidev, DSI_COMPLEXIO_IRQ_STATUS);
  627. } else {
  628. ciostatus = 0;
  629. }
  630. #ifdef DSI_CATCH_MISSING_TE
  631. if (irqstatus & DSI_IRQ_TE_TRIGGER)
  632. del_timer(&dsi->te_timer);
  633. #endif
  634. /* make a copy and unlock, so that isrs can unregister
  635. * themselves */
  636. memcpy(&dsi->isr_tables_copy, &dsi->isr_tables,
  637. sizeof(dsi->isr_tables));
  638. spin_unlock(&dsi->irq_lock);
  639. dsi_handle_isrs(&dsi->isr_tables_copy, irqstatus, vcstatus, ciostatus);
  640. dsi_handle_irq_errors(dsidev, irqstatus, vcstatus, ciostatus);
  641. dsi_collect_irq_stats(dsidev, irqstatus, vcstatus, ciostatus);
  642. return IRQ_HANDLED;
  643. }
  644. /* dsi->irq_lock has to be locked by the caller */
  645. static void _omap_dsi_configure_irqs(struct platform_device *dsidev,
  646. struct dsi_isr_data *isr_array,
  647. unsigned isr_array_size, u32 default_mask,
  648. const struct dsi_reg enable_reg,
  649. const struct dsi_reg status_reg)
  650. {
  651. struct dsi_isr_data *isr_data;
  652. u32 mask;
  653. u32 old_mask;
  654. int i;
  655. mask = default_mask;
  656. for (i = 0; i < isr_array_size; i++) {
  657. isr_data = &isr_array[i];
  658. if (isr_data->isr == NULL)
  659. continue;
  660. mask |= isr_data->mask;
  661. }
  662. old_mask = dsi_read_reg(dsidev, enable_reg);
  663. /* clear the irqstatus for newly enabled irqs */
  664. dsi_write_reg(dsidev, status_reg, (mask ^ old_mask) & mask);
  665. dsi_write_reg(dsidev, enable_reg, mask);
  666. /* flush posted writes */
  667. dsi_read_reg(dsidev, enable_reg);
  668. dsi_read_reg(dsidev, status_reg);
  669. }
  670. /* dsi->irq_lock has to be locked by the caller */
  671. static void _omap_dsi_set_irqs(struct platform_device *dsidev)
  672. {
  673. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  674. u32 mask = DSI_IRQ_ERROR_MASK;
  675. #ifdef DSI_CATCH_MISSING_TE
  676. mask |= DSI_IRQ_TE_TRIGGER;
  677. #endif
  678. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table,
  679. ARRAY_SIZE(dsi->isr_tables.isr_table), mask,
  680. DSI_IRQENABLE, DSI_IRQSTATUS);
  681. }
  682. /* dsi->irq_lock has to be locked by the caller */
  683. static void _omap_dsi_set_irqs_vc(struct platform_device *dsidev, int vc)
  684. {
  685. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  686. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_vc[vc],
  687. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[vc]),
  688. DSI_VC_IRQ_ERROR_MASK,
  689. DSI_VC_IRQENABLE(vc), DSI_VC_IRQSTATUS(vc));
  690. }
  691. /* dsi->irq_lock has to be locked by the caller */
  692. static void _omap_dsi_set_irqs_cio(struct platform_device *dsidev)
  693. {
  694. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  695. _omap_dsi_configure_irqs(dsidev, dsi->isr_tables.isr_table_cio,
  696. ARRAY_SIZE(dsi->isr_tables.isr_table_cio),
  697. DSI_CIO_IRQ_ERROR_MASK,
  698. DSI_COMPLEXIO_IRQ_ENABLE, DSI_COMPLEXIO_IRQ_STATUS);
  699. }
  700. static void _dsi_initialize_irq(struct platform_device *dsidev)
  701. {
  702. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  703. unsigned long flags;
  704. int vc;
  705. spin_lock_irqsave(&dsi->irq_lock, flags);
  706. memset(&dsi->isr_tables, 0, sizeof(dsi->isr_tables));
  707. _omap_dsi_set_irqs(dsidev);
  708. for (vc = 0; vc < 4; ++vc)
  709. _omap_dsi_set_irqs_vc(dsidev, vc);
  710. _omap_dsi_set_irqs_cio(dsidev);
  711. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  712. }
  713. static int _dsi_register_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  714. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  715. {
  716. struct dsi_isr_data *isr_data;
  717. int free_idx;
  718. int i;
  719. BUG_ON(isr == NULL);
  720. /* check for duplicate entry and find a free slot */
  721. free_idx = -1;
  722. for (i = 0; i < isr_array_size; i++) {
  723. isr_data = &isr_array[i];
  724. if (isr_data->isr == isr && isr_data->arg == arg &&
  725. isr_data->mask == mask) {
  726. return -EINVAL;
  727. }
  728. if (isr_data->isr == NULL && free_idx == -1)
  729. free_idx = i;
  730. }
  731. if (free_idx == -1)
  732. return -EBUSY;
  733. isr_data = &isr_array[free_idx];
  734. isr_data->isr = isr;
  735. isr_data->arg = arg;
  736. isr_data->mask = mask;
  737. return 0;
  738. }
  739. static int _dsi_unregister_isr(omap_dsi_isr_t isr, void *arg, u32 mask,
  740. struct dsi_isr_data *isr_array, unsigned isr_array_size)
  741. {
  742. struct dsi_isr_data *isr_data;
  743. int i;
  744. for (i = 0; i < isr_array_size; i++) {
  745. isr_data = &isr_array[i];
  746. if (isr_data->isr != isr || isr_data->arg != arg ||
  747. isr_data->mask != mask)
  748. continue;
  749. isr_data->isr = NULL;
  750. isr_data->arg = NULL;
  751. isr_data->mask = 0;
  752. return 0;
  753. }
  754. return -EINVAL;
  755. }
  756. static int dsi_register_isr(struct platform_device *dsidev, omap_dsi_isr_t isr,
  757. void *arg, u32 mask)
  758. {
  759. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  760. unsigned long flags;
  761. int r;
  762. spin_lock_irqsave(&dsi->irq_lock, flags);
  763. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  764. ARRAY_SIZE(dsi->isr_tables.isr_table));
  765. if (r == 0)
  766. _omap_dsi_set_irqs(dsidev);
  767. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  768. return r;
  769. }
  770. static int dsi_unregister_isr(struct platform_device *dsidev,
  771. omap_dsi_isr_t isr, void *arg, u32 mask)
  772. {
  773. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  774. unsigned long flags;
  775. int r;
  776. spin_lock_irqsave(&dsi->irq_lock, flags);
  777. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table,
  778. ARRAY_SIZE(dsi->isr_tables.isr_table));
  779. if (r == 0)
  780. _omap_dsi_set_irqs(dsidev);
  781. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  782. return r;
  783. }
  784. static int dsi_register_isr_vc(struct platform_device *dsidev, int channel,
  785. omap_dsi_isr_t isr, void *arg, u32 mask)
  786. {
  787. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  788. unsigned long flags;
  789. int r;
  790. spin_lock_irqsave(&dsi->irq_lock, flags);
  791. r = _dsi_register_isr(isr, arg, mask,
  792. dsi->isr_tables.isr_table_vc[channel],
  793. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  794. if (r == 0)
  795. _omap_dsi_set_irqs_vc(dsidev, channel);
  796. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  797. return r;
  798. }
  799. static int dsi_unregister_isr_vc(struct platform_device *dsidev, int channel,
  800. omap_dsi_isr_t isr, void *arg, u32 mask)
  801. {
  802. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  803. unsigned long flags;
  804. int r;
  805. spin_lock_irqsave(&dsi->irq_lock, flags);
  806. r = _dsi_unregister_isr(isr, arg, mask,
  807. dsi->isr_tables.isr_table_vc[channel],
  808. ARRAY_SIZE(dsi->isr_tables.isr_table_vc[channel]));
  809. if (r == 0)
  810. _omap_dsi_set_irqs_vc(dsidev, channel);
  811. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  812. return r;
  813. }
  814. static int dsi_register_isr_cio(struct platform_device *dsidev,
  815. omap_dsi_isr_t isr, void *arg, u32 mask)
  816. {
  817. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  818. unsigned long flags;
  819. int r;
  820. spin_lock_irqsave(&dsi->irq_lock, flags);
  821. r = _dsi_register_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  822. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  823. if (r == 0)
  824. _omap_dsi_set_irqs_cio(dsidev);
  825. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  826. return r;
  827. }
  828. static int dsi_unregister_isr_cio(struct platform_device *dsidev,
  829. omap_dsi_isr_t isr, void *arg, u32 mask)
  830. {
  831. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  832. unsigned long flags;
  833. int r;
  834. spin_lock_irqsave(&dsi->irq_lock, flags);
  835. r = _dsi_unregister_isr(isr, arg, mask, dsi->isr_tables.isr_table_cio,
  836. ARRAY_SIZE(dsi->isr_tables.isr_table_cio));
  837. if (r == 0)
  838. _omap_dsi_set_irqs_cio(dsidev);
  839. spin_unlock_irqrestore(&dsi->irq_lock, flags);
  840. return r;
  841. }
  842. static u32 dsi_get_errors(struct platform_device *dsidev)
  843. {
  844. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  845. unsigned long flags;
  846. u32 e;
  847. spin_lock_irqsave(&dsi->errors_lock, flags);
  848. e = dsi->errors;
  849. dsi->errors = 0;
  850. spin_unlock_irqrestore(&dsi->errors_lock, flags);
  851. return e;
  852. }
  853. /* DSI func clock. this could also be dsi_pll_hsdiv_dsi_clk */
  854. static inline void enable_clocks(bool enable)
  855. {
  856. if (enable)
  857. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  858. else
  859. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  860. }
  861. /* source clock for DSI PLL. this could also be PCLKFREE */
  862. static inline void dsi_enable_pll_clock(struct platform_device *dsidev,
  863. bool enable)
  864. {
  865. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  866. if (enable)
  867. dss_clk_enable(DSS_CLK_SYSCK);
  868. else
  869. dss_clk_disable(DSS_CLK_SYSCK);
  870. if (enable && dsi->pll_locked) {
  871. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1)
  872. DSSERR("cannot lock PLL when enabling clocks\n");
  873. }
  874. }
  875. #ifdef DEBUG
  876. static void _dsi_print_reset_status(struct platform_device *dsidev)
  877. {
  878. u32 l;
  879. int b0, b1, b2;
  880. if (!dss_debug)
  881. return;
  882. /* A dummy read using the SCP interface to any DSIPHY register is
  883. * required after DSIPHY reset to complete the reset of the DSI complex
  884. * I/O. */
  885. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  886. printk(KERN_DEBUG "DSI resets: ");
  887. l = dsi_read_reg(dsidev, DSI_PLL_STATUS);
  888. printk("PLL (%d) ", FLD_GET(l, 0, 0));
  889. l = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  890. printk("CIO (%d) ", FLD_GET(l, 29, 29));
  891. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  892. b0 = 28;
  893. b1 = 27;
  894. b2 = 26;
  895. } else {
  896. b0 = 24;
  897. b1 = 25;
  898. b2 = 26;
  899. }
  900. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  901. printk("PHY (%x%x%x, %d, %d, %d)\n",
  902. FLD_GET(l, b0, b0),
  903. FLD_GET(l, b1, b1),
  904. FLD_GET(l, b2, b2),
  905. FLD_GET(l, 29, 29),
  906. FLD_GET(l, 30, 30),
  907. FLD_GET(l, 31, 31));
  908. }
  909. #else
  910. #define _dsi_print_reset_status(x)
  911. #endif
  912. static inline int dsi_if_enable(struct platform_device *dsidev, bool enable)
  913. {
  914. DSSDBG("dsi_if_enable(%d)\n", enable);
  915. enable = enable ? 1 : 0;
  916. REG_FLD_MOD(dsidev, DSI_CTRL, enable, 0, 0); /* IF_EN */
  917. if (wait_for_bit_change(dsidev, DSI_CTRL, 0, enable) != enable) {
  918. DSSERR("Failed to set dsi_if_enable to %d\n", enable);
  919. return -EIO;
  920. }
  921. return 0;
  922. }
  923. unsigned long dsi_get_pll_hsdiv_dispc_rate(struct platform_device *dsidev)
  924. {
  925. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  926. return dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk;
  927. }
  928. static unsigned long dsi_get_pll_hsdiv_dsi_rate(struct platform_device *dsidev)
  929. {
  930. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  931. return dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk;
  932. }
  933. static unsigned long dsi_get_txbyteclkhs(struct platform_device *dsidev)
  934. {
  935. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  936. return dsi->current_cinfo.clkin4ddr / 16;
  937. }
  938. static unsigned long dsi_fclk_rate(struct platform_device *dsidev)
  939. {
  940. unsigned long r;
  941. int dsi_module = dsi_get_dsidev_id(dsidev);
  942. if (dss_get_dsi_clk_source(dsi_module) == OMAP_DSS_CLK_SRC_FCK) {
  943. /* DSI FCLK source is DSS_CLK_FCK */
  944. r = dss_clk_get_rate(DSS_CLK_FCK);
  945. } else {
  946. /* DSI FCLK source is dsi_pll_hsdiv_dsi_clk */
  947. r = dsi_get_pll_hsdiv_dsi_rate(dsidev);
  948. }
  949. return r;
  950. }
  951. static int dsi_set_lp_clk_divisor(struct omap_dss_device *dssdev)
  952. {
  953. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  954. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  955. unsigned long dsi_fclk;
  956. unsigned lp_clk_div;
  957. unsigned long lp_clk;
  958. lp_clk_div = dssdev->clocks.dsi.lp_clk_div;
  959. if (lp_clk_div == 0 || lp_clk_div > dsi->lpdiv_max)
  960. return -EINVAL;
  961. dsi_fclk = dsi_fclk_rate(dsidev);
  962. lp_clk = dsi_fclk / 2 / lp_clk_div;
  963. DSSDBG("LP_CLK_DIV %u, LP_CLK %lu\n", lp_clk_div, lp_clk);
  964. dsi->current_cinfo.lp_clk = lp_clk;
  965. dsi->current_cinfo.lp_clk_div = lp_clk_div;
  966. /* LP_CLK_DIVISOR */
  967. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, lp_clk_div, 12, 0);
  968. /* LP_RX_SYNCHRO_ENABLE */
  969. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, dsi_fclk > 30000000 ? 1 : 0, 21, 21);
  970. return 0;
  971. }
  972. static void dsi_enable_scp_clk(struct platform_device *dsidev)
  973. {
  974. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  975. if (dsi->scp_clk_refcount++ == 0)
  976. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 14, 14); /* CIO_CLK_ICG */
  977. }
  978. static void dsi_disable_scp_clk(struct platform_device *dsidev)
  979. {
  980. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  981. WARN_ON(dsi->scp_clk_refcount == 0);
  982. if (--dsi->scp_clk_refcount == 0)
  983. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 14, 14); /* CIO_CLK_ICG */
  984. }
  985. enum dsi_pll_power_state {
  986. DSI_PLL_POWER_OFF = 0x0,
  987. DSI_PLL_POWER_ON_HSCLK = 0x1,
  988. DSI_PLL_POWER_ON_ALL = 0x2,
  989. DSI_PLL_POWER_ON_DIV = 0x3,
  990. };
  991. static int dsi_pll_power(struct platform_device *dsidev,
  992. enum dsi_pll_power_state state)
  993. {
  994. int t = 0;
  995. /* DSI-PLL power command 0x3 is not working */
  996. if (dss_has_feature(FEAT_DSI_PLL_PWR_BUG) &&
  997. state == DSI_PLL_POWER_ON_DIV)
  998. state = DSI_PLL_POWER_ON_ALL;
  999. /* PLL_PWR_CMD */
  1000. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, state, 31, 30);
  1001. /* PLL_PWR_STATUS */
  1002. while (FLD_GET(dsi_read_reg(dsidev, DSI_CLK_CTRL), 29, 28) != state) {
  1003. if (++t > 1000) {
  1004. DSSERR("Failed to set DSI PLL power mode to %d\n",
  1005. state);
  1006. return -ENODEV;
  1007. }
  1008. udelay(1);
  1009. }
  1010. return 0;
  1011. }
  1012. /* calculate clock rates using dividers in cinfo */
  1013. static int dsi_calc_clock_rates(struct omap_dss_device *dssdev,
  1014. struct dsi_clock_info *cinfo)
  1015. {
  1016. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1017. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1018. if (cinfo->regn == 0 || cinfo->regn > dsi->regn_max)
  1019. return -EINVAL;
  1020. if (cinfo->regm == 0 || cinfo->regm > dsi->regm_max)
  1021. return -EINVAL;
  1022. if (cinfo->regm_dispc > dsi->regm_dispc_max)
  1023. return -EINVAL;
  1024. if (cinfo->regm_dsi > dsi->regm_dsi_max)
  1025. return -EINVAL;
  1026. if (cinfo->use_sys_clk) {
  1027. cinfo->clkin = dss_clk_get_rate(DSS_CLK_SYSCK);
  1028. /* XXX it is unclear if highfreq should be used
  1029. * with DSS_SYS_CLK source also */
  1030. cinfo->highfreq = 0;
  1031. } else {
  1032. cinfo->clkin = dispc_pclk_rate(dssdev->manager->id);
  1033. if (cinfo->clkin < 32000000)
  1034. cinfo->highfreq = 0;
  1035. else
  1036. cinfo->highfreq = 1;
  1037. }
  1038. cinfo->fint = cinfo->clkin / (cinfo->regn * (cinfo->highfreq ? 2 : 1));
  1039. if (cinfo->fint > dsi->fint_max || cinfo->fint < dsi->fint_min)
  1040. return -EINVAL;
  1041. cinfo->clkin4ddr = 2 * cinfo->regm * cinfo->fint;
  1042. if (cinfo->clkin4ddr > 1800 * 1000 * 1000)
  1043. return -EINVAL;
  1044. if (cinfo->regm_dispc > 0)
  1045. cinfo->dsi_pll_hsdiv_dispc_clk =
  1046. cinfo->clkin4ddr / cinfo->regm_dispc;
  1047. else
  1048. cinfo->dsi_pll_hsdiv_dispc_clk = 0;
  1049. if (cinfo->regm_dsi > 0)
  1050. cinfo->dsi_pll_hsdiv_dsi_clk =
  1051. cinfo->clkin4ddr / cinfo->regm_dsi;
  1052. else
  1053. cinfo->dsi_pll_hsdiv_dsi_clk = 0;
  1054. return 0;
  1055. }
  1056. int dsi_pll_calc_clock_div_pck(struct platform_device *dsidev, bool is_tft,
  1057. unsigned long req_pck, struct dsi_clock_info *dsi_cinfo,
  1058. struct dispc_clock_info *dispc_cinfo)
  1059. {
  1060. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1061. struct dsi_clock_info cur, best;
  1062. struct dispc_clock_info best_dispc;
  1063. int min_fck_per_pck;
  1064. int match = 0;
  1065. unsigned long dss_sys_clk, max_dss_fck;
  1066. dss_sys_clk = dss_clk_get_rate(DSS_CLK_SYSCK);
  1067. max_dss_fck = dss_feat_get_param_max(FEAT_PARAM_DSS_FCK);
  1068. if (req_pck == dsi->cache_req_pck &&
  1069. dsi->cache_cinfo.clkin == dss_sys_clk) {
  1070. DSSDBG("DSI clock info found from cache\n");
  1071. *dsi_cinfo = dsi->cache_cinfo;
  1072. dispc_find_clk_divs(is_tft, req_pck,
  1073. dsi_cinfo->dsi_pll_hsdiv_dispc_clk, dispc_cinfo);
  1074. return 0;
  1075. }
  1076. min_fck_per_pck = CONFIG_OMAP2_DSS_MIN_FCK_PER_PCK;
  1077. if (min_fck_per_pck &&
  1078. req_pck * min_fck_per_pck > max_dss_fck) {
  1079. DSSERR("Requested pixel clock not possible with the current "
  1080. "OMAP2_DSS_MIN_FCK_PER_PCK setting. Turning "
  1081. "the constraint off.\n");
  1082. min_fck_per_pck = 0;
  1083. }
  1084. DSSDBG("dsi_pll_calc\n");
  1085. retry:
  1086. memset(&best, 0, sizeof(best));
  1087. memset(&best_dispc, 0, sizeof(best_dispc));
  1088. memset(&cur, 0, sizeof(cur));
  1089. cur.clkin = dss_sys_clk;
  1090. cur.use_sys_clk = 1;
  1091. cur.highfreq = 0;
  1092. /* no highfreq: 0.75MHz < Fint = clkin / regn < 2.1MHz */
  1093. /* highfreq: 0.75MHz < Fint = clkin / (2*regn) < 2.1MHz */
  1094. /* To reduce PLL lock time, keep Fint high (around 2 MHz) */
  1095. for (cur.regn = 1; cur.regn < dsi->regn_max; ++cur.regn) {
  1096. if (cur.highfreq == 0)
  1097. cur.fint = cur.clkin / cur.regn;
  1098. else
  1099. cur.fint = cur.clkin / (2 * cur.regn);
  1100. if (cur.fint > dsi->fint_max || cur.fint < dsi->fint_min)
  1101. continue;
  1102. /* DSIPHY(MHz) = (2 * regm / regn) * (clkin / (highfreq + 1)) */
  1103. for (cur.regm = 1; cur.regm < dsi->regm_max; ++cur.regm) {
  1104. unsigned long a, b;
  1105. a = 2 * cur.regm * (cur.clkin/1000);
  1106. b = cur.regn * (cur.highfreq + 1);
  1107. cur.clkin4ddr = a / b * 1000;
  1108. if (cur.clkin4ddr > 1800 * 1000 * 1000)
  1109. break;
  1110. /* dsi_pll_hsdiv_dispc_clk(MHz) =
  1111. * DSIPHY(MHz) / regm_dispc < 173MHz/186Mhz */
  1112. for (cur.regm_dispc = 1; cur.regm_dispc <
  1113. dsi->regm_dispc_max; ++cur.regm_dispc) {
  1114. struct dispc_clock_info cur_dispc;
  1115. cur.dsi_pll_hsdiv_dispc_clk =
  1116. cur.clkin4ddr / cur.regm_dispc;
  1117. /* this will narrow down the search a bit,
  1118. * but still give pixclocks below what was
  1119. * requested */
  1120. if (cur.dsi_pll_hsdiv_dispc_clk < req_pck)
  1121. break;
  1122. if (cur.dsi_pll_hsdiv_dispc_clk > max_dss_fck)
  1123. continue;
  1124. if (min_fck_per_pck &&
  1125. cur.dsi_pll_hsdiv_dispc_clk <
  1126. req_pck * min_fck_per_pck)
  1127. continue;
  1128. match = 1;
  1129. dispc_find_clk_divs(is_tft, req_pck,
  1130. cur.dsi_pll_hsdiv_dispc_clk,
  1131. &cur_dispc);
  1132. if (abs(cur_dispc.pck - req_pck) <
  1133. abs(best_dispc.pck - req_pck)) {
  1134. best = cur;
  1135. best_dispc = cur_dispc;
  1136. if (cur_dispc.pck == req_pck)
  1137. goto found;
  1138. }
  1139. }
  1140. }
  1141. }
  1142. found:
  1143. if (!match) {
  1144. if (min_fck_per_pck) {
  1145. DSSERR("Could not find suitable clock settings.\n"
  1146. "Turning FCK/PCK constraint off and"
  1147. "trying again.\n");
  1148. min_fck_per_pck = 0;
  1149. goto retry;
  1150. }
  1151. DSSERR("Could not find suitable clock settings.\n");
  1152. return -EINVAL;
  1153. }
  1154. /* dsi_pll_hsdiv_dsi_clk (regm_dsi) is not used */
  1155. best.regm_dsi = 0;
  1156. best.dsi_pll_hsdiv_dsi_clk = 0;
  1157. if (dsi_cinfo)
  1158. *dsi_cinfo = best;
  1159. if (dispc_cinfo)
  1160. *dispc_cinfo = best_dispc;
  1161. dsi->cache_req_pck = req_pck;
  1162. dsi->cache_clk_freq = 0;
  1163. dsi->cache_cinfo = best;
  1164. return 0;
  1165. }
  1166. int dsi_pll_set_clock_div(struct platform_device *dsidev,
  1167. struct dsi_clock_info *cinfo)
  1168. {
  1169. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1170. int r = 0;
  1171. u32 l;
  1172. int f = 0;
  1173. u8 regn_start, regn_end, regm_start, regm_end;
  1174. u8 regm_dispc_start, regm_dispc_end, regm_dsi_start, regm_dsi_end;
  1175. DSSDBGF();
  1176. dsi->current_cinfo.use_sys_clk = cinfo->use_sys_clk;
  1177. dsi->current_cinfo.highfreq = cinfo->highfreq;
  1178. dsi->current_cinfo.fint = cinfo->fint;
  1179. dsi->current_cinfo.clkin4ddr = cinfo->clkin4ddr;
  1180. dsi->current_cinfo.dsi_pll_hsdiv_dispc_clk =
  1181. cinfo->dsi_pll_hsdiv_dispc_clk;
  1182. dsi->current_cinfo.dsi_pll_hsdiv_dsi_clk =
  1183. cinfo->dsi_pll_hsdiv_dsi_clk;
  1184. dsi->current_cinfo.regn = cinfo->regn;
  1185. dsi->current_cinfo.regm = cinfo->regm;
  1186. dsi->current_cinfo.regm_dispc = cinfo->regm_dispc;
  1187. dsi->current_cinfo.regm_dsi = cinfo->regm_dsi;
  1188. DSSDBG("DSI Fint %ld\n", cinfo->fint);
  1189. DSSDBG("clkin (%s) rate %ld, highfreq %d\n",
  1190. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree",
  1191. cinfo->clkin,
  1192. cinfo->highfreq);
  1193. /* DSIPHY == CLKIN4DDR */
  1194. DSSDBG("CLKIN4DDR = 2 * %d / %d * %lu / %d = %lu\n",
  1195. cinfo->regm,
  1196. cinfo->regn,
  1197. cinfo->clkin,
  1198. cinfo->highfreq + 1,
  1199. cinfo->clkin4ddr);
  1200. DSSDBG("Data rate on 1 DSI lane %ld Mbps\n",
  1201. cinfo->clkin4ddr / 1000 / 1000 / 2);
  1202. DSSDBG("Clock lane freq %ld Hz\n", cinfo->clkin4ddr / 4);
  1203. DSSDBG("regm_dispc = %d, %s (%s) = %lu\n", cinfo->regm_dispc,
  1204. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1205. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  1206. cinfo->dsi_pll_hsdiv_dispc_clk);
  1207. DSSDBG("regm_dsi = %d, %s (%s) = %lu\n", cinfo->regm_dsi,
  1208. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1209. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  1210. cinfo->dsi_pll_hsdiv_dsi_clk);
  1211. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGN, &regn_start, &regn_end);
  1212. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM, &regm_start, &regm_end);
  1213. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DISPC, &regm_dispc_start,
  1214. &regm_dispc_end);
  1215. dss_feat_get_reg_field(FEAT_REG_DSIPLL_REGM_DSI, &regm_dsi_start,
  1216. &regm_dsi_end);
  1217. /* DSI_PLL_AUTOMODE = manual */
  1218. REG_FLD_MOD(dsidev, DSI_PLL_CONTROL, 0, 0, 0);
  1219. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION1);
  1220. l = FLD_MOD(l, 1, 0, 0); /* DSI_PLL_STOPMODE */
  1221. /* DSI_PLL_REGN */
  1222. l = FLD_MOD(l, cinfo->regn - 1, regn_start, regn_end);
  1223. /* DSI_PLL_REGM */
  1224. l = FLD_MOD(l, cinfo->regm, regm_start, regm_end);
  1225. /* DSI_CLOCK_DIV */
  1226. l = FLD_MOD(l, cinfo->regm_dispc > 0 ? cinfo->regm_dispc - 1 : 0,
  1227. regm_dispc_start, regm_dispc_end);
  1228. /* DSIPROTO_CLOCK_DIV */
  1229. l = FLD_MOD(l, cinfo->regm_dsi > 0 ? cinfo->regm_dsi - 1 : 0,
  1230. regm_dsi_start, regm_dsi_end);
  1231. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION1, l);
  1232. BUG_ON(cinfo->fint < dsi->fint_min || cinfo->fint > dsi->fint_max);
  1233. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL)) {
  1234. f = cinfo->fint < 1000000 ? 0x3 :
  1235. cinfo->fint < 1250000 ? 0x4 :
  1236. cinfo->fint < 1500000 ? 0x5 :
  1237. cinfo->fint < 1750000 ? 0x6 :
  1238. 0x7;
  1239. }
  1240. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1241. if (dss_has_feature(FEAT_DSI_PLL_FREQSEL))
  1242. l = FLD_MOD(l, f, 4, 1); /* DSI_PLL_FREQSEL */
  1243. l = FLD_MOD(l, cinfo->use_sys_clk ? 0 : 1,
  1244. 11, 11); /* DSI_PLL_CLKSEL */
  1245. l = FLD_MOD(l, cinfo->highfreq,
  1246. 12, 12); /* DSI_PLL_HIGHFREQ */
  1247. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1248. l = FLD_MOD(l, 0, 14, 14); /* DSIPHY_CLKINEN */
  1249. l = FLD_MOD(l, 1, 20, 20); /* DSI_HSDIVBYPASS */
  1250. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1251. REG_FLD_MOD(dsidev, DSI_PLL_GO, 1, 0, 0); /* DSI_PLL_GO */
  1252. if (wait_for_bit_change(dsidev, DSI_PLL_GO, 0, 0) != 0) {
  1253. DSSERR("dsi pll go bit not going down.\n");
  1254. r = -EIO;
  1255. goto err;
  1256. }
  1257. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 1, 1) != 1) {
  1258. DSSERR("cannot lock PLL\n");
  1259. r = -EIO;
  1260. goto err;
  1261. }
  1262. dsi->pll_locked = 1;
  1263. l = dsi_read_reg(dsidev, DSI_PLL_CONFIGURATION2);
  1264. l = FLD_MOD(l, 0, 0, 0); /* DSI_PLL_IDLE */
  1265. l = FLD_MOD(l, 0, 5, 5); /* DSI_PLL_PLLLPMODE */
  1266. l = FLD_MOD(l, 0, 6, 6); /* DSI_PLL_LOWCURRSTBY */
  1267. l = FLD_MOD(l, 0, 7, 7); /* DSI_PLL_TIGHTPHASELOCK */
  1268. l = FLD_MOD(l, 0, 8, 8); /* DSI_PLL_DRIFTGUARDEN */
  1269. l = FLD_MOD(l, 0, 10, 9); /* DSI_PLL_LOCKSEL */
  1270. l = FLD_MOD(l, 1, 13, 13); /* DSI_PLL_REFEN */
  1271. l = FLD_MOD(l, 1, 14, 14); /* DSIPHY_CLKINEN */
  1272. l = FLD_MOD(l, 0, 15, 15); /* DSI_BYPASSEN */
  1273. l = FLD_MOD(l, 1, 16, 16); /* DSS_CLOCK_EN */
  1274. l = FLD_MOD(l, 0, 17, 17); /* DSS_CLOCK_PWDN */
  1275. l = FLD_MOD(l, 1, 18, 18); /* DSI_PROTO_CLOCK_EN */
  1276. l = FLD_MOD(l, 0, 19, 19); /* DSI_PROTO_CLOCK_PWDN */
  1277. l = FLD_MOD(l, 0, 20, 20); /* DSI_HSDIVBYPASS */
  1278. dsi_write_reg(dsidev, DSI_PLL_CONFIGURATION2, l);
  1279. DSSDBG("PLL config done\n");
  1280. err:
  1281. return r;
  1282. }
  1283. int dsi_pll_init(struct platform_device *dsidev, bool enable_hsclk,
  1284. bool enable_hsdiv)
  1285. {
  1286. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1287. int r = 0;
  1288. enum dsi_pll_power_state pwstate;
  1289. DSSDBG("PLL init\n");
  1290. if (dsi->vdds_dsi_reg == NULL) {
  1291. struct regulator *vdds_dsi;
  1292. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  1293. if (IS_ERR(vdds_dsi)) {
  1294. DSSERR("can't get VDDS_DSI regulator\n");
  1295. return PTR_ERR(vdds_dsi);
  1296. }
  1297. dsi->vdds_dsi_reg = vdds_dsi;
  1298. }
  1299. enable_clocks(1);
  1300. dsi_enable_pll_clock(dsidev, 1);
  1301. /*
  1302. * Note: SCP CLK is not required on OMAP3, but it is required on OMAP4.
  1303. */
  1304. dsi_enable_scp_clk(dsidev);
  1305. if (!dsi->vdds_dsi_enabled) {
  1306. r = regulator_enable(dsi->vdds_dsi_reg);
  1307. if (r)
  1308. goto err0;
  1309. dsi->vdds_dsi_enabled = true;
  1310. }
  1311. /* XXX PLL does not come out of reset without this... */
  1312. dispc_pck_free_enable(1);
  1313. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 0, 1) != 1) {
  1314. DSSERR("PLL not coming out of reset.\n");
  1315. r = -ENODEV;
  1316. dispc_pck_free_enable(0);
  1317. goto err1;
  1318. }
  1319. /* XXX ... but if left on, we get problems when planes do not
  1320. * fill the whole display. No idea about this */
  1321. dispc_pck_free_enable(0);
  1322. if (enable_hsclk && enable_hsdiv)
  1323. pwstate = DSI_PLL_POWER_ON_ALL;
  1324. else if (enable_hsclk)
  1325. pwstate = DSI_PLL_POWER_ON_HSCLK;
  1326. else if (enable_hsdiv)
  1327. pwstate = DSI_PLL_POWER_ON_DIV;
  1328. else
  1329. pwstate = DSI_PLL_POWER_OFF;
  1330. r = dsi_pll_power(dsidev, pwstate);
  1331. if (r)
  1332. goto err1;
  1333. DSSDBG("PLL init done\n");
  1334. return 0;
  1335. err1:
  1336. if (dsi->vdds_dsi_enabled) {
  1337. regulator_disable(dsi->vdds_dsi_reg);
  1338. dsi->vdds_dsi_enabled = false;
  1339. }
  1340. err0:
  1341. dsi_disable_scp_clk(dsidev);
  1342. enable_clocks(0);
  1343. dsi_enable_pll_clock(dsidev, 0);
  1344. return r;
  1345. }
  1346. void dsi_pll_uninit(struct platform_device *dsidev, bool disconnect_lanes)
  1347. {
  1348. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1349. dsi->pll_locked = 0;
  1350. dsi_pll_power(dsidev, DSI_PLL_POWER_OFF);
  1351. if (disconnect_lanes) {
  1352. WARN_ON(!dsi->vdds_dsi_enabled);
  1353. regulator_disable(dsi->vdds_dsi_reg);
  1354. dsi->vdds_dsi_enabled = false;
  1355. }
  1356. dsi_disable_scp_clk(dsidev);
  1357. enable_clocks(0);
  1358. dsi_enable_pll_clock(dsidev, 0);
  1359. DSSDBG("PLL uninit done\n");
  1360. }
  1361. static void dsi_dump_dsidev_clocks(struct platform_device *dsidev,
  1362. struct seq_file *s)
  1363. {
  1364. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1365. struct dsi_clock_info *cinfo = &dsi->current_cinfo;
  1366. enum omap_dss_clk_source dispc_clk_src, dsi_clk_src;
  1367. int dsi_module = dsi_get_dsidev_id(dsidev);
  1368. dispc_clk_src = dss_get_dispc_clk_source();
  1369. dsi_clk_src = dss_get_dsi_clk_source(dsi_module);
  1370. enable_clocks(1);
  1371. seq_printf(s, "- DSI%d PLL -\n", dsi_module + 1);
  1372. seq_printf(s, "dsi pll source = %s\n",
  1373. cinfo->use_sys_clk ? "dss_sys_clk" : "pclkfree");
  1374. seq_printf(s, "Fint\t\t%-16luregn %u\n", cinfo->fint, cinfo->regn);
  1375. seq_printf(s, "CLKIN4DDR\t%-16luregm %u\n",
  1376. cinfo->clkin4ddr, cinfo->regm);
  1377. seq_printf(s, "%s (%s)\t%-16luregm_dispc %u\t(%s)\n",
  1378. dss_get_generic_clk_source_name(dispc_clk_src),
  1379. dss_feat_get_clk_source_name(dispc_clk_src),
  1380. cinfo->dsi_pll_hsdiv_dispc_clk,
  1381. cinfo->regm_dispc,
  1382. dispc_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1383. "off" : "on");
  1384. seq_printf(s, "%s (%s)\t%-16luregm_dsi %u\t(%s)\n",
  1385. dss_get_generic_clk_source_name(dsi_clk_src),
  1386. dss_feat_get_clk_source_name(dsi_clk_src),
  1387. cinfo->dsi_pll_hsdiv_dsi_clk,
  1388. cinfo->regm_dsi,
  1389. dsi_clk_src == OMAP_DSS_CLK_SRC_FCK ?
  1390. "off" : "on");
  1391. seq_printf(s, "- DSI%d -\n", dsi_module + 1);
  1392. seq_printf(s, "dsi fclk source = %s (%s)\n",
  1393. dss_get_generic_clk_source_name(dsi_clk_src),
  1394. dss_feat_get_clk_source_name(dsi_clk_src));
  1395. seq_printf(s, "DSI_FCLK\t%lu\n", dsi_fclk_rate(dsidev));
  1396. seq_printf(s, "DDR_CLK\t\t%lu\n",
  1397. cinfo->clkin4ddr / 4);
  1398. seq_printf(s, "TxByteClkHS\t%lu\n", dsi_get_txbyteclkhs(dsidev));
  1399. seq_printf(s, "LP_CLK\t\t%lu\n", cinfo->lp_clk);
  1400. enable_clocks(0);
  1401. }
  1402. void dsi_dump_clocks(struct seq_file *s)
  1403. {
  1404. struct platform_device *dsidev;
  1405. int i;
  1406. for (i = 0; i < MAX_NUM_DSI; i++) {
  1407. dsidev = dsi_get_dsidev_from_id(i);
  1408. if (dsidev)
  1409. dsi_dump_dsidev_clocks(dsidev, s);
  1410. }
  1411. }
  1412. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  1413. static void dsi_dump_dsidev_irqs(struct platform_device *dsidev,
  1414. struct seq_file *s)
  1415. {
  1416. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1417. unsigned long flags;
  1418. struct dsi_irq_stats stats;
  1419. int dsi_module = dsi_get_dsidev_id(dsidev);
  1420. spin_lock_irqsave(&dsi->irq_stats_lock, flags);
  1421. stats = dsi->irq_stats;
  1422. memset(&dsi->irq_stats, 0, sizeof(dsi->irq_stats));
  1423. dsi->irq_stats.last_reset = jiffies;
  1424. spin_unlock_irqrestore(&dsi->irq_stats_lock, flags);
  1425. seq_printf(s, "period %u ms\n",
  1426. jiffies_to_msecs(jiffies - stats.last_reset));
  1427. seq_printf(s, "irqs %d\n", stats.irq_count);
  1428. #define PIS(x) \
  1429. seq_printf(s, "%-20s %10d\n", #x, stats.dsi_irqs[ffs(DSI_IRQ_##x)-1]);
  1430. seq_printf(s, "-- DSI%d interrupts --\n", dsi_module + 1);
  1431. PIS(VC0);
  1432. PIS(VC1);
  1433. PIS(VC2);
  1434. PIS(VC3);
  1435. PIS(WAKEUP);
  1436. PIS(RESYNC);
  1437. PIS(PLL_LOCK);
  1438. PIS(PLL_UNLOCK);
  1439. PIS(PLL_RECALL);
  1440. PIS(COMPLEXIO_ERR);
  1441. PIS(HS_TX_TIMEOUT);
  1442. PIS(LP_RX_TIMEOUT);
  1443. PIS(TE_TRIGGER);
  1444. PIS(ACK_TRIGGER);
  1445. PIS(SYNC_LOST);
  1446. PIS(LDO_POWER_GOOD);
  1447. PIS(TA_TIMEOUT);
  1448. #undef PIS
  1449. #define PIS(x) \
  1450. seq_printf(s, "%-20s %10d %10d %10d %10d\n", #x, \
  1451. stats.vc_irqs[0][ffs(DSI_VC_IRQ_##x)-1], \
  1452. stats.vc_irqs[1][ffs(DSI_VC_IRQ_##x)-1], \
  1453. stats.vc_irqs[2][ffs(DSI_VC_IRQ_##x)-1], \
  1454. stats.vc_irqs[3][ffs(DSI_VC_IRQ_##x)-1]);
  1455. seq_printf(s, "-- VC interrupts --\n");
  1456. PIS(CS);
  1457. PIS(ECC_CORR);
  1458. PIS(PACKET_SENT);
  1459. PIS(FIFO_TX_OVF);
  1460. PIS(FIFO_RX_OVF);
  1461. PIS(BTA);
  1462. PIS(ECC_NO_CORR);
  1463. PIS(FIFO_TX_UDF);
  1464. PIS(PP_BUSY_CHANGE);
  1465. #undef PIS
  1466. #define PIS(x) \
  1467. seq_printf(s, "%-20s %10d\n", #x, \
  1468. stats.cio_irqs[ffs(DSI_CIO_IRQ_##x)-1]);
  1469. seq_printf(s, "-- CIO interrupts --\n");
  1470. PIS(ERRSYNCESC1);
  1471. PIS(ERRSYNCESC2);
  1472. PIS(ERRSYNCESC3);
  1473. PIS(ERRESC1);
  1474. PIS(ERRESC2);
  1475. PIS(ERRESC3);
  1476. PIS(ERRCONTROL1);
  1477. PIS(ERRCONTROL2);
  1478. PIS(ERRCONTROL3);
  1479. PIS(STATEULPS1);
  1480. PIS(STATEULPS2);
  1481. PIS(STATEULPS3);
  1482. PIS(ERRCONTENTIONLP0_1);
  1483. PIS(ERRCONTENTIONLP1_1);
  1484. PIS(ERRCONTENTIONLP0_2);
  1485. PIS(ERRCONTENTIONLP1_2);
  1486. PIS(ERRCONTENTIONLP0_3);
  1487. PIS(ERRCONTENTIONLP1_3);
  1488. PIS(ULPSACTIVENOT_ALL0);
  1489. PIS(ULPSACTIVENOT_ALL1);
  1490. #undef PIS
  1491. }
  1492. static void dsi1_dump_irqs(struct seq_file *s)
  1493. {
  1494. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1495. dsi_dump_dsidev_irqs(dsidev, s);
  1496. }
  1497. static void dsi2_dump_irqs(struct seq_file *s)
  1498. {
  1499. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1500. dsi_dump_dsidev_irqs(dsidev, s);
  1501. }
  1502. void dsi_create_debugfs_files_irq(struct dentry *debugfs_dir,
  1503. const struct file_operations *debug_fops)
  1504. {
  1505. struct platform_device *dsidev;
  1506. dsidev = dsi_get_dsidev_from_id(0);
  1507. if (dsidev)
  1508. debugfs_create_file("dsi1_irqs", S_IRUGO, debugfs_dir,
  1509. &dsi1_dump_irqs, debug_fops);
  1510. dsidev = dsi_get_dsidev_from_id(1);
  1511. if (dsidev)
  1512. debugfs_create_file("dsi2_irqs", S_IRUGO, debugfs_dir,
  1513. &dsi2_dump_irqs, debug_fops);
  1514. }
  1515. #endif
  1516. static void dsi_dump_dsidev_regs(struct platform_device *dsidev,
  1517. struct seq_file *s)
  1518. {
  1519. #define DUMPREG(r) seq_printf(s, "%-35s %08x\n", #r, dsi_read_reg(dsidev, r))
  1520. dss_clk_enable(DSS_CLK_ICK | DSS_CLK_FCK);
  1521. dsi_enable_scp_clk(dsidev);
  1522. DUMPREG(DSI_REVISION);
  1523. DUMPREG(DSI_SYSCONFIG);
  1524. DUMPREG(DSI_SYSSTATUS);
  1525. DUMPREG(DSI_IRQSTATUS);
  1526. DUMPREG(DSI_IRQENABLE);
  1527. DUMPREG(DSI_CTRL);
  1528. DUMPREG(DSI_COMPLEXIO_CFG1);
  1529. DUMPREG(DSI_COMPLEXIO_IRQ_STATUS);
  1530. DUMPREG(DSI_COMPLEXIO_IRQ_ENABLE);
  1531. DUMPREG(DSI_CLK_CTRL);
  1532. DUMPREG(DSI_TIMING1);
  1533. DUMPREG(DSI_TIMING2);
  1534. DUMPREG(DSI_VM_TIMING1);
  1535. DUMPREG(DSI_VM_TIMING2);
  1536. DUMPREG(DSI_VM_TIMING3);
  1537. DUMPREG(DSI_CLK_TIMING);
  1538. DUMPREG(DSI_TX_FIFO_VC_SIZE);
  1539. DUMPREG(DSI_RX_FIFO_VC_SIZE);
  1540. DUMPREG(DSI_COMPLEXIO_CFG2);
  1541. DUMPREG(DSI_RX_FIFO_VC_FULLNESS);
  1542. DUMPREG(DSI_VM_TIMING4);
  1543. DUMPREG(DSI_TX_FIFO_VC_EMPTINESS);
  1544. DUMPREG(DSI_VM_TIMING5);
  1545. DUMPREG(DSI_VM_TIMING6);
  1546. DUMPREG(DSI_VM_TIMING7);
  1547. DUMPREG(DSI_STOPCLK_TIMING);
  1548. DUMPREG(DSI_VC_CTRL(0));
  1549. DUMPREG(DSI_VC_TE(0));
  1550. DUMPREG(DSI_VC_LONG_PACKET_HEADER(0));
  1551. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(0));
  1552. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(0));
  1553. DUMPREG(DSI_VC_IRQSTATUS(0));
  1554. DUMPREG(DSI_VC_IRQENABLE(0));
  1555. DUMPREG(DSI_VC_CTRL(1));
  1556. DUMPREG(DSI_VC_TE(1));
  1557. DUMPREG(DSI_VC_LONG_PACKET_HEADER(1));
  1558. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(1));
  1559. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(1));
  1560. DUMPREG(DSI_VC_IRQSTATUS(1));
  1561. DUMPREG(DSI_VC_IRQENABLE(1));
  1562. DUMPREG(DSI_VC_CTRL(2));
  1563. DUMPREG(DSI_VC_TE(2));
  1564. DUMPREG(DSI_VC_LONG_PACKET_HEADER(2));
  1565. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(2));
  1566. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(2));
  1567. DUMPREG(DSI_VC_IRQSTATUS(2));
  1568. DUMPREG(DSI_VC_IRQENABLE(2));
  1569. DUMPREG(DSI_VC_CTRL(3));
  1570. DUMPREG(DSI_VC_TE(3));
  1571. DUMPREG(DSI_VC_LONG_PACKET_HEADER(3));
  1572. DUMPREG(DSI_VC_LONG_PACKET_PAYLOAD(3));
  1573. DUMPREG(DSI_VC_SHORT_PACKET_HEADER(3));
  1574. DUMPREG(DSI_VC_IRQSTATUS(3));
  1575. DUMPREG(DSI_VC_IRQENABLE(3));
  1576. DUMPREG(DSI_DSIPHY_CFG0);
  1577. DUMPREG(DSI_DSIPHY_CFG1);
  1578. DUMPREG(DSI_DSIPHY_CFG2);
  1579. DUMPREG(DSI_DSIPHY_CFG5);
  1580. DUMPREG(DSI_PLL_CONTROL);
  1581. DUMPREG(DSI_PLL_STATUS);
  1582. DUMPREG(DSI_PLL_GO);
  1583. DUMPREG(DSI_PLL_CONFIGURATION1);
  1584. DUMPREG(DSI_PLL_CONFIGURATION2);
  1585. dsi_disable_scp_clk(dsidev);
  1586. dss_clk_disable(DSS_CLK_ICK | DSS_CLK_FCK);
  1587. #undef DUMPREG
  1588. }
  1589. static void dsi1_dump_regs(struct seq_file *s)
  1590. {
  1591. struct platform_device *dsidev = dsi_get_dsidev_from_id(0);
  1592. dsi_dump_dsidev_regs(dsidev, s);
  1593. }
  1594. static void dsi2_dump_regs(struct seq_file *s)
  1595. {
  1596. struct platform_device *dsidev = dsi_get_dsidev_from_id(1);
  1597. dsi_dump_dsidev_regs(dsidev, s);
  1598. }
  1599. void dsi_create_debugfs_files_reg(struct dentry *debugfs_dir,
  1600. const struct file_operations *debug_fops)
  1601. {
  1602. struct platform_device *dsidev;
  1603. dsidev = dsi_get_dsidev_from_id(0);
  1604. if (dsidev)
  1605. debugfs_create_file("dsi1_regs", S_IRUGO, debugfs_dir,
  1606. &dsi1_dump_regs, debug_fops);
  1607. dsidev = dsi_get_dsidev_from_id(1);
  1608. if (dsidev)
  1609. debugfs_create_file("dsi2_regs", S_IRUGO, debugfs_dir,
  1610. &dsi2_dump_regs, debug_fops);
  1611. }
  1612. enum dsi_cio_power_state {
  1613. DSI_COMPLEXIO_POWER_OFF = 0x0,
  1614. DSI_COMPLEXIO_POWER_ON = 0x1,
  1615. DSI_COMPLEXIO_POWER_ULPS = 0x2,
  1616. };
  1617. static int dsi_cio_power(struct platform_device *dsidev,
  1618. enum dsi_cio_power_state state)
  1619. {
  1620. int t = 0;
  1621. /* PWR_CMD */
  1622. REG_FLD_MOD(dsidev, DSI_COMPLEXIO_CFG1, state, 28, 27);
  1623. /* PWR_STATUS */
  1624. while (FLD_GET(dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1),
  1625. 26, 25) != state) {
  1626. if (++t > 1000) {
  1627. DSSERR("failed to set complexio power state to "
  1628. "%d\n", state);
  1629. return -ENODEV;
  1630. }
  1631. udelay(1);
  1632. }
  1633. return 0;
  1634. }
  1635. /* Number of data lanes present on DSI interface */
  1636. static inline int dsi_get_num_data_lanes(struct platform_device *dsidev)
  1637. {
  1638. /* DSI on OMAP3 doesn't have register DSI_GNQ, set number
  1639. * of data lanes as 2 by default */
  1640. if (dss_has_feature(FEAT_DSI_GNQ))
  1641. return REG_GET(dsidev, DSI_GNQ, 11, 9); /* NB_DATA_LANES */
  1642. else
  1643. return 2;
  1644. }
  1645. /* Number of data lanes used by the dss device */
  1646. static inline int dsi_get_num_data_lanes_dssdev(struct omap_dss_device *dssdev)
  1647. {
  1648. int num_data_lanes = 0;
  1649. if (dssdev->phy.dsi.data1_lane != 0)
  1650. num_data_lanes++;
  1651. if (dssdev->phy.dsi.data2_lane != 0)
  1652. num_data_lanes++;
  1653. if (dssdev->phy.dsi.data3_lane != 0)
  1654. num_data_lanes++;
  1655. if (dssdev->phy.dsi.data4_lane != 0)
  1656. num_data_lanes++;
  1657. return num_data_lanes;
  1658. }
  1659. static unsigned dsi_get_line_buf_size(struct platform_device *dsidev)
  1660. {
  1661. int val;
  1662. /* line buffer on OMAP3 is 1024 x 24bits */
  1663. /* XXX: for some reason using full buffer size causes
  1664. * considerable TX slowdown with update sizes that fill the
  1665. * whole buffer */
  1666. if (!dss_has_feature(FEAT_DSI_GNQ))
  1667. return 1023 * 3;
  1668. val = REG_GET(dsidev, DSI_GNQ, 14, 12); /* VP1_LINE_BUFFER_SIZE */
  1669. switch (val) {
  1670. case 1:
  1671. return 512 * 3; /* 512x24 bits */
  1672. case 2:
  1673. return 682 * 3; /* 682x24 bits */
  1674. case 3:
  1675. return 853 * 3; /* 853x24 bits */
  1676. case 4:
  1677. return 1024 * 3; /* 1024x24 bits */
  1678. case 5:
  1679. return 1194 * 3; /* 1194x24 bits */
  1680. case 6:
  1681. return 1365 * 3; /* 1365x24 bits */
  1682. default:
  1683. BUG();
  1684. }
  1685. }
  1686. static void dsi_set_lane_config(struct omap_dss_device *dssdev)
  1687. {
  1688. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1689. u32 r;
  1690. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1691. int clk_lane = dssdev->phy.dsi.clk_lane;
  1692. int data1_lane = dssdev->phy.dsi.data1_lane;
  1693. int data2_lane = dssdev->phy.dsi.data2_lane;
  1694. int clk_pol = dssdev->phy.dsi.clk_pol;
  1695. int data1_pol = dssdev->phy.dsi.data1_pol;
  1696. int data2_pol = dssdev->phy.dsi.data2_pol;
  1697. r = dsi_read_reg(dsidev, DSI_COMPLEXIO_CFG1);
  1698. r = FLD_MOD(r, clk_lane, 2, 0);
  1699. r = FLD_MOD(r, clk_pol, 3, 3);
  1700. r = FLD_MOD(r, data1_lane, 6, 4);
  1701. r = FLD_MOD(r, data1_pol, 7, 7);
  1702. r = FLD_MOD(r, data2_lane, 10, 8);
  1703. r = FLD_MOD(r, data2_pol, 11, 11);
  1704. if (num_data_lanes_dssdev > 2) {
  1705. int data3_lane = dssdev->phy.dsi.data3_lane;
  1706. int data3_pol = dssdev->phy.dsi.data3_pol;
  1707. r = FLD_MOD(r, data3_lane, 14, 12);
  1708. r = FLD_MOD(r, data3_pol, 15, 15);
  1709. }
  1710. if (num_data_lanes_dssdev > 3) {
  1711. int data4_lane = dssdev->phy.dsi.data4_lane;
  1712. int data4_pol = dssdev->phy.dsi.data4_pol;
  1713. r = FLD_MOD(r, data4_lane, 18, 16);
  1714. r = FLD_MOD(r, data4_pol, 19, 19);
  1715. }
  1716. dsi_write_reg(dsidev, DSI_COMPLEXIO_CFG1, r);
  1717. /* The configuration of the DSI complex I/O (number of data lanes,
  1718. position, differential order) should not be changed while
  1719. DSS.DSI_CLK_CRTRL[20] LP_CLK_ENABLE bit is set to 1. In order for
  1720. the hardware to take into account a new configuration of the complex
  1721. I/O (done in DSS.DSI_COMPLEXIO_CFG1 register), it is recommended to
  1722. follow this sequence: First set the DSS.DSI_CTRL[0] IF_EN bit to 1,
  1723. then reset the DSS.DSI_CTRL[0] IF_EN to 0, then set
  1724. DSS.DSI_CLK_CTRL[20] LP_CLK_ENABLE to 1 and finally set again the
  1725. DSS.DSI_CTRL[0] IF_EN bit to 1. If the sequence is not followed, the
  1726. DSI complex I/O configuration is unknown. */
  1727. /*
  1728. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1729. REG_FLD_MOD(dsidev, DSI_CTRL, 0, 0, 0);
  1730. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20);
  1731. REG_FLD_MOD(dsidev, DSI_CTRL, 1, 0, 0);
  1732. */
  1733. }
  1734. static inline unsigned ns2ddr(struct platform_device *dsidev, unsigned ns)
  1735. {
  1736. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1737. /* convert time in ns to ddr ticks, rounding up */
  1738. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1739. return (ns * (ddr_clk / 1000 / 1000) + 999) / 1000;
  1740. }
  1741. static inline unsigned ddr2ns(struct platform_device *dsidev, unsigned ddr)
  1742. {
  1743. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1744. unsigned long ddr_clk = dsi->current_cinfo.clkin4ddr / 4;
  1745. return ddr * 1000 * 1000 / (ddr_clk / 1000);
  1746. }
  1747. static void dsi_cio_timings(struct platform_device *dsidev)
  1748. {
  1749. u32 r;
  1750. u32 ths_prepare, ths_prepare_ths_zero, ths_trail, ths_exit;
  1751. u32 tlpx_half, tclk_trail, tclk_zero;
  1752. u32 tclk_prepare;
  1753. /* calculate timings */
  1754. /* 1 * DDR_CLK = 2 * UI */
  1755. /* min 40ns + 4*UI max 85ns + 6*UI */
  1756. ths_prepare = ns2ddr(dsidev, 70) + 2;
  1757. /* min 145ns + 10*UI */
  1758. ths_prepare_ths_zero = ns2ddr(dsidev, 175) + 2;
  1759. /* min max(8*UI, 60ns+4*UI) */
  1760. ths_trail = ns2ddr(dsidev, 60) + 5;
  1761. /* min 100ns */
  1762. ths_exit = ns2ddr(dsidev, 145);
  1763. /* tlpx min 50n */
  1764. tlpx_half = ns2ddr(dsidev, 25);
  1765. /* min 60ns */
  1766. tclk_trail = ns2ddr(dsidev, 60) + 2;
  1767. /* min 38ns, max 95ns */
  1768. tclk_prepare = ns2ddr(dsidev, 65);
  1769. /* min tclk-prepare + tclk-zero = 300ns */
  1770. tclk_zero = ns2ddr(dsidev, 260);
  1771. DSSDBG("ths_prepare %u (%uns), ths_prepare_ths_zero %u (%uns)\n",
  1772. ths_prepare, ddr2ns(dsidev, ths_prepare),
  1773. ths_prepare_ths_zero, ddr2ns(dsidev, ths_prepare_ths_zero));
  1774. DSSDBG("ths_trail %u (%uns), ths_exit %u (%uns)\n",
  1775. ths_trail, ddr2ns(dsidev, ths_trail),
  1776. ths_exit, ddr2ns(dsidev, ths_exit));
  1777. DSSDBG("tlpx_half %u (%uns), tclk_trail %u (%uns), "
  1778. "tclk_zero %u (%uns)\n",
  1779. tlpx_half, ddr2ns(dsidev, tlpx_half),
  1780. tclk_trail, ddr2ns(dsidev, tclk_trail),
  1781. tclk_zero, ddr2ns(dsidev, tclk_zero));
  1782. DSSDBG("tclk_prepare %u (%uns)\n",
  1783. tclk_prepare, ddr2ns(dsidev, tclk_prepare));
  1784. /* program timings */
  1785. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG0);
  1786. r = FLD_MOD(r, ths_prepare, 31, 24);
  1787. r = FLD_MOD(r, ths_prepare_ths_zero, 23, 16);
  1788. r = FLD_MOD(r, ths_trail, 15, 8);
  1789. r = FLD_MOD(r, ths_exit, 7, 0);
  1790. dsi_write_reg(dsidev, DSI_DSIPHY_CFG0, r);
  1791. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG1);
  1792. r = FLD_MOD(r, tlpx_half, 22, 16);
  1793. r = FLD_MOD(r, tclk_trail, 15, 8);
  1794. r = FLD_MOD(r, tclk_zero, 7, 0);
  1795. dsi_write_reg(dsidev, DSI_DSIPHY_CFG1, r);
  1796. r = dsi_read_reg(dsidev, DSI_DSIPHY_CFG2);
  1797. r = FLD_MOD(r, tclk_prepare, 7, 0);
  1798. dsi_write_reg(dsidev, DSI_DSIPHY_CFG2, r);
  1799. }
  1800. static void dsi_cio_enable_lane_override(struct omap_dss_device *dssdev,
  1801. enum dsi_lane lanes)
  1802. {
  1803. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1804. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1805. int clk_lane = dssdev->phy.dsi.clk_lane;
  1806. int data1_lane = dssdev->phy.dsi.data1_lane;
  1807. int data2_lane = dssdev->phy.dsi.data2_lane;
  1808. int data3_lane = dssdev->phy.dsi.data3_lane;
  1809. int data4_lane = dssdev->phy.dsi.data4_lane;
  1810. int clk_pol = dssdev->phy.dsi.clk_pol;
  1811. int data1_pol = dssdev->phy.dsi.data1_pol;
  1812. int data2_pol = dssdev->phy.dsi.data2_pol;
  1813. int data3_pol = dssdev->phy.dsi.data3_pol;
  1814. int data4_pol = dssdev->phy.dsi.data4_pol;
  1815. u32 l = 0;
  1816. u8 lptxscp_start = dsi->num_data_lanes == 2 ? 22 : 26;
  1817. if (lanes & DSI_CLK_P)
  1818. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 0 : 1));
  1819. if (lanes & DSI_CLK_N)
  1820. l |= 1 << ((clk_lane - 1) * 2 + (clk_pol ? 1 : 0));
  1821. if (lanes & DSI_DATA1_P)
  1822. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 0 : 1));
  1823. if (lanes & DSI_DATA1_N)
  1824. l |= 1 << ((data1_lane - 1) * 2 + (data1_pol ? 1 : 0));
  1825. if (lanes & DSI_DATA2_P)
  1826. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 0 : 1));
  1827. if (lanes & DSI_DATA2_N)
  1828. l |= 1 << ((data2_lane - 1) * 2 + (data2_pol ? 1 : 0));
  1829. if (lanes & DSI_DATA3_P)
  1830. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 0 : 1));
  1831. if (lanes & DSI_DATA3_N)
  1832. l |= 1 << ((data3_lane - 1) * 2 + (data3_pol ? 1 : 0));
  1833. if (lanes & DSI_DATA4_P)
  1834. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 0 : 1));
  1835. if (lanes & DSI_DATA4_N)
  1836. l |= 1 << ((data4_lane - 1) * 2 + (data4_pol ? 1 : 0));
  1837. /*
  1838. * Bits in REGLPTXSCPDAT4TO0DXDY:
  1839. * 17: DY0 18: DX0
  1840. * 19: DY1 20: DX1
  1841. * 21: DY2 22: DX2
  1842. * 23: DY3 24: DX3
  1843. * 25: DY4 26: DX4
  1844. */
  1845. /* Set the lane override configuration */
  1846. /* REGLPTXSCPDAT4TO0DXDY */
  1847. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, l, lptxscp_start, 17);
  1848. /* Enable lane override */
  1849. /* ENLPTXSCPDAT */
  1850. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 1, 27, 27);
  1851. }
  1852. static void dsi_cio_disable_lane_override(struct platform_device *dsidev)
  1853. {
  1854. /* Disable lane override */
  1855. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 27, 27); /* ENLPTXSCPDAT */
  1856. /* Reset the lane override configuration */
  1857. /* REGLPTXSCPDAT4TO0DXDY */
  1858. REG_FLD_MOD(dsidev, DSI_DSIPHY_CFG10, 0, 22, 17);
  1859. }
  1860. static int dsi_cio_wait_tx_clk_esc_reset(struct omap_dss_device *dssdev)
  1861. {
  1862. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1863. int t;
  1864. int bits[3];
  1865. bool in_use[3];
  1866. if (dss_has_feature(FEAT_DSI_REVERSE_TXCLKESC)) {
  1867. bits[0] = 28;
  1868. bits[1] = 27;
  1869. bits[2] = 26;
  1870. } else {
  1871. bits[0] = 24;
  1872. bits[1] = 25;
  1873. bits[2] = 26;
  1874. }
  1875. in_use[0] = false;
  1876. in_use[1] = false;
  1877. in_use[2] = false;
  1878. if (dssdev->phy.dsi.clk_lane != 0)
  1879. in_use[dssdev->phy.dsi.clk_lane - 1] = true;
  1880. if (dssdev->phy.dsi.data1_lane != 0)
  1881. in_use[dssdev->phy.dsi.data1_lane - 1] = true;
  1882. if (dssdev->phy.dsi.data2_lane != 0)
  1883. in_use[dssdev->phy.dsi.data2_lane - 1] = true;
  1884. t = 100000;
  1885. while (true) {
  1886. u32 l;
  1887. int i;
  1888. int ok;
  1889. l = dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1890. ok = 0;
  1891. for (i = 0; i < 3; ++i) {
  1892. if (!in_use[i] || (l & (1 << bits[i])))
  1893. ok++;
  1894. }
  1895. if (ok == 3)
  1896. break;
  1897. if (--t == 0) {
  1898. for (i = 0; i < 3; ++i) {
  1899. if (!in_use[i] || (l & (1 << bits[i])))
  1900. continue;
  1901. DSSERR("CIO TXCLKESC%d domain not coming " \
  1902. "out of reset\n", i);
  1903. }
  1904. return -EIO;
  1905. }
  1906. }
  1907. return 0;
  1908. }
  1909. static int dsi_cio_init(struct omap_dss_device *dssdev)
  1910. {
  1911. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  1912. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1913. int r;
  1914. int num_data_lanes_dssdev = dsi_get_num_data_lanes_dssdev(dssdev);
  1915. u32 l;
  1916. DSSDBGF();
  1917. if (dsi->dsi_mux_pads)
  1918. dsi->dsi_mux_pads(true);
  1919. dsi_enable_scp_clk(dsidev);
  1920. /* A dummy read using the SCP interface to any DSIPHY register is
  1921. * required after DSIPHY reset to complete the reset of the DSI complex
  1922. * I/O. */
  1923. dsi_read_reg(dsidev, DSI_DSIPHY_CFG5);
  1924. if (wait_for_bit_change(dsidev, DSI_DSIPHY_CFG5, 30, 1) != 1) {
  1925. DSSERR("CIO SCP Clock domain not coming out of reset.\n");
  1926. r = -EIO;
  1927. goto err_scp_clk_dom;
  1928. }
  1929. dsi_set_lane_config(dssdev);
  1930. /* set TX STOP MODE timer to maximum for this operation */
  1931. l = dsi_read_reg(dsidev, DSI_TIMING1);
  1932. l = FLD_MOD(l, 1, 15, 15); /* FORCE_TX_STOP_MODE_IO */
  1933. l = FLD_MOD(l, 1, 14, 14); /* STOP_STATE_X16_IO */
  1934. l = FLD_MOD(l, 1, 13, 13); /* STOP_STATE_X4_IO */
  1935. l = FLD_MOD(l, 0x1fff, 12, 0); /* STOP_STATE_COUNTER_IO */
  1936. dsi_write_reg(dsidev, DSI_TIMING1, l);
  1937. if (dsi->ulps_enabled) {
  1938. u32 lane_mask = DSI_CLK_P | DSI_DATA1_P | DSI_DATA2_P;
  1939. DSSDBG("manual ulps exit\n");
  1940. /* ULPS is exited by Mark-1 state for 1ms, followed by
  1941. * stop state. DSS HW cannot do this via the normal
  1942. * ULPS exit sequence, as after reset the DSS HW thinks
  1943. * that we are not in ULPS mode, and refuses to send the
  1944. * sequence. So we need to send the ULPS exit sequence
  1945. * manually.
  1946. */
  1947. if (num_data_lanes_dssdev > 2)
  1948. lane_mask |= DSI_DATA3_P;
  1949. if (num_data_lanes_dssdev > 3)
  1950. lane_mask |= DSI_DATA4_P;
  1951. dsi_cio_enable_lane_override(dssdev, lane_mask);
  1952. }
  1953. r = dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_ON);
  1954. if (r)
  1955. goto err_cio_pwr;
  1956. if (wait_for_bit_change(dsidev, DSI_COMPLEXIO_CFG1, 29, 1) != 1) {
  1957. DSSERR("CIO PWR clock domain not coming out of reset.\n");
  1958. r = -ENODEV;
  1959. goto err_cio_pwr_dom;
  1960. }
  1961. dsi_if_enable(dsidev, true);
  1962. dsi_if_enable(dsidev, false);
  1963. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 1, 20, 20); /* LP_CLK_ENABLE */
  1964. r = dsi_cio_wait_tx_clk_esc_reset(dssdev);
  1965. if (r)
  1966. goto err_tx_clk_esc_rst;
  1967. if (dsi->ulps_enabled) {
  1968. /* Keep Mark-1 state for 1ms (as per DSI spec) */
  1969. ktime_t wait = ns_to_ktime(1000 * 1000);
  1970. set_current_state(TASK_UNINTERRUPTIBLE);
  1971. schedule_hrtimeout(&wait, HRTIMER_MODE_REL);
  1972. /* Disable the override. The lanes should be set to Mark-11
  1973. * state by the HW */
  1974. dsi_cio_disable_lane_override(dsidev);
  1975. }
  1976. /* FORCE_TX_STOP_MODE_IO */
  1977. REG_FLD_MOD(dsidev, DSI_TIMING1, 0, 15, 15);
  1978. dsi_cio_timings(dsidev);
  1979. dsi->ulps_enabled = false;
  1980. DSSDBG("CIO init done\n");
  1981. return 0;
  1982. err_tx_clk_esc_rst:
  1983. REG_FLD_MOD(dsidev, DSI_CLK_CTRL, 0, 20, 20); /* LP_CLK_ENABLE */
  1984. err_cio_pwr_dom:
  1985. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  1986. err_cio_pwr:
  1987. if (dsi->ulps_enabled)
  1988. dsi_cio_disable_lane_override(dsidev);
  1989. err_scp_clk_dom:
  1990. dsi_disable_scp_clk(dsidev);
  1991. if (dsi->dsi_mux_pads)
  1992. dsi->dsi_mux_pads(false);
  1993. return r;
  1994. }
  1995. static void dsi_cio_uninit(struct platform_device *dsidev)
  1996. {
  1997. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  1998. dsi_cio_power(dsidev, DSI_COMPLEXIO_POWER_OFF);
  1999. dsi_disable_scp_clk(dsidev);
  2000. if (dsi->dsi_mux_pads)
  2001. dsi->dsi_mux_pads(false);
  2002. }
  2003. static int _dsi_wait_reset(struct platform_device *dsidev)
  2004. {
  2005. int t = 0;
  2006. while (REG_GET(dsidev, DSI_SYSSTATUS, 0, 0) == 0) {
  2007. if (++t > 5) {
  2008. DSSERR("soft reset failed\n");
  2009. return -ENODEV;
  2010. }
  2011. udelay(1);
  2012. }
  2013. return 0;
  2014. }
  2015. static int _dsi_reset(struct platform_device *dsidev)
  2016. {
  2017. /* Soft reset */
  2018. REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 1, 1, 1);
  2019. return _dsi_wait_reset(dsidev);
  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. #define DSI_DECL_VARS \
  2937. int __dsi_cb = 0; u32 __dsi_cv = 0;
  2938. #define DSI_FLUSH(dsidev, ch) \
  2939. if (__dsi_cb > 0) { \
  2940. /*DSSDBG("sending long packet %#010x\n", __dsi_cv);*/ \
  2941. dsi_write_reg(dsidev, DSI_VC_LONG_PACKET_PAYLOAD(ch), __dsi_cv); \
  2942. __dsi_cb = __dsi_cv = 0; \
  2943. }
  2944. #define DSI_PUSH(dsidev, ch, data) \
  2945. do { \
  2946. __dsi_cv |= (data) << (__dsi_cb * 8); \
  2947. /*DSSDBG("cv = %#010x, cb = %d\n", __dsi_cv, __dsi_cb);*/ \
  2948. if (++__dsi_cb > 3) \
  2949. DSI_FLUSH(dsidev, ch); \
  2950. } while (0)
  2951. static int dsi_update_screen_l4(struct omap_dss_device *dssdev,
  2952. int x, int y, int w, int h)
  2953. {
  2954. /* Note: supports only 24bit colors in 32bit container */
  2955. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  2956. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  2957. int first = 1;
  2958. int fifo_stalls = 0;
  2959. int max_dsi_packet_size;
  2960. int max_data_per_packet;
  2961. int max_pixels_per_packet;
  2962. int pixels_left;
  2963. int bytespp = dssdev->ctrl.pixel_size / 8;
  2964. int scr_width;
  2965. u32 __iomem *data;
  2966. int start_offset;
  2967. int horiz_inc;
  2968. int current_x;
  2969. struct omap_overlay *ovl;
  2970. debug_irq = 0;
  2971. DSSDBG("dsi_update_screen_l4 (%d,%d %dx%d)\n",
  2972. x, y, w, h);
  2973. ovl = dssdev->manager->overlays[0];
  2974. if (ovl->info.color_mode != OMAP_DSS_COLOR_RGB24U)
  2975. return -EINVAL;
  2976. if (dssdev->ctrl.pixel_size != 24)
  2977. return -EINVAL;
  2978. scr_width = ovl->info.screen_width;
  2979. data = ovl->info.vaddr;
  2980. start_offset = scr_width * y + x;
  2981. horiz_inc = scr_width - w;
  2982. current_x = x;
  2983. /* We need header(4) + DCSCMD(1) + pixels(numpix*bytespp) bytes
  2984. * in fifo */
  2985. /* When using CPU, max long packet size is TX buffer size */
  2986. max_dsi_packet_size = dsi->vc[0].fifo_size * 32 * 4;
  2987. /* we seem to get better perf if we divide the tx fifo to half,
  2988. and while the other half is being sent, we fill the other half
  2989. max_dsi_packet_size /= 2; */
  2990. max_data_per_packet = max_dsi_packet_size - 4 - 1;
  2991. max_pixels_per_packet = max_data_per_packet / bytespp;
  2992. DSSDBG("max_pixels_per_packet %d\n", max_pixels_per_packet);
  2993. pixels_left = w * h;
  2994. DSSDBG("total pixels %d\n", pixels_left);
  2995. data += start_offset;
  2996. while (pixels_left > 0) {
  2997. /* 0x2c = write_memory_start */
  2998. /* 0x3c = write_memory_continue */
  2999. u8 dcs_cmd = first ? 0x2c : 0x3c;
  3000. int pixels;
  3001. DSI_DECL_VARS;
  3002. first = 0;
  3003. #if 1
  3004. /* using fifo not empty */
  3005. /* TX_FIFO_NOT_EMPTY */
  3006. while (FLD_GET(dsi_read_reg(dsidev, DSI_VC_CTRL(0)), 5, 5)) {
  3007. fifo_stalls++;
  3008. if (fifo_stalls > 0xfffff) {
  3009. DSSERR("fifo stalls overflow, pixels left %d\n",
  3010. pixels_left);
  3011. dsi_if_enable(dsidev, 0);
  3012. return -EIO;
  3013. }
  3014. udelay(1);
  3015. }
  3016. #elif 1
  3017. /* using fifo emptiness */
  3018. while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS, 7, 0)+1)*4 <
  3019. max_dsi_packet_size) {
  3020. fifo_stalls++;
  3021. if (fifo_stalls > 0xfffff) {
  3022. DSSERR("fifo stalls overflow, pixels left %d\n",
  3023. pixels_left);
  3024. dsi_if_enable(dsidev, 0);
  3025. return -EIO;
  3026. }
  3027. }
  3028. #else
  3029. while ((REG_GET(dsidev, DSI_TX_FIFO_VC_EMPTINESS,
  3030. 7, 0) + 1) * 4 == 0) {
  3031. fifo_stalls++;
  3032. if (fifo_stalls > 0xfffff) {
  3033. DSSERR("fifo stalls overflow, pixels left %d\n",
  3034. pixels_left);
  3035. dsi_if_enable(dsidev, 0);
  3036. return -EIO;
  3037. }
  3038. }
  3039. #endif
  3040. pixels = min(max_pixels_per_packet, pixels_left);
  3041. pixels_left -= pixels;
  3042. dsi_vc_write_long_header(dsidev, 0, DSI_DT_DCS_LONG_WRITE,
  3043. 1 + pixels * bytespp, 0);
  3044. DSI_PUSH(dsidev, 0, dcs_cmd);
  3045. while (pixels-- > 0) {
  3046. u32 pix = __raw_readl(data++);
  3047. DSI_PUSH(dsidev, 0, (pix >> 16) & 0xff);
  3048. DSI_PUSH(dsidev, 0, (pix >> 8) & 0xff);
  3049. DSI_PUSH(dsidev, 0, (pix >> 0) & 0xff);
  3050. current_x++;
  3051. if (current_x == x+w) {
  3052. current_x = x;
  3053. data += horiz_inc;
  3054. }
  3055. }
  3056. DSI_FLUSH(dsidev, 0);
  3057. }
  3058. return 0;
  3059. }
  3060. static void dsi_update_screen_dispc(struct omap_dss_device *dssdev,
  3061. u16 x, u16 y, u16 w, u16 h)
  3062. {
  3063. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3064. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3065. unsigned bytespp;
  3066. unsigned bytespl;
  3067. unsigned bytespf;
  3068. unsigned total_len;
  3069. unsigned packet_payload;
  3070. unsigned packet_len;
  3071. u32 l;
  3072. int r;
  3073. const unsigned channel = dsi->update_channel;
  3074. const unsigned line_buf_size = dsi_get_line_buf_size(dsidev);
  3075. DSSDBG("dsi_update_screen_dispc(%d,%d %dx%d)\n",
  3076. x, y, w, h);
  3077. dsi_vc_config_vp(dsidev, channel);
  3078. bytespp = dssdev->ctrl.pixel_size / 8;
  3079. bytespl = w * bytespp;
  3080. bytespf = bytespl * h;
  3081. /* NOTE: packet_payload has to be equal to N * bytespl, where N is
  3082. * number of lines in a packet. See errata about VP_CLK_RATIO */
  3083. if (bytespf < line_buf_size)
  3084. packet_payload = bytespf;
  3085. else
  3086. packet_payload = (line_buf_size) / bytespl * bytespl;
  3087. packet_len = packet_payload + 1; /* 1 byte for DCS cmd */
  3088. total_len = (bytespf / packet_payload) * packet_len;
  3089. if (bytespf % packet_payload)
  3090. total_len += (bytespf % packet_payload) + 1;
  3091. l = FLD_VAL(total_len, 23, 0); /* TE_SIZE */
  3092. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  3093. dsi_vc_write_long_header(dsidev, channel, DSI_DT_DCS_LONG_WRITE,
  3094. packet_len, 0);
  3095. if (dsi->te_enabled)
  3096. l = FLD_MOD(l, 1, 30, 30); /* TE_EN */
  3097. else
  3098. l = FLD_MOD(l, 1, 31, 31); /* TE_START */
  3099. dsi_write_reg(dsidev, DSI_VC_TE(channel), l);
  3100. /* We put SIDLEMODE to no-idle for the duration of the transfer,
  3101. * because DSS interrupts are not capable of waking up the CPU and the
  3102. * framedone interrupt could be delayed for quite a long time. I think
  3103. * the same goes for any DSS interrupts, but for some reason I have not
  3104. * seen the problem anywhere else than here.
  3105. */
  3106. dispc_disable_sidle();
  3107. dsi_perf_mark_start(dsidev);
  3108. r = schedule_delayed_work(&dsi->framedone_timeout_work,
  3109. msecs_to_jiffies(250));
  3110. BUG_ON(r == 0);
  3111. dss_start_update(dssdev);
  3112. if (dsi->te_enabled) {
  3113. /* disable LP_RX_TO, so that we can receive TE. Time to wait
  3114. * for TE is longer than the timer allows */
  3115. REG_FLD_MOD(dsidev, DSI_TIMING2, 0, 15, 15); /* LP_RX_TO */
  3116. dsi_vc_send_bta(dsidev, channel);
  3117. #ifdef DSI_CATCH_MISSING_TE
  3118. mod_timer(&dsi->te_timer, jiffies + msecs_to_jiffies(250));
  3119. #endif
  3120. }
  3121. }
  3122. #ifdef DSI_CATCH_MISSING_TE
  3123. static void dsi_te_timeout(unsigned long arg)
  3124. {
  3125. DSSERR("TE not received for 250ms!\n");
  3126. }
  3127. #endif
  3128. static void dsi_handle_framedone(struct platform_device *dsidev, int error)
  3129. {
  3130. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3131. /* SIDLEMODE back to smart-idle */
  3132. dispc_enable_sidle();
  3133. if (dsi->te_enabled) {
  3134. /* enable LP_RX_TO again after the TE */
  3135. REG_FLD_MOD(dsidev, DSI_TIMING2, 1, 15, 15); /* LP_RX_TO */
  3136. }
  3137. dsi->framedone_callback(error, dsi->framedone_data);
  3138. if (!error)
  3139. dsi_perf_show(dsidev, "DISPC");
  3140. }
  3141. static void dsi_framedone_timeout_work_callback(struct work_struct *work)
  3142. {
  3143. struct dsi_data *dsi = container_of(work, struct dsi_data,
  3144. framedone_timeout_work.work);
  3145. /* XXX While extremely unlikely, we could get FRAMEDONE interrupt after
  3146. * 250ms which would conflict with this timeout work. What should be
  3147. * done is first cancel the transfer on the HW, and then cancel the
  3148. * possibly scheduled framedone work. However, cancelling the transfer
  3149. * on the HW is buggy, and would probably require resetting the whole
  3150. * DSI */
  3151. DSSERR("Framedone not received for 250ms!\n");
  3152. dsi_handle_framedone(dsi->pdev, -ETIMEDOUT);
  3153. }
  3154. static void dsi_framedone_irq_callback(void *data, u32 mask)
  3155. {
  3156. struct omap_dss_device *dssdev = (struct omap_dss_device *) data;
  3157. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3158. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3159. /* Note: We get FRAMEDONE when DISPC has finished sending pixels and
  3160. * turns itself off. However, DSI still has the pixels in its buffers,
  3161. * and is sending the data.
  3162. */
  3163. __cancel_delayed_work(&dsi->framedone_timeout_work);
  3164. dsi_handle_framedone(dsidev, 0);
  3165. #ifdef CONFIG_OMAP2_DSS_FAKE_VSYNC
  3166. dispc_fake_vsync_irq();
  3167. #endif
  3168. }
  3169. int omap_dsi_prepare_update(struct omap_dss_device *dssdev,
  3170. u16 *x, u16 *y, u16 *w, u16 *h,
  3171. bool enlarge_update_area)
  3172. {
  3173. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3174. u16 dw, dh;
  3175. dssdev->driver->get_resolution(dssdev, &dw, &dh);
  3176. if (*x > dw || *y > dh)
  3177. return -EINVAL;
  3178. if (*x + *w > dw)
  3179. return -EINVAL;
  3180. if (*y + *h > dh)
  3181. return -EINVAL;
  3182. if (*w == 1)
  3183. return -EINVAL;
  3184. if (*w == 0 || *h == 0)
  3185. return -EINVAL;
  3186. dsi_perf_mark_setup(dsidev);
  3187. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  3188. dss_setup_partial_planes(dssdev, x, y, w, h,
  3189. enlarge_update_area);
  3190. dispc_set_lcd_size(dssdev->manager->id, *w, *h);
  3191. }
  3192. return 0;
  3193. }
  3194. EXPORT_SYMBOL(omap_dsi_prepare_update);
  3195. int omap_dsi_update(struct omap_dss_device *dssdev,
  3196. int channel,
  3197. u16 x, u16 y, u16 w, u16 h,
  3198. void (*callback)(int, void *), void *data)
  3199. {
  3200. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3201. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3202. dsi->update_channel = channel;
  3203. /* OMAP DSS cannot send updates of odd widths.
  3204. * omap_dsi_prepare_update() makes the widths even, but add a BUG_ON
  3205. * here to make sure we catch erroneous updates. Otherwise we'll only
  3206. * see rather obscure HW error happening, as DSS halts. */
  3207. BUG_ON(x % 2 == 1);
  3208. if (dssdev->manager->caps & OMAP_DSS_OVL_MGR_CAP_DISPC) {
  3209. dsi->framedone_callback = callback;
  3210. dsi->framedone_data = data;
  3211. dsi->update_region.x = x;
  3212. dsi->update_region.y = y;
  3213. dsi->update_region.w = w;
  3214. dsi->update_region.h = h;
  3215. dsi->update_region.device = dssdev;
  3216. dsi_update_screen_dispc(dssdev, x, y, w, h);
  3217. } else {
  3218. int r;
  3219. r = dsi_update_screen_l4(dssdev, x, y, w, h);
  3220. if (r)
  3221. return r;
  3222. dsi_perf_show(dsidev, "L4");
  3223. callback(0, data);
  3224. }
  3225. return 0;
  3226. }
  3227. EXPORT_SYMBOL(omap_dsi_update);
  3228. /* Display funcs */
  3229. static int dsi_display_init_dispc(struct omap_dss_device *dssdev)
  3230. {
  3231. int r;
  3232. u32 irq;
  3233. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3234. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3235. r = omap_dispc_register_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3236. irq);
  3237. if (r) {
  3238. DSSERR("can't get FRAMEDONE irq\n");
  3239. return r;
  3240. }
  3241. dispc_set_lcd_display_type(dssdev->manager->id,
  3242. OMAP_DSS_LCD_DISPLAY_TFT);
  3243. dispc_set_parallel_interface_mode(dssdev->manager->id,
  3244. OMAP_DSS_PARALLELMODE_DSI);
  3245. dispc_enable_fifohandcheck(dssdev->manager->id, 1);
  3246. dispc_set_tft_data_lines(dssdev->manager->id, dssdev->ctrl.pixel_size);
  3247. {
  3248. struct omap_video_timings timings = {
  3249. .hsw = 1,
  3250. .hfp = 1,
  3251. .hbp = 1,
  3252. .vsw = 1,
  3253. .vfp = 0,
  3254. .vbp = 0,
  3255. };
  3256. dispc_set_lcd_timings(dssdev->manager->id, &timings);
  3257. }
  3258. return 0;
  3259. }
  3260. static void dsi_display_uninit_dispc(struct omap_dss_device *dssdev)
  3261. {
  3262. u32 irq;
  3263. irq = dssdev->manager->id == OMAP_DSS_CHANNEL_LCD ?
  3264. DISPC_IRQ_FRAMEDONE : DISPC_IRQ_FRAMEDONE2;
  3265. omap_dispc_unregister_isr(dsi_framedone_irq_callback, (void *) dssdev,
  3266. irq);
  3267. }
  3268. static int dsi_configure_dsi_clocks(struct omap_dss_device *dssdev)
  3269. {
  3270. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3271. struct dsi_clock_info cinfo;
  3272. int r;
  3273. /* we always use DSS_CLK_SYSCK as input clock */
  3274. cinfo.use_sys_clk = true;
  3275. cinfo.regn = dssdev->clocks.dsi.regn;
  3276. cinfo.regm = dssdev->clocks.dsi.regm;
  3277. cinfo.regm_dispc = dssdev->clocks.dsi.regm_dispc;
  3278. cinfo.regm_dsi = dssdev->clocks.dsi.regm_dsi;
  3279. r = dsi_calc_clock_rates(dssdev, &cinfo);
  3280. if (r) {
  3281. DSSERR("Failed to calc dsi clocks\n");
  3282. return r;
  3283. }
  3284. r = dsi_pll_set_clock_div(dsidev, &cinfo);
  3285. if (r) {
  3286. DSSERR("Failed to set dsi clocks\n");
  3287. return r;
  3288. }
  3289. return 0;
  3290. }
  3291. static int dsi_configure_dispc_clocks(struct omap_dss_device *dssdev)
  3292. {
  3293. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3294. struct dispc_clock_info dispc_cinfo;
  3295. int r;
  3296. unsigned long long fck;
  3297. fck = dsi_get_pll_hsdiv_dispc_rate(dsidev);
  3298. dispc_cinfo.lck_div = dssdev->clocks.dispc.channel.lck_div;
  3299. dispc_cinfo.pck_div = dssdev->clocks.dispc.channel.pck_div;
  3300. r = dispc_calc_clock_rates(fck, &dispc_cinfo);
  3301. if (r) {
  3302. DSSERR("Failed to calc dispc clocks\n");
  3303. return r;
  3304. }
  3305. r = dispc_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  3306. if (r) {
  3307. DSSERR("Failed to set dispc clocks\n");
  3308. return r;
  3309. }
  3310. return 0;
  3311. }
  3312. static int dsi_display_init_dsi(struct omap_dss_device *dssdev)
  3313. {
  3314. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3315. int dsi_module = dsi_get_dsidev_id(dsidev);
  3316. int r;
  3317. r = dsi_pll_init(dsidev, true, true);
  3318. if (r)
  3319. goto err0;
  3320. r = dsi_configure_dsi_clocks(dssdev);
  3321. if (r)
  3322. goto err1;
  3323. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  3324. dss_select_dsi_clk_source(dsi_module, dssdev->clocks.dsi.dsi_fclk_src);
  3325. dss_select_lcd_clk_source(dssdev->manager->id,
  3326. dssdev->clocks.dispc.channel.lcd_clk_src);
  3327. DSSDBG("PLL OK\n");
  3328. r = dsi_configure_dispc_clocks(dssdev);
  3329. if (r)
  3330. goto err2;
  3331. r = dsi_cio_init(dssdev);
  3332. if (r)
  3333. goto err2;
  3334. _dsi_print_reset_status(dsidev);
  3335. dsi_proto_timings(dssdev);
  3336. dsi_set_lp_clk_divisor(dssdev);
  3337. if (1)
  3338. _dsi_print_reset_status(dsidev);
  3339. r = dsi_proto_config(dssdev);
  3340. if (r)
  3341. goto err3;
  3342. /* enable interface */
  3343. dsi_vc_enable(dsidev, 0, 1);
  3344. dsi_vc_enable(dsidev, 1, 1);
  3345. dsi_vc_enable(dsidev, 2, 1);
  3346. dsi_vc_enable(dsidev, 3, 1);
  3347. dsi_if_enable(dsidev, 1);
  3348. dsi_force_tx_stop_mode_io(dsidev);
  3349. return 0;
  3350. err3:
  3351. dsi_cio_uninit(dsidev);
  3352. err2:
  3353. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3354. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3355. err1:
  3356. dsi_pll_uninit(dsidev, true);
  3357. err0:
  3358. return r;
  3359. }
  3360. static void dsi_display_uninit_dsi(struct omap_dss_device *dssdev,
  3361. bool disconnect_lanes, bool enter_ulps)
  3362. {
  3363. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3364. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3365. int dsi_module = dsi_get_dsidev_id(dsidev);
  3366. if (enter_ulps && !dsi->ulps_enabled)
  3367. dsi_enter_ulps(dsidev);
  3368. /* disable interface */
  3369. dsi_if_enable(dsidev, 0);
  3370. dsi_vc_enable(dsidev, 0, 0);
  3371. dsi_vc_enable(dsidev, 1, 0);
  3372. dsi_vc_enable(dsidev, 2, 0);
  3373. dsi_vc_enable(dsidev, 3, 0);
  3374. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  3375. dss_select_dsi_clk_source(dsi_module, OMAP_DSS_CLK_SRC_FCK);
  3376. dsi_cio_uninit(dsidev);
  3377. dsi_pll_uninit(dsidev, disconnect_lanes);
  3378. }
  3379. static int dsi_core_init(struct platform_device *dsidev)
  3380. {
  3381. /* Autoidle */
  3382. REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 1, 0, 0);
  3383. /* ENWAKEUP */
  3384. REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 1, 2, 2);
  3385. /* SIDLEMODE smart-idle */
  3386. REG_FLD_MOD(dsidev, DSI_SYSCONFIG, 2, 4, 3);
  3387. _dsi_initialize_irq(dsidev);
  3388. return 0;
  3389. }
  3390. int omapdss_dsi_display_enable(struct omap_dss_device *dssdev)
  3391. {
  3392. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3393. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3394. int r = 0;
  3395. DSSDBG("dsi_display_enable\n");
  3396. WARN_ON(!dsi_bus_is_locked(dsidev));
  3397. mutex_lock(&dsi->lock);
  3398. r = omap_dss_start_device(dssdev);
  3399. if (r) {
  3400. DSSERR("failed to start device\n");
  3401. goto err0;
  3402. }
  3403. enable_clocks(1);
  3404. dsi_enable_pll_clock(dsidev, 1);
  3405. r = _dsi_reset(dsidev);
  3406. if (r)
  3407. goto err1;
  3408. dsi_core_init(dsidev);
  3409. r = dsi_display_init_dispc(dssdev);
  3410. if (r)
  3411. goto err1;
  3412. r = dsi_display_init_dsi(dssdev);
  3413. if (r)
  3414. goto err2;
  3415. mutex_unlock(&dsi->lock);
  3416. return 0;
  3417. err2:
  3418. dsi_display_uninit_dispc(dssdev);
  3419. err1:
  3420. enable_clocks(0);
  3421. dsi_enable_pll_clock(dsidev, 0);
  3422. omap_dss_stop_device(dssdev);
  3423. err0:
  3424. mutex_unlock(&dsi->lock);
  3425. DSSDBG("dsi_display_enable FAILED\n");
  3426. return r;
  3427. }
  3428. EXPORT_SYMBOL(omapdss_dsi_display_enable);
  3429. void omapdss_dsi_display_disable(struct omap_dss_device *dssdev,
  3430. bool disconnect_lanes, bool enter_ulps)
  3431. {
  3432. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3433. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3434. DSSDBG("dsi_display_disable\n");
  3435. WARN_ON(!dsi_bus_is_locked(dsidev));
  3436. mutex_lock(&dsi->lock);
  3437. dsi_display_uninit_dispc(dssdev);
  3438. dsi_display_uninit_dsi(dssdev, disconnect_lanes, enter_ulps);
  3439. enable_clocks(0);
  3440. dsi_enable_pll_clock(dsidev, 0);
  3441. omap_dss_stop_device(dssdev);
  3442. mutex_unlock(&dsi->lock);
  3443. }
  3444. EXPORT_SYMBOL(omapdss_dsi_display_disable);
  3445. int omapdss_dsi_enable_te(struct omap_dss_device *dssdev, bool enable)
  3446. {
  3447. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3448. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3449. dsi->te_enabled = enable;
  3450. return 0;
  3451. }
  3452. EXPORT_SYMBOL(omapdss_dsi_enable_te);
  3453. void dsi_get_overlay_fifo_thresholds(enum omap_plane plane,
  3454. u32 fifo_size, enum omap_burst_size *burst_size,
  3455. u32 *fifo_low, u32 *fifo_high)
  3456. {
  3457. unsigned burst_size_bytes;
  3458. *burst_size = OMAP_DSS_BURST_16x32;
  3459. burst_size_bytes = 16 * 32 / 8;
  3460. *fifo_high = fifo_size - burst_size_bytes;
  3461. *fifo_low = fifo_size - burst_size_bytes * 2;
  3462. }
  3463. int dsi_init_display(struct omap_dss_device *dssdev)
  3464. {
  3465. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3466. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3467. int dsi_module = dsi_get_dsidev_id(dsidev);
  3468. DSSDBG("DSI init\n");
  3469. /* XXX these should be figured out dynamically */
  3470. dssdev->caps = OMAP_DSS_DISPLAY_CAP_MANUAL_UPDATE |
  3471. OMAP_DSS_DISPLAY_CAP_TEAR_ELIM;
  3472. if (dsi->vdds_dsi_reg == NULL) {
  3473. struct regulator *vdds_dsi;
  3474. vdds_dsi = regulator_get(&dsi->pdev->dev, "vdds_dsi");
  3475. if (IS_ERR(vdds_dsi)) {
  3476. DSSERR("can't get VDDS_DSI regulator\n");
  3477. return PTR_ERR(vdds_dsi);
  3478. }
  3479. dsi->vdds_dsi_reg = vdds_dsi;
  3480. }
  3481. if (dsi_get_num_data_lanes_dssdev(dssdev) > dsi->num_data_lanes) {
  3482. DSSERR("DSI%d can't support more than %d data lanes\n",
  3483. dsi_module + 1, dsi->num_data_lanes);
  3484. return -EINVAL;
  3485. }
  3486. return 0;
  3487. }
  3488. int omap_dsi_request_vc(struct omap_dss_device *dssdev, int *channel)
  3489. {
  3490. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3491. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3492. int i;
  3493. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3494. if (!dsi->vc[i].dssdev) {
  3495. dsi->vc[i].dssdev = dssdev;
  3496. *channel = i;
  3497. return 0;
  3498. }
  3499. }
  3500. DSSERR("cannot get VC for display %s", dssdev->name);
  3501. return -ENOSPC;
  3502. }
  3503. EXPORT_SYMBOL(omap_dsi_request_vc);
  3504. int omap_dsi_set_vc_id(struct omap_dss_device *dssdev, int channel, int vc_id)
  3505. {
  3506. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3507. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3508. if (vc_id < 0 || vc_id > 3) {
  3509. DSSERR("VC ID out of range\n");
  3510. return -EINVAL;
  3511. }
  3512. if (channel < 0 || channel > 3) {
  3513. DSSERR("Virtual Channel out of range\n");
  3514. return -EINVAL;
  3515. }
  3516. if (dsi->vc[channel].dssdev != dssdev) {
  3517. DSSERR("Virtual Channel not allocated to display %s\n",
  3518. dssdev->name);
  3519. return -EINVAL;
  3520. }
  3521. dsi->vc[channel].vc_id = vc_id;
  3522. return 0;
  3523. }
  3524. EXPORT_SYMBOL(omap_dsi_set_vc_id);
  3525. void omap_dsi_release_vc(struct omap_dss_device *dssdev, int channel)
  3526. {
  3527. struct platform_device *dsidev = dsi_get_dsidev_from_dssdev(dssdev);
  3528. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3529. if ((channel >= 0 && channel <= 3) &&
  3530. dsi->vc[channel].dssdev == dssdev) {
  3531. dsi->vc[channel].dssdev = NULL;
  3532. dsi->vc[channel].vc_id = 0;
  3533. }
  3534. }
  3535. EXPORT_SYMBOL(omap_dsi_release_vc);
  3536. void dsi_wait_pll_hsdiv_dispc_active(struct platform_device *dsidev)
  3537. {
  3538. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 7, 1) != 1)
  3539. DSSERR("%s (%s) not active\n",
  3540. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC),
  3541. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC));
  3542. }
  3543. void dsi_wait_pll_hsdiv_dsi_active(struct platform_device *dsidev)
  3544. {
  3545. if (wait_for_bit_change(dsidev, DSI_PLL_STATUS, 8, 1) != 1)
  3546. DSSERR("%s (%s) not active\n",
  3547. dss_get_generic_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI),
  3548. dss_feat_get_clk_source_name(OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DSI));
  3549. }
  3550. static void dsi_calc_clock_param_ranges(struct platform_device *dsidev)
  3551. {
  3552. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3553. dsi->regn_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGN);
  3554. dsi->regm_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM);
  3555. dsi->regm_dispc_max =
  3556. dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DISPC);
  3557. dsi->regm_dsi_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_REGM_DSI);
  3558. dsi->fint_min = dss_feat_get_param_min(FEAT_PARAM_DSIPLL_FINT);
  3559. dsi->fint_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_FINT);
  3560. dsi->lpdiv_max = dss_feat_get_param_max(FEAT_PARAM_DSIPLL_LPDIV);
  3561. }
  3562. static int dsi_init(struct platform_device *dsidev)
  3563. {
  3564. struct omap_display_platform_data *dss_plat_data;
  3565. struct omap_dss_board_info *board_info;
  3566. u32 rev;
  3567. int r, i, dsi_module = dsi_get_dsidev_id(dsidev);
  3568. struct resource *dsi_mem;
  3569. struct dsi_data *dsi;
  3570. dsi = kzalloc(sizeof(*dsi), GFP_KERNEL);
  3571. if (!dsi) {
  3572. r = -ENOMEM;
  3573. goto err0;
  3574. }
  3575. dsi->pdev = dsidev;
  3576. dsi_pdev_map[dsi_module] = dsidev;
  3577. dev_set_drvdata(&dsidev->dev, dsi);
  3578. dss_plat_data = dsidev->dev.platform_data;
  3579. board_info = dss_plat_data->board_data;
  3580. dsi->dsi_mux_pads = board_info->dsi_mux_pads;
  3581. spin_lock_init(&dsi->irq_lock);
  3582. spin_lock_init(&dsi->errors_lock);
  3583. dsi->errors = 0;
  3584. #ifdef CONFIG_OMAP2_DSS_COLLECT_IRQ_STATS
  3585. spin_lock_init(&dsi->irq_stats_lock);
  3586. dsi->irq_stats.last_reset = jiffies;
  3587. #endif
  3588. mutex_init(&dsi->lock);
  3589. sema_init(&dsi->bus_lock, 1);
  3590. INIT_DELAYED_WORK_DEFERRABLE(&dsi->framedone_timeout_work,
  3591. dsi_framedone_timeout_work_callback);
  3592. #ifdef DSI_CATCH_MISSING_TE
  3593. init_timer(&dsi->te_timer);
  3594. dsi->te_timer.function = dsi_te_timeout;
  3595. dsi->te_timer.data = 0;
  3596. #endif
  3597. dsi_mem = platform_get_resource(dsi->pdev, IORESOURCE_MEM, 0);
  3598. if (!dsi_mem) {
  3599. DSSERR("can't get IORESOURCE_MEM DSI\n");
  3600. r = -EINVAL;
  3601. goto err1;
  3602. }
  3603. dsi->base = ioremap(dsi_mem->start, resource_size(dsi_mem));
  3604. if (!dsi->base) {
  3605. DSSERR("can't ioremap DSI\n");
  3606. r = -ENOMEM;
  3607. goto err1;
  3608. }
  3609. dsi->irq = platform_get_irq(dsi->pdev, 0);
  3610. if (dsi->irq < 0) {
  3611. DSSERR("platform_get_irq failed\n");
  3612. r = -ENODEV;
  3613. goto err2;
  3614. }
  3615. r = request_irq(dsi->irq, omap_dsi_irq_handler, IRQF_SHARED,
  3616. dev_name(&dsidev->dev), dsi->pdev);
  3617. if (r < 0) {
  3618. DSSERR("request_irq failed\n");
  3619. goto err2;
  3620. }
  3621. /* DSI VCs initialization */
  3622. for (i = 0; i < ARRAY_SIZE(dsi->vc); i++) {
  3623. dsi->vc[i].mode = DSI_VC_MODE_L4;
  3624. dsi->vc[i].dssdev = NULL;
  3625. dsi->vc[i].vc_id = 0;
  3626. }
  3627. dsi_calc_clock_param_ranges(dsidev);
  3628. enable_clocks(1);
  3629. rev = dsi_read_reg(dsidev, DSI_REVISION);
  3630. dev_dbg(&dsidev->dev, "OMAP DSI rev %d.%d\n",
  3631. FLD_GET(rev, 7, 4), FLD_GET(rev, 3, 0));
  3632. dsi->num_data_lanes = dsi_get_num_data_lanes(dsidev);
  3633. enable_clocks(0);
  3634. return 0;
  3635. err2:
  3636. iounmap(dsi->base);
  3637. err1:
  3638. kfree(dsi);
  3639. err0:
  3640. return r;
  3641. }
  3642. static void dsi_exit(struct platform_device *dsidev)
  3643. {
  3644. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3645. if (dsi->vdds_dsi_reg != NULL) {
  3646. if (dsi->vdds_dsi_enabled) {
  3647. regulator_disable(dsi->vdds_dsi_reg);
  3648. dsi->vdds_dsi_enabled = false;
  3649. }
  3650. regulator_put(dsi->vdds_dsi_reg);
  3651. dsi->vdds_dsi_reg = NULL;
  3652. }
  3653. free_irq(dsi->irq, dsi->pdev);
  3654. iounmap(dsi->base);
  3655. kfree(dsi);
  3656. DSSDBG("omap_dsi_exit\n");
  3657. }
  3658. /* DSI1 HW IP initialisation */
  3659. static int omap_dsi1hw_probe(struct platform_device *dsidev)
  3660. {
  3661. int r;
  3662. r = dsi_init(dsidev);
  3663. if (r) {
  3664. DSSERR("Failed to initialize DSI\n");
  3665. goto err_dsi;
  3666. }
  3667. err_dsi:
  3668. return r;
  3669. }
  3670. static int omap_dsi1hw_remove(struct platform_device *dsidev)
  3671. {
  3672. struct dsi_data *dsi = dsi_get_dsidrv_data(dsidev);
  3673. dsi_exit(dsidev);
  3674. WARN_ON(dsi->scp_clk_refcount > 0);
  3675. return 0;
  3676. }
  3677. static struct platform_driver omap_dsi1hw_driver = {
  3678. .probe = omap_dsi1hw_probe,
  3679. .remove = omap_dsi1hw_remove,
  3680. .driver = {
  3681. .name = "omapdss_dsi1",
  3682. .owner = THIS_MODULE,
  3683. },
  3684. };
  3685. int dsi_init_platform_driver(void)
  3686. {
  3687. return platform_driver_register(&omap_dsi1hw_driver);
  3688. }
  3689. void dsi_uninit_platform_driver(void)
  3690. {
  3691. return platform_driver_unregister(&omap_dsi1hw_driver);
  3692. }