dsi.c 134 KB

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