dsi.c 133 KB

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