dsi.c 137 KB

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