dsi.c 140 KB

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