dsi.c 138 KB

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