dsi.c 122 KB

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