dsi.c 133 KB

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