dsi.c 135 KB

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