intel_display.c 249 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. */
  26. #include <linux/dmi.h>
  27. #include <linux/module.h>
  28. #include <linux/input.h>
  29. #include <linux/i2c.h>
  30. #include <linux/kernel.h>
  31. #include <linux/slab.h>
  32. #include <linux/vgaarb.h>
  33. #include <drm/drm_edid.h>
  34. #include <drm/drmP.h>
  35. #include "intel_drv.h"
  36. #include <drm/i915_drm.h>
  37. #include "i915_drv.h"
  38. #include "i915_trace.h"
  39. #include <drm/drm_dp_helper.h>
  40. #include <drm/drm_crtc_helper.h>
  41. #include <linux/dma_remapping.h>
  42. bool intel_pipe_has_type(struct drm_crtc *crtc, int type);
  43. static void intel_increase_pllclock(struct drm_crtc *crtc);
  44. static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
  45. typedef struct {
  46. /* given values */
  47. int n;
  48. int m1, m2;
  49. int p1, p2;
  50. /* derived values */
  51. int dot;
  52. int vco;
  53. int m;
  54. int p;
  55. } intel_clock_t;
  56. typedef struct {
  57. int min, max;
  58. } intel_range_t;
  59. typedef struct {
  60. int dot_limit;
  61. int p2_slow, p2_fast;
  62. } intel_p2_t;
  63. #define INTEL_P2_NUM 2
  64. typedef struct intel_limit intel_limit_t;
  65. struct intel_limit {
  66. intel_range_t dot, vco, n, m, m1, m2, p, p1;
  67. intel_p2_t p2;
  68. bool (* find_pll)(const intel_limit_t *, struct drm_crtc *,
  69. int, int, intel_clock_t *, intel_clock_t *);
  70. };
  71. /* FDI */
  72. #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */
  73. int
  74. intel_pch_rawclk(struct drm_device *dev)
  75. {
  76. struct drm_i915_private *dev_priv = dev->dev_private;
  77. WARN_ON(!HAS_PCH_SPLIT(dev));
  78. return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK;
  79. }
  80. static bool
  81. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  82. int target, int refclk, intel_clock_t *match_clock,
  83. intel_clock_t *best_clock);
  84. static bool
  85. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  86. int target, int refclk, intel_clock_t *match_clock,
  87. intel_clock_t *best_clock);
  88. static bool
  89. intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc,
  90. int target, int refclk, intel_clock_t *match_clock,
  91. intel_clock_t *best_clock);
  92. static bool
  93. intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc,
  94. int target, int refclk, intel_clock_t *match_clock,
  95. intel_clock_t *best_clock);
  96. static bool
  97. intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
  98. int target, int refclk, intel_clock_t *match_clock,
  99. intel_clock_t *best_clock);
  100. static inline u32 /* units of 100MHz */
  101. intel_fdi_link_freq(struct drm_device *dev)
  102. {
  103. if (IS_GEN5(dev)) {
  104. struct drm_i915_private *dev_priv = dev->dev_private;
  105. return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2;
  106. } else
  107. return 27;
  108. }
  109. static const intel_limit_t intel_limits_i8xx_dvo = {
  110. .dot = { .min = 25000, .max = 350000 },
  111. .vco = { .min = 930000, .max = 1400000 },
  112. .n = { .min = 3, .max = 16 },
  113. .m = { .min = 96, .max = 140 },
  114. .m1 = { .min = 18, .max = 26 },
  115. .m2 = { .min = 6, .max = 16 },
  116. .p = { .min = 4, .max = 128 },
  117. .p1 = { .min = 2, .max = 33 },
  118. .p2 = { .dot_limit = 165000,
  119. .p2_slow = 4, .p2_fast = 2 },
  120. .find_pll = intel_find_best_PLL,
  121. };
  122. static const intel_limit_t intel_limits_i8xx_lvds = {
  123. .dot = { .min = 25000, .max = 350000 },
  124. .vco = { .min = 930000, .max = 1400000 },
  125. .n = { .min = 3, .max = 16 },
  126. .m = { .min = 96, .max = 140 },
  127. .m1 = { .min = 18, .max = 26 },
  128. .m2 = { .min = 6, .max = 16 },
  129. .p = { .min = 4, .max = 128 },
  130. .p1 = { .min = 1, .max = 6 },
  131. .p2 = { .dot_limit = 165000,
  132. .p2_slow = 14, .p2_fast = 7 },
  133. .find_pll = intel_find_best_PLL,
  134. };
  135. static const intel_limit_t intel_limits_i9xx_sdvo = {
  136. .dot = { .min = 20000, .max = 400000 },
  137. .vco = { .min = 1400000, .max = 2800000 },
  138. .n = { .min = 1, .max = 6 },
  139. .m = { .min = 70, .max = 120 },
  140. .m1 = { .min = 10, .max = 22 },
  141. .m2 = { .min = 5, .max = 9 },
  142. .p = { .min = 5, .max = 80 },
  143. .p1 = { .min = 1, .max = 8 },
  144. .p2 = { .dot_limit = 200000,
  145. .p2_slow = 10, .p2_fast = 5 },
  146. .find_pll = intel_find_best_PLL,
  147. };
  148. static const intel_limit_t intel_limits_i9xx_lvds = {
  149. .dot = { .min = 20000, .max = 400000 },
  150. .vco = { .min = 1400000, .max = 2800000 },
  151. .n = { .min = 1, .max = 6 },
  152. .m = { .min = 70, .max = 120 },
  153. .m1 = { .min = 10, .max = 22 },
  154. .m2 = { .min = 5, .max = 9 },
  155. .p = { .min = 7, .max = 98 },
  156. .p1 = { .min = 1, .max = 8 },
  157. .p2 = { .dot_limit = 112000,
  158. .p2_slow = 14, .p2_fast = 7 },
  159. .find_pll = intel_find_best_PLL,
  160. };
  161. static const intel_limit_t intel_limits_g4x_sdvo = {
  162. .dot = { .min = 25000, .max = 270000 },
  163. .vco = { .min = 1750000, .max = 3500000},
  164. .n = { .min = 1, .max = 4 },
  165. .m = { .min = 104, .max = 138 },
  166. .m1 = { .min = 17, .max = 23 },
  167. .m2 = { .min = 5, .max = 11 },
  168. .p = { .min = 10, .max = 30 },
  169. .p1 = { .min = 1, .max = 3},
  170. .p2 = { .dot_limit = 270000,
  171. .p2_slow = 10,
  172. .p2_fast = 10
  173. },
  174. .find_pll = intel_g4x_find_best_PLL,
  175. };
  176. static const intel_limit_t intel_limits_g4x_hdmi = {
  177. .dot = { .min = 22000, .max = 400000 },
  178. .vco = { .min = 1750000, .max = 3500000},
  179. .n = { .min = 1, .max = 4 },
  180. .m = { .min = 104, .max = 138 },
  181. .m1 = { .min = 16, .max = 23 },
  182. .m2 = { .min = 5, .max = 11 },
  183. .p = { .min = 5, .max = 80 },
  184. .p1 = { .min = 1, .max = 8},
  185. .p2 = { .dot_limit = 165000,
  186. .p2_slow = 10, .p2_fast = 5 },
  187. .find_pll = intel_g4x_find_best_PLL,
  188. };
  189. static const intel_limit_t intel_limits_g4x_single_channel_lvds = {
  190. .dot = { .min = 20000, .max = 115000 },
  191. .vco = { .min = 1750000, .max = 3500000 },
  192. .n = { .min = 1, .max = 3 },
  193. .m = { .min = 104, .max = 138 },
  194. .m1 = { .min = 17, .max = 23 },
  195. .m2 = { .min = 5, .max = 11 },
  196. .p = { .min = 28, .max = 112 },
  197. .p1 = { .min = 2, .max = 8 },
  198. .p2 = { .dot_limit = 0,
  199. .p2_slow = 14, .p2_fast = 14
  200. },
  201. .find_pll = intel_g4x_find_best_PLL,
  202. };
  203. static const intel_limit_t intel_limits_g4x_dual_channel_lvds = {
  204. .dot = { .min = 80000, .max = 224000 },
  205. .vco = { .min = 1750000, .max = 3500000 },
  206. .n = { .min = 1, .max = 3 },
  207. .m = { .min = 104, .max = 138 },
  208. .m1 = { .min = 17, .max = 23 },
  209. .m2 = { .min = 5, .max = 11 },
  210. .p = { .min = 14, .max = 42 },
  211. .p1 = { .min = 2, .max = 6 },
  212. .p2 = { .dot_limit = 0,
  213. .p2_slow = 7, .p2_fast = 7
  214. },
  215. .find_pll = intel_g4x_find_best_PLL,
  216. };
  217. static const intel_limit_t intel_limits_g4x_display_port = {
  218. .dot = { .min = 161670, .max = 227000 },
  219. .vco = { .min = 1750000, .max = 3500000},
  220. .n = { .min = 1, .max = 2 },
  221. .m = { .min = 97, .max = 108 },
  222. .m1 = { .min = 0x10, .max = 0x12 },
  223. .m2 = { .min = 0x05, .max = 0x06 },
  224. .p = { .min = 10, .max = 20 },
  225. .p1 = { .min = 1, .max = 2},
  226. .p2 = { .dot_limit = 0,
  227. .p2_slow = 10, .p2_fast = 10 },
  228. .find_pll = intel_find_pll_g4x_dp,
  229. };
  230. static const intel_limit_t intel_limits_pineview_sdvo = {
  231. .dot = { .min = 20000, .max = 400000},
  232. .vco = { .min = 1700000, .max = 3500000 },
  233. /* Pineview's Ncounter is a ring counter */
  234. .n = { .min = 3, .max = 6 },
  235. .m = { .min = 2, .max = 256 },
  236. /* Pineview only has one combined m divider, which we treat as m2. */
  237. .m1 = { .min = 0, .max = 0 },
  238. .m2 = { .min = 0, .max = 254 },
  239. .p = { .min = 5, .max = 80 },
  240. .p1 = { .min = 1, .max = 8 },
  241. .p2 = { .dot_limit = 200000,
  242. .p2_slow = 10, .p2_fast = 5 },
  243. .find_pll = intel_find_best_PLL,
  244. };
  245. static const intel_limit_t intel_limits_pineview_lvds = {
  246. .dot = { .min = 20000, .max = 400000 },
  247. .vco = { .min = 1700000, .max = 3500000 },
  248. .n = { .min = 3, .max = 6 },
  249. .m = { .min = 2, .max = 256 },
  250. .m1 = { .min = 0, .max = 0 },
  251. .m2 = { .min = 0, .max = 254 },
  252. .p = { .min = 7, .max = 112 },
  253. .p1 = { .min = 1, .max = 8 },
  254. .p2 = { .dot_limit = 112000,
  255. .p2_slow = 14, .p2_fast = 14 },
  256. .find_pll = intel_find_best_PLL,
  257. };
  258. /* Ironlake / Sandybridge
  259. *
  260. * We calculate clock using (register_value + 2) for N/M1/M2, so here
  261. * the range value for them is (actual_value - 2).
  262. */
  263. static const intel_limit_t intel_limits_ironlake_dac = {
  264. .dot = { .min = 25000, .max = 350000 },
  265. .vco = { .min = 1760000, .max = 3510000 },
  266. .n = { .min = 1, .max = 5 },
  267. .m = { .min = 79, .max = 127 },
  268. .m1 = { .min = 12, .max = 22 },
  269. .m2 = { .min = 5, .max = 9 },
  270. .p = { .min = 5, .max = 80 },
  271. .p1 = { .min = 1, .max = 8 },
  272. .p2 = { .dot_limit = 225000,
  273. .p2_slow = 10, .p2_fast = 5 },
  274. .find_pll = intel_g4x_find_best_PLL,
  275. };
  276. static const intel_limit_t intel_limits_ironlake_single_lvds = {
  277. .dot = { .min = 25000, .max = 350000 },
  278. .vco = { .min = 1760000, .max = 3510000 },
  279. .n = { .min = 1, .max = 3 },
  280. .m = { .min = 79, .max = 118 },
  281. .m1 = { .min = 12, .max = 22 },
  282. .m2 = { .min = 5, .max = 9 },
  283. .p = { .min = 28, .max = 112 },
  284. .p1 = { .min = 2, .max = 8 },
  285. .p2 = { .dot_limit = 225000,
  286. .p2_slow = 14, .p2_fast = 14 },
  287. .find_pll = intel_g4x_find_best_PLL,
  288. };
  289. static const intel_limit_t intel_limits_ironlake_dual_lvds = {
  290. .dot = { .min = 25000, .max = 350000 },
  291. .vco = { .min = 1760000, .max = 3510000 },
  292. .n = { .min = 1, .max = 3 },
  293. .m = { .min = 79, .max = 127 },
  294. .m1 = { .min = 12, .max = 22 },
  295. .m2 = { .min = 5, .max = 9 },
  296. .p = { .min = 14, .max = 56 },
  297. .p1 = { .min = 2, .max = 8 },
  298. .p2 = { .dot_limit = 225000,
  299. .p2_slow = 7, .p2_fast = 7 },
  300. .find_pll = intel_g4x_find_best_PLL,
  301. };
  302. /* LVDS 100mhz refclk limits. */
  303. static const intel_limit_t intel_limits_ironlake_single_lvds_100m = {
  304. .dot = { .min = 25000, .max = 350000 },
  305. .vco = { .min = 1760000, .max = 3510000 },
  306. .n = { .min = 1, .max = 2 },
  307. .m = { .min = 79, .max = 126 },
  308. .m1 = { .min = 12, .max = 22 },
  309. .m2 = { .min = 5, .max = 9 },
  310. .p = { .min = 28, .max = 112 },
  311. .p1 = { .min = 2, .max = 8 },
  312. .p2 = { .dot_limit = 225000,
  313. .p2_slow = 14, .p2_fast = 14 },
  314. .find_pll = intel_g4x_find_best_PLL,
  315. };
  316. static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = {
  317. .dot = { .min = 25000, .max = 350000 },
  318. .vco = { .min = 1760000, .max = 3510000 },
  319. .n = { .min = 1, .max = 3 },
  320. .m = { .min = 79, .max = 126 },
  321. .m1 = { .min = 12, .max = 22 },
  322. .m2 = { .min = 5, .max = 9 },
  323. .p = { .min = 14, .max = 42 },
  324. .p1 = { .min = 2, .max = 6 },
  325. .p2 = { .dot_limit = 225000,
  326. .p2_slow = 7, .p2_fast = 7 },
  327. .find_pll = intel_g4x_find_best_PLL,
  328. };
  329. static const intel_limit_t intel_limits_ironlake_display_port = {
  330. .dot = { .min = 25000, .max = 350000 },
  331. .vco = { .min = 1760000, .max = 3510000},
  332. .n = { .min = 1, .max = 2 },
  333. .m = { .min = 81, .max = 90 },
  334. .m1 = { .min = 12, .max = 22 },
  335. .m2 = { .min = 5, .max = 9 },
  336. .p = { .min = 10, .max = 20 },
  337. .p1 = { .min = 1, .max = 2},
  338. .p2 = { .dot_limit = 0,
  339. .p2_slow = 10, .p2_fast = 10 },
  340. .find_pll = intel_find_pll_ironlake_dp,
  341. };
  342. static const intel_limit_t intel_limits_vlv_dac = {
  343. .dot = { .min = 25000, .max = 270000 },
  344. .vco = { .min = 4000000, .max = 6000000 },
  345. .n = { .min = 1, .max = 7 },
  346. .m = { .min = 22, .max = 450 }, /* guess */
  347. .m1 = { .min = 2, .max = 3 },
  348. .m2 = { .min = 11, .max = 156 },
  349. .p = { .min = 10, .max = 30 },
  350. .p1 = { .min = 2, .max = 3 },
  351. .p2 = { .dot_limit = 270000,
  352. .p2_slow = 2, .p2_fast = 20 },
  353. .find_pll = intel_vlv_find_best_pll,
  354. };
  355. static const intel_limit_t intel_limits_vlv_hdmi = {
  356. .dot = { .min = 20000, .max = 165000 },
  357. .vco = { .min = 4000000, .max = 5994000},
  358. .n = { .min = 1, .max = 7 },
  359. .m = { .min = 60, .max = 300 }, /* guess */
  360. .m1 = { .min = 2, .max = 3 },
  361. .m2 = { .min = 11, .max = 156 },
  362. .p = { .min = 10, .max = 30 },
  363. .p1 = { .min = 2, .max = 3 },
  364. .p2 = { .dot_limit = 270000,
  365. .p2_slow = 2, .p2_fast = 20 },
  366. .find_pll = intel_vlv_find_best_pll,
  367. };
  368. static const intel_limit_t intel_limits_vlv_dp = {
  369. .dot = { .min = 25000, .max = 270000 },
  370. .vco = { .min = 4000000, .max = 6000000 },
  371. .n = { .min = 1, .max = 7 },
  372. .m = { .min = 22, .max = 450 },
  373. .m1 = { .min = 2, .max = 3 },
  374. .m2 = { .min = 11, .max = 156 },
  375. .p = { .min = 10, .max = 30 },
  376. .p1 = { .min = 2, .max = 3 },
  377. .p2 = { .dot_limit = 270000,
  378. .p2_slow = 2, .p2_fast = 20 },
  379. .find_pll = intel_vlv_find_best_pll,
  380. };
  381. u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg)
  382. {
  383. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  384. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  385. DRM_ERROR("DPIO idle wait timed out\n");
  386. return 0;
  387. }
  388. I915_WRITE(DPIO_REG, reg);
  389. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID |
  390. DPIO_BYTE);
  391. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  392. DRM_ERROR("DPIO read wait timed out\n");
  393. return 0;
  394. }
  395. return I915_READ(DPIO_DATA);
  396. }
  397. static void intel_dpio_write(struct drm_i915_private *dev_priv, int reg,
  398. u32 val)
  399. {
  400. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  401. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) {
  402. DRM_ERROR("DPIO idle wait timed out\n");
  403. return;
  404. }
  405. I915_WRITE(DPIO_DATA, val);
  406. I915_WRITE(DPIO_REG, reg);
  407. I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_WRITE | DPIO_PORTID |
  408. DPIO_BYTE);
  409. if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100))
  410. DRM_ERROR("DPIO write wait timed out\n");
  411. }
  412. static void vlv_init_dpio(struct drm_device *dev)
  413. {
  414. struct drm_i915_private *dev_priv = dev->dev_private;
  415. /* Reset the DPIO config */
  416. I915_WRITE(DPIO_CTL, 0);
  417. POSTING_READ(DPIO_CTL);
  418. I915_WRITE(DPIO_CTL, 1);
  419. POSTING_READ(DPIO_CTL);
  420. }
  421. static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc,
  422. int refclk)
  423. {
  424. struct drm_device *dev = crtc->dev;
  425. const intel_limit_t *limit;
  426. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  427. if (intel_is_dual_link_lvds(dev)) {
  428. /* LVDS dual channel */
  429. if (refclk == 100000)
  430. limit = &intel_limits_ironlake_dual_lvds_100m;
  431. else
  432. limit = &intel_limits_ironlake_dual_lvds;
  433. } else {
  434. if (refclk == 100000)
  435. limit = &intel_limits_ironlake_single_lvds_100m;
  436. else
  437. limit = &intel_limits_ironlake_single_lvds;
  438. }
  439. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  440. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  441. limit = &intel_limits_ironlake_display_port;
  442. else
  443. limit = &intel_limits_ironlake_dac;
  444. return limit;
  445. }
  446. static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc)
  447. {
  448. struct drm_device *dev = crtc->dev;
  449. const intel_limit_t *limit;
  450. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  451. if (intel_is_dual_link_lvds(dev))
  452. /* LVDS with dual channel */
  453. limit = &intel_limits_g4x_dual_channel_lvds;
  454. else
  455. /* LVDS with dual channel */
  456. limit = &intel_limits_g4x_single_channel_lvds;
  457. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) ||
  458. intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  459. limit = &intel_limits_g4x_hdmi;
  460. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) {
  461. limit = &intel_limits_g4x_sdvo;
  462. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  463. limit = &intel_limits_g4x_display_port;
  464. } else /* The option is for other outputs */
  465. limit = &intel_limits_i9xx_sdvo;
  466. return limit;
  467. }
  468. static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk)
  469. {
  470. struct drm_device *dev = crtc->dev;
  471. const intel_limit_t *limit;
  472. if (HAS_PCH_SPLIT(dev))
  473. limit = intel_ironlake_limit(crtc, refclk);
  474. else if (IS_G4X(dev)) {
  475. limit = intel_g4x_limit(crtc);
  476. } else if (IS_PINEVIEW(dev)) {
  477. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  478. limit = &intel_limits_pineview_lvds;
  479. else
  480. limit = &intel_limits_pineview_sdvo;
  481. } else if (IS_VALLEYVIEW(dev)) {
  482. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG))
  483. limit = &intel_limits_vlv_dac;
  484. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  485. limit = &intel_limits_vlv_hdmi;
  486. else
  487. limit = &intel_limits_vlv_dp;
  488. } else if (!IS_GEN2(dev)) {
  489. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  490. limit = &intel_limits_i9xx_lvds;
  491. else
  492. limit = &intel_limits_i9xx_sdvo;
  493. } else {
  494. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  495. limit = &intel_limits_i8xx_lvds;
  496. else
  497. limit = &intel_limits_i8xx_dvo;
  498. }
  499. return limit;
  500. }
  501. /* m1 is reserved as 0 in Pineview, n is a ring counter */
  502. static void pineview_clock(int refclk, intel_clock_t *clock)
  503. {
  504. clock->m = clock->m2 + 2;
  505. clock->p = clock->p1 * clock->p2;
  506. clock->vco = refclk * clock->m / clock->n;
  507. clock->dot = clock->vco / clock->p;
  508. }
  509. static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock)
  510. {
  511. if (IS_PINEVIEW(dev)) {
  512. pineview_clock(refclk, clock);
  513. return;
  514. }
  515. clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2);
  516. clock->p = clock->p1 * clock->p2;
  517. clock->vco = refclk * clock->m / (clock->n + 2);
  518. clock->dot = clock->vco / clock->p;
  519. }
  520. /**
  521. * Returns whether any output on the specified pipe is of the specified type
  522. */
  523. bool intel_pipe_has_type(struct drm_crtc *crtc, int type)
  524. {
  525. struct drm_device *dev = crtc->dev;
  526. struct intel_encoder *encoder;
  527. for_each_encoder_on_crtc(dev, crtc, encoder)
  528. if (encoder->type == type)
  529. return true;
  530. return false;
  531. }
  532. #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0)
  533. /**
  534. * Returns whether the given set of divisors are valid for a given refclk with
  535. * the given connectors.
  536. */
  537. static bool intel_PLL_is_valid(struct drm_device *dev,
  538. const intel_limit_t *limit,
  539. const intel_clock_t *clock)
  540. {
  541. if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1)
  542. INTELPllInvalid("p1 out of range\n");
  543. if (clock->p < limit->p.min || limit->p.max < clock->p)
  544. INTELPllInvalid("p out of range\n");
  545. if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2)
  546. INTELPllInvalid("m2 out of range\n");
  547. if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1)
  548. INTELPllInvalid("m1 out of range\n");
  549. if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev))
  550. INTELPllInvalid("m1 <= m2\n");
  551. if (clock->m < limit->m.min || limit->m.max < clock->m)
  552. INTELPllInvalid("m out of range\n");
  553. if (clock->n < limit->n.min || limit->n.max < clock->n)
  554. INTELPllInvalid("n out of range\n");
  555. if (clock->vco < limit->vco.min || limit->vco.max < clock->vco)
  556. INTELPllInvalid("vco out of range\n");
  557. /* XXX: We may need to be checking "Dot clock" depending on the multiplier,
  558. * connector, etc., rather than just a single range.
  559. */
  560. if (clock->dot < limit->dot.min || limit->dot.max < clock->dot)
  561. INTELPllInvalid("dot out of range\n");
  562. return true;
  563. }
  564. static bool
  565. intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  566. int target, int refclk, intel_clock_t *match_clock,
  567. intel_clock_t *best_clock)
  568. {
  569. struct drm_device *dev = crtc->dev;
  570. intel_clock_t clock;
  571. int err = target;
  572. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  573. /*
  574. * For LVDS just rely on its current settings for dual-channel.
  575. * We haven't figured out how to reliably set up different
  576. * single/dual channel state, if we even can.
  577. */
  578. if (intel_is_dual_link_lvds(dev))
  579. clock.p2 = limit->p2.p2_fast;
  580. else
  581. clock.p2 = limit->p2.p2_slow;
  582. } else {
  583. if (target < limit->p2.dot_limit)
  584. clock.p2 = limit->p2.p2_slow;
  585. else
  586. clock.p2 = limit->p2.p2_fast;
  587. }
  588. memset(best_clock, 0, sizeof(*best_clock));
  589. for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max;
  590. clock.m1++) {
  591. for (clock.m2 = limit->m2.min;
  592. clock.m2 <= limit->m2.max; clock.m2++) {
  593. /* m1 is always 0 in Pineview */
  594. if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev))
  595. break;
  596. for (clock.n = limit->n.min;
  597. clock.n <= limit->n.max; clock.n++) {
  598. for (clock.p1 = limit->p1.min;
  599. clock.p1 <= limit->p1.max; clock.p1++) {
  600. int this_err;
  601. intel_clock(dev, refclk, &clock);
  602. if (!intel_PLL_is_valid(dev, limit,
  603. &clock))
  604. continue;
  605. if (match_clock &&
  606. clock.p != match_clock->p)
  607. continue;
  608. this_err = abs(clock.dot - target);
  609. if (this_err < err) {
  610. *best_clock = clock;
  611. err = this_err;
  612. }
  613. }
  614. }
  615. }
  616. }
  617. return (err != target);
  618. }
  619. static bool
  620. intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc,
  621. int target, int refclk, intel_clock_t *match_clock,
  622. intel_clock_t *best_clock)
  623. {
  624. struct drm_device *dev = crtc->dev;
  625. intel_clock_t clock;
  626. int max_n;
  627. bool found;
  628. /* approximately equals target * 0.00585 */
  629. int err_most = (target >> 8) + (target >> 9);
  630. found = false;
  631. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  632. int lvds_reg;
  633. if (HAS_PCH_SPLIT(dev))
  634. lvds_reg = PCH_LVDS;
  635. else
  636. lvds_reg = LVDS;
  637. if (intel_is_dual_link_lvds(dev))
  638. clock.p2 = limit->p2.p2_fast;
  639. else
  640. clock.p2 = limit->p2.p2_slow;
  641. } else {
  642. if (target < limit->p2.dot_limit)
  643. clock.p2 = limit->p2.p2_slow;
  644. else
  645. clock.p2 = limit->p2.p2_fast;
  646. }
  647. memset(best_clock, 0, sizeof(*best_clock));
  648. max_n = limit->n.max;
  649. /* based on hardware requirement, prefer smaller n to precision */
  650. for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) {
  651. /* based on hardware requirement, prefere larger m1,m2 */
  652. for (clock.m1 = limit->m1.max;
  653. clock.m1 >= limit->m1.min; clock.m1--) {
  654. for (clock.m2 = limit->m2.max;
  655. clock.m2 >= limit->m2.min; clock.m2--) {
  656. for (clock.p1 = limit->p1.max;
  657. clock.p1 >= limit->p1.min; clock.p1--) {
  658. int this_err;
  659. intel_clock(dev, refclk, &clock);
  660. if (!intel_PLL_is_valid(dev, limit,
  661. &clock))
  662. continue;
  663. if (match_clock &&
  664. clock.p != match_clock->p)
  665. continue;
  666. this_err = abs(clock.dot - target);
  667. if (this_err < err_most) {
  668. *best_clock = clock;
  669. err_most = this_err;
  670. max_n = clock.n;
  671. found = true;
  672. }
  673. }
  674. }
  675. }
  676. }
  677. return found;
  678. }
  679. static bool
  680. intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  681. int target, int refclk, intel_clock_t *match_clock,
  682. intel_clock_t *best_clock)
  683. {
  684. struct drm_device *dev = crtc->dev;
  685. intel_clock_t clock;
  686. if (target < 200000) {
  687. clock.n = 1;
  688. clock.p1 = 2;
  689. clock.p2 = 10;
  690. clock.m1 = 12;
  691. clock.m2 = 9;
  692. } else {
  693. clock.n = 2;
  694. clock.p1 = 1;
  695. clock.p2 = 10;
  696. clock.m1 = 14;
  697. clock.m2 = 8;
  698. }
  699. intel_clock(dev, refclk, &clock);
  700. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  701. return true;
  702. }
  703. /* DisplayPort has only two frequencies, 162MHz and 270MHz */
  704. static bool
  705. intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc,
  706. int target, int refclk, intel_clock_t *match_clock,
  707. intel_clock_t *best_clock)
  708. {
  709. intel_clock_t clock;
  710. if (target < 200000) {
  711. clock.p1 = 2;
  712. clock.p2 = 10;
  713. clock.n = 2;
  714. clock.m1 = 23;
  715. clock.m2 = 8;
  716. } else {
  717. clock.p1 = 1;
  718. clock.p2 = 10;
  719. clock.n = 1;
  720. clock.m1 = 14;
  721. clock.m2 = 2;
  722. }
  723. clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2);
  724. clock.p = (clock.p1 * clock.p2);
  725. clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p;
  726. clock.vco = 0;
  727. memcpy(best_clock, &clock, sizeof(intel_clock_t));
  728. return true;
  729. }
  730. static bool
  731. intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc,
  732. int target, int refclk, intel_clock_t *match_clock,
  733. intel_clock_t *best_clock)
  734. {
  735. u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2;
  736. u32 m, n, fastclk;
  737. u32 updrate, minupdate, fracbits, p;
  738. unsigned long bestppm, ppm, absppm;
  739. int dotclk, flag;
  740. flag = 0;
  741. dotclk = target * 1000;
  742. bestppm = 1000000;
  743. ppm = absppm = 0;
  744. fastclk = dotclk / (2*100);
  745. updrate = 0;
  746. minupdate = 19200;
  747. fracbits = 1;
  748. n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0;
  749. bestm1 = bestm2 = bestp1 = bestp2 = 0;
  750. /* based on hardware requirement, prefer smaller n to precision */
  751. for (n = limit->n.min; n <= ((refclk) / minupdate); n++) {
  752. updrate = refclk / n;
  753. for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) {
  754. for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) {
  755. if (p2 > 10)
  756. p2 = p2 - 1;
  757. p = p1 * p2;
  758. /* based on hardware requirement, prefer bigger m1,m2 values */
  759. for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) {
  760. m2 = (((2*(fastclk * p * n / m1 )) +
  761. refclk) / (2*refclk));
  762. m = m1 * m2;
  763. vco = updrate * m;
  764. if (vco >= limit->vco.min && vco < limit->vco.max) {
  765. ppm = 1000000 * ((vco / p) - fastclk) / fastclk;
  766. absppm = (ppm > 0) ? ppm : (-ppm);
  767. if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) {
  768. bestppm = 0;
  769. flag = 1;
  770. }
  771. if (absppm < bestppm - 10) {
  772. bestppm = absppm;
  773. flag = 1;
  774. }
  775. if (flag) {
  776. bestn = n;
  777. bestm1 = m1;
  778. bestm2 = m2;
  779. bestp1 = p1;
  780. bestp2 = p2;
  781. flag = 0;
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. best_clock->n = bestn;
  789. best_clock->m1 = bestm1;
  790. best_clock->m2 = bestm2;
  791. best_clock->p1 = bestp1;
  792. best_clock->p2 = bestp2;
  793. return true;
  794. }
  795. enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv,
  796. enum pipe pipe)
  797. {
  798. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  799. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  800. return intel_crtc->cpu_transcoder;
  801. }
  802. static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe)
  803. {
  804. struct drm_i915_private *dev_priv = dev->dev_private;
  805. u32 frame, frame_reg = PIPEFRAME(pipe);
  806. frame = I915_READ(frame_reg);
  807. if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50))
  808. DRM_DEBUG_KMS("vblank wait timed out\n");
  809. }
  810. /**
  811. * intel_wait_for_vblank - wait for vblank on a given pipe
  812. * @dev: drm device
  813. * @pipe: pipe to wait for
  814. *
  815. * Wait for vblank to occur on a given pipe. Needed for various bits of
  816. * mode setting code.
  817. */
  818. void intel_wait_for_vblank(struct drm_device *dev, int pipe)
  819. {
  820. struct drm_i915_private *dev_priv = dev->dev_private;
  821. int pipestat_reg = PIPESTAT(pipe);
  822. if (INTEL_INFO(dev)->gen >= 5) {
  823. ironlake_wait_for_vblank(dev, pipe);
  824. return;
  825. }
  826. /* Clear existing vblank status. Note this will clear any other
  827. * sticky status fields as well.
  828. *
  829. * This races with i915_driver_irq_handler() with the result
  830. * that either function could miss a vblank event. Here it is not
  831. * fatal, as we will either wait upon the next vblank interrupt or
  832. * timeout. Generally speaking intel_wait_for_vblank() is only
  833. * called during modeset at which time the GPU should be idle and
  834. * should *not* be performing page flips and thus not waiting on
  835. * vblanks...
  836. * Currently, the result of us stealing a vblank from the irq
  837. * handler is that a single frame will be skipped during swapbuffers.
  838. */
  839. I915_WRITE(pipestat_reg,
  840. I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS);
  841. /* Wait for vblank interrupt bit to set */
  842. if (wait_for(I915_READ(pipestat_reg) &
  843. PIPE_VBLANK_INTERRUPT_STATUS,
  844. 50))
  845. DRM_DEBUG_KMS("vblank wait timed out\n");
  846. }
  847. /*
  848. * intel_wait_for_pipe_off - wait for pipe to turn off
  849. * @dev: drm device
  850. * @pipe: pipe to wait for
  851. *
  852. * After disabling a pipe, we can't wait for vblank in the usual way,
  853. * spinning on the vblank interrupt status bit, since we won't actually
  854. * see an interrupt when the pipe is disabled.
  855. *
  856. * On Gen4 and above:
  857. * wait for the pipe register state bit to turn off
  858. *
  859. * Otherwise:
  860. * wait for the display line value to settle (it usually
  861. * ends up stopping at the start of the next frame).
  862. *
  863. */
  864. void intel_wait_for_pipe_off(struct drm_device *dev, int pipe)
  865. {
  866. struct drm_i915_private *dev_priv = dev->dev_private;
  867. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  868. pipe);
  869. if (INTEL_INFO(dev)->gen >= 4) {
  870. int reg = PIPECONF(cpu_transcoder);
  871. /* Wait for the Pipe State to go off */
  872. if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0,
  873. 100))
  874. WARN(1, "pipe_off wait timed out\n");
  875. } else {
  876. u32 last_line, line_mask;
  877. int reg = PIPEDSL(pipe);
  878. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  879. if (IS_GEN2(dev))
  880. line_mask = DSL_LINEMASK_GEN2;
  881. else
  882. line_mask = DSL_LINEMASK_GEN3;
  883. /* Wait for the display line to settle */
  884. do {
  885. last_line = I915_READ(reg) & line_mask;
  886. mdelay(5);
  887. } while (((I915_READ(reg) & line_mask) != last_line) &&
  888. time_after(timeout, jiffies));
  889. if (time_after(jiffies, timeout))
  890. WARN(1, "pipe_off wait timed out\n");
  891. }
  892. }
  893. /*
  894. * ibx_digital_port_connected - is the specified port connected?
  895. * @dev_priv: i915 private structure
  896. * @port: the port to test
  897. *
  898. * Returns true if @port is connected, false otherwise.
  899. */
  900. bool ibx_digital_port_connected(struct drm_i915_private *dev_priv,
  901. struct intel_digital_port *port)
  902. {
  903. u32 bit;
  904. if (HAS_PCH_IBX(dev_priv->dev)) {
  905. switch(port->port) {
  906. case PORT_B:
  907. bit = SDE_PORTB_HOTPLUG;
  908. break;
  909. case PORT_C:
  910. bit = SDE_PORTC_HOTPLUG;
  911. break;
  912. case PORT_D:
  913. bit = SDE_PORTD_HOTPLUG;
  914. break;
  915. default:
  916. return true;
  917. }
  918. } else {
  919. switch(port->port) {
  920. case PORT_B:
  921. bit = SDE_PORTB_HOTPLUG_CPT;
  922. break;
  923. case PORT_C:
  924. bit = SDE_PORTC_HOTPLUG_CPT;
  925. break;
  926. case PORT_D:
  927. bit = SDE_PORTD_HOTPLUG_CPT;
  928. break;
  929. default:
  930. return true;
  931. }
  932. }
  933. return I915_READ(SDEISR) & bit;
  934. }
  935. static const char *state_string(bool enabled)
  936. {
  937. return enabled ? "on" : "off";
  938. }
  939. /* Only for pre-ILK configs */
  940. static void assert_pll(struct drm_i915_private *dev_priv,
  941. enum pipe pipe, bool state)
  942. {
  943. int reg;
  944. u32 val;
  945. bool cur_state;
  946. reg = DPLL(pipe);
  947. val = I915_READ(reg);
  948. cur_state = !!(val & DPLL_VCO_ENABLE);
  949. WARN(cur_state != state,
  950. "PLL state assertion failure (expected %s, current %s)\n",
  951. state_string(state), state_string(cur_state));
  952. }
  953. #define assert_pll_enabled(d, p) assert_pll(d, p, true)
  954. #define assert_pll_disabled(d, p) assert_pll(d, p, false)
  955. /* For ILK+ */
  956. static void assert_pch_pll(struct drm_i915_private *dev_priv,
  957. struct intel_pch_pll *pll,
  958. struct intel_crtc *crtc,
  959. bool state)
  960. {
  961. u32 val;
  962. bool cur_state;
  963. if (HAS_PCH_LPT(dev_priv->dev)) {
  964. DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n");
  965. return;
  966. }
  967. if (WARN (!pll,
  968. "asserting PCH PLL %s with no PLL\n", state_string(state)))
  969. return;
  970. val = I915_READ(pll->pll_reg);
  971. cur_state = !!(val & DPLL_VCO_ENABLE);
  972. WARN(cur_state != state,
  973. "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n",
  974. pll->pll_reg, state_string(state), state_string(cur_state), val);
  975. /* Make sure the selected PLL is correctly attached to the transcoder */
  976. if (crtc && HAS_PCH_CPT(dev_priv->dev)) {
  977. u32 pch_dpll;
  978. pch_dpll = I915_READ(PCH_DPLL_SEL);
  979. cur_state = pll->pll_reg == _PCH_DPLL_B;
  980. if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state,
  981. "PLL[%d] not attached to this transcoder %d: %08x\n",
  982. cur_state, crtc->pipe, pch_dpll)) {
  983. cur_state = !!(val >> (4*crtc->pipe + 3));
  984. WARN(cur_state != state,
  985. "PLL[%d] not %s on this transcoder %d: %08x\n",
  986. pll->pll_reg == _PCH_DPLL_B,
  987. state_string(state),
  988. crtc->pipe,
  989. val);
  990. }
  991. }
  992. }
  993. #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true)
  994. #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false)
  995. static void assert_fdi_tx(struct drm_i915_private *dev_priv,
  996. enum pipe pipe, bool state)
  997. {
  998. int reg;
  999. u32 val;
  1000. bool cur_state;
  1001. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1002. pipe);
  1003. if (HAS_DDI(dev_priv->dev)) {
  1004. /* DDI does not have a specific FDI_TX register */
  1005. reg = TRANS_DDI_FUNC_CTL(cpu_transcoder);
  1006. val = I915_READ(reg);
  1007. cur_state = !!(val & TRANS_DDI_FUNC_ENABLE);
  1008. } else {
  1009. reg = FDI_TX_CTL(pipe);
  1010. val = I915_READ(reg);
  1011. cur_state = !!(val & FDI_TX_ENABLE);
  1012. }
  1013. WARN(cur_state != state,
  1014. "FDI TX state assertion failure (expected %s, current %s)\n",
  1015. state_string(state), state_string(cur_state));
  1016. }
  1017. #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true)
  1018. #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false)
  1019. static void assert_fdi_rx(struct drm_i915_private *dev_priv,
  1020. enum pipe pipe, bool state)
  1021. {
  1022. int reg;
  1023. u32 val;
  1024. bool cur_state;
  1025. reg = FDI_RX_CTL(pipe);
  1026. val = I915_READ(reg);
  1027. cur_state = !!(val & FDI_RX_ENABLE);
  1028. WARN(cur_state != state,
  1029. "FDI RX state assertion failure (expected %s, current %s)\n",
  1030. state_string(state), state_string(cur_state));
  1031. }
  1032. #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true)
  1033. #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false)
  1034. static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv,
  1035. enum pipe pipe)
  1036. {
  1037. int reg;
  1038. u32 val;
  1039. /* ILK FDI PLL is always enabled */
  1040. if (dev_priv->info->gen == 5)
  1041. return;
  1042. /* On Haswell, DDI ports are responsible for the FDI PLL setup */
  1043. if (HAS_DDI(dev_priv->dev))
  1044. return;
  1045. reg = FDI_TX_CTL(pipe);
  1046. val = I915_READ(reg);
  1047. WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n");
  1048. }
  1049. static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv,
  1050. enum pipe pipe)
  1051. {
  1052. int reg;
  1053. u32 val;
  1054. reg = FDI_RX_CTL(pipe);
  1055. val = I915_READ(reg);
  1056. WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n");
  1057. }
  1058. static void assert_panel_unlocked(struct drm_i915_private *dev_priv,
  1059. enum pipe pipe)
  1060. {
  1061. int pp_reg, lvds_reg;
  1062. u32 val;
  1063. enum pipe panel_pipe = PIPE_A;
  1064. bool locked = true;
  1065. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1066. pp_reg = PCH_PP_CONTROL;
  1067. lvds_reg = PCH_LVDS;
  1068. } else {
  1069. pp_reg = PP_CONTROL;
  1070. lvds_reg = LVDS;
  1071. }
  1072. val = I915_READ(pp_reg);
  1073. if (!(val & PANEL_POWER_ON) ||
  1074. ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS))
  1075. locked = false;
  1076. if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT)
  1077. panel_pipe = PIPE_B;
  1078. WARN(panel_pipe == pipe && locked,
  1079. "panel assertion failure, pipe %c regs locked\n",
  1080. pipe_name(pipe));
  1081. }
  1082. void assert_pipe(struct drm_i915_private *dev_priv,
  1083. enum pipe pipe, bool state)
  1084. {
  1085. int reg;
  1086. u32 val;
  1087. bool cur_state;
  1088. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1089. pipe);
  1090. /* if we need the pipe A quirk it must be always on */
  1091. if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE)
  1092. state = true;
  1093. if (IS_HASWELL(dev_priv->dev) && cpu_transcoder != TRANSCODER_EDP &&
  1094. !(I915_READ(HSW_PWR_WELL_DRIVER) & HSW_PWR_WELL_ENABLE)) {
  1095. cur_state = false;
  1096. } else {
  1097. reg = PIPECONF(cpu_transcoder);
  1098. val = I915_READ(reg);
  1099. cur_state = !!(val & PIPECONF_ENABLE);
  1100. }
  1101. WARN(cur_state != state,
  1102. "pipe %c assertion failure (expected %s, current %s)\n",
  1103. pipe_name(pipe), state_string(state), state_string(cur_state));
  1104. }
  1105. static void assert_plane(struct drm_i915_private *dev_priv,
  1106. enum plane plane, bool state)
  1107. {
  1108. int reg;
  1109. u32 val;
  1110. bool cur_state;
  1111. reg = DSPCNTR(plane);
  1112. val = I915_READ(reg);
  1113. cur_state = !!(val & DISPLAY_PLANE_ENABLE);
  1114. WARN(cur_state != state,
  1115. "plane %c assertion failure (expected %s, current %s)\n",
  1116. plane_name(plane), state_string(state), state_string(cur_state));
  1117. }
  1118. #define assert_plane_enabled(d, p) assert_plane(d, p, true)
  1119. #define assert_plane_disabled(d, p) assert_plane(d, p, false)
  1120. static void assert_planes_disabled(struct drm_i915_private *dev_priv,
  1121. enum pipe pipe)
  1122. {
  1123. int reg, i;
  1124. u32 val;
  1125. int cur_pipe;
  1126. /* Planes are fixed to pipes on ILK+ */
  1127. if (HAS_PCH_SPLIT(dev_priv->dev)) {
  1128. reg = DSPCNTR(pipe);
  1129. val = I915_READ(reg);
  1130. WARN((val & DISPLAY_PLANE_ENABLE),
  1131. "plane %c assertion failure, should be disabled but not\n",
  1132. plane_name(pipe));
  1133. return;
  1134. }
  1135. /* Need to check both planes against the pipe */
  1136. for (i = 0; i < 2; i++) {
  1137. reg = DSPCNTR(i);
  1138. val = I915_READ(reg);
  1139. cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >>
  1140. DISPPLANE_SEL_PIPE_SHIFT;
  1141. WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe,
  1142. "plane %c assertion failure, should be off on pipe %c but is still active\n",
  1143. plane_name(i), pipe_name(pipe));
  1144. }
  1145. }
  1146. static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv)
  1147. {
  1148. u32 val;
  1149. bool enabled;
  1150. if (HAS_PCH_LPT(dev_priv->dev)) {
  1151. DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n");
  1152. return;
  1153. }
  1154. val = I915_READ(PCH_DREF_CONTROL);
  1155. enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK |
  1156. DREF_SUPERSPREAD_SOURCE_MASK));
  1157. WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n");
  1158. }
  1159. static void assert_transcoder_disabled(struct drm_i915_private *dev_priv,
  1160. enum pipe pipe)
  1161. {
  1162. int reg;
  1163. u32 val;
  1164. bool enabled;
  1165. reg = TRANSCONF(pipe);
  1166. val = I915_READ(reg);
  1167. enabled = !!(val & TRANS_ENABLE);
  1168. WARN(enabled,
  1169. "transcoder assertion failed, should be off on pipe %c but is still active\n",
  1170. pipe_name(pipe));
  1171. }
  1172. static bool dp_pipe_enabled(struct drm_i915_private *dev_priv,
  1173. enum pipe pipe, u32 port_sel, u32 val)
  1174. {
  1175. if ((val & DP_PORT_EN) == 0)
  1176. return false;
  1177. if (HAS_PCH_CPT(dev_priv->dev)) {
  1178. u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe);
  1179. u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg);
  1180. if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel)
  1181. return false;
  1182. } else {
  1183. if ((val & DP_PIPE_MASK) != (pipe << 30))
  1184. return false;
  1185. }
  1186. return true;
  1187. }
  1188. static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv,
  1189. enum pipe pipe, u32 val)
  1190. {
  1191. if ((val & PORT_ENABLE) == 0)
  1192. return false;
  1193. if (HAS_PCH_CPT(dev_priv->dev)) {
  1194. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1195. return false;
  1196. } else {
  1197. if ((val & TRANSCODER_MASK) != TRANSCODER(pipe))
  1198. return false;
  1199. }
  1200. return true;
  1201. }
  1202. static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv,
  1203. enum pipe pipe, u32 val)
  1204. {
  1205. if ((val & LVDS_PORT_EN) == 0)
  1206. return false;
  1207. if (HAS_PCH_CPT(dev_priv->dev)) {
  1208. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1209. return false;
  1210. } else {
  1211. if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe))
  1212. return false;
  1213. }
  1214. return true;
  1215. }
  1216. static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv,
  1217. enum pipe pipe, u32 val)
  1218. {
  1219. if ((val & ADPA_DAC_ENABLE) == 0)
  1220. return false;
  1221. if (HAS_PCH_CPT(dev_priv->dev)) {
  1222. if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe))
  1223. return false;
  1224. } else {
  1225. if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe))
  1226. return false;
  1227. }
  1228. return true;
  1229. }
  1230. static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv,
  1231. enum pipe pipe, int reg, u32 port_sel)
  1232. {
  1233. u32 val = I915_READ(reg);
  1234. WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val),
  1235. "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n",
  1236. reg, pipe_name(pipe));
  1237. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0
  1238. && (val & DP_PIPEB_SELECT),
  1239. "IBX PCH dp port still using transcoder B\n");
  1240. }
  1241. static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv,
  1242. enum pipe pipe, int reg)
  1243. {
  1244. u32 val = I915_READ(reg);
  1245. WARN(hdmi_pipe_enabled(dev_priv, pipe, val),
  1246. "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n",
  1247. reg, pipe_name(pipe));
  1248. WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0
  1249. && (val & SDVO_PIPE_B_SELECT),
  1250. "IBX PCH hdmi port still using transcoder B\n");
  1251. }
  1252. static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv,
  1253. enum pipe pipe)
  1254. {
  1255. int reg;
  1256. u32 val;
  1257. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B);
  1258. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C);
  1259. assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D);
  1260. reg = PCH_ADPA;
  1261. val = I915_READ(reg);
  1262. WARN(adpa_pipe_enabled(dev_priv, pipe, val),
  1263. "PCH VGA enabled on transcoder %c, should be disabled\n",
  1264. pipe_name(pipe));
  1265. reg = PCH_LVDS;
  1266. val = I915_READ(reg);
  1267. WARN(lvds_pipe_enabled(dev_priv, pipe, val),
  1268. "PCH LVDS enabled on transcoder %c, should be disabled\n",
  1269. pipe_name(pipe));
  1270. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB);
  1271. assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC);
  1272. assert_pch_hdmi_disabled(dev_priv, pipe, HDMID);
  1273. }
  1274. /**
  1275. * intel_enable_pll - enable a PLL
  1276. * @dev_priv: i915 private structure
  1277. * @pipe: pipe PLL to enable
  1278. *
  1279. * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to
  1280. * make sure the PLL reg is writable first though, since the panel write
  1281. * protect mechanism may be enabled.
  1282. *
  1283. * Note! This is for pre-ILK only.
  1284. *
  1285. * Unfortunately needed by dvo_ns2501 since the dvo depends on it running.
  1286. */
  1287. static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1288. {
  1289. int reg;
  1290. u32 val;
  1291. /* No really, not for ILK+ */
  1292. BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5);
  1293. /* PLL is protected by panel, make sure we can write it */
  1294. if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev))
  1295. assert_panel_unlocked(dev_priv, pipe);
  1296. reg = DPLL(pipe);
  1297. val = I915_READ(reg);
  1298. val |= DPLL_VCO_ENABLE;
  1299. /* We do this three times for luck */
  1300. I915_WRITE(reg, val);
  1301. POSTING_READ(reg);
  1302. udelay(150); /* wait for warmup */
  1303. I915_WRITE(reg, val);
  1304. POSTING_READ(reg);
  1305. udelay(150); /* wait for warmup */
  1306. I915_WRITE(reg, val);
  1307. POSTING_READ(reg);
  1308. udelay(150); /* wait for warmup */
  1309. }
  1310. /**
  1311. * intel_disable_pll - disable a PLL
  1312. * @dev_priv: i915 private structure
  1313. * @pipe: pipe PLL to disable
  1314. *
  1315. * Disable the PLL for @pipe, making sure the pipe is off first.
  1316. *
  1317. * Note! This is for pre-ILK only.
  1318. */
  1319. static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe)
  1320. {
  1321. int reg;
  1322. u32 val;
  1323. /* Don't disable pipe A or pipe A PLLs if needed */
  1324. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1325. return;
  1326. /* Make sure the pipe isn't still relying on us */
  1327. assert_pipe_disabled(dev_priv, pipe);
  1328. reg = DPLL(pipe);
  1329. val = I915_READ(reg);
  1330. val &= ~DPLL_VCO_ENABLE;
  1331. I915_WRITE(reg, val);
  1332. POSTING_READ(reg);
  1333. }
  1334. /* SBI access */
  1335. static void
  1336. intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value,
  1337. enum intel_sbi_destination destination)
  1338. {
  1339. u32 tmp;
  1340. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  1341. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
  1342. 100)) {
  1343. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1344. return;
  1345. }
  1346. I915_WRITE(SBI_ADDR, (reg << 16));
  1347. I915_WRITE(SBI_DATA, value);
  1348. if (destination == SBI_ICLK)
  1349. tmp = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRWR;
  1350. else
  1351. tmp = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IOWR;
  1352. I915_WRITE(SBI_CTL_STAT, SBI_BUSY | tmp);
  1353. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
  1354. 100)) {
  1355. DRM_ERROR("timeout waiting for SBI to complete write transaction\n");
  1356. return;
  1357. }
  1358. }
  1359. static u32
  1360. intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg,
  1361. enum intel_sbi_destination destination)
  1362. {
  1363. u32 value = 0;
  1364. WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock));
  1365. if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0,
  1366. 100)) {
  1367. DRM_ERROR("timeout waiting for SBI to become ready\n");
  1368. return 0;
  1369. }
  1370. I915_WRITE(SBI_ADDR, (reg << 16));
  1371. if (destination == SBI_ICLK)
  1372. value = SBI_CTL_DEST_ICLK | SBI_CTL_OP_CRRD;
  1373. else
  1374. value = SBI_CTL_DEST_MPHY | SBI_CTL_OP_IORD;
  1375. I915_WRITE(SBI_CTL_STAT, value | SBI_BUSY);
  1376. if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0,
  1377. 100)) {
  1378. DRM_ERROR("timeout waiting for SBI to complete read transaction\n");
  1379. return 0;
  1380. }
  1381. return I915_READ(SBI_DATA);
  1382. }
  1383. /**
  1384. * ironlake_enable_pch_pll - enable PCH PLL
  1385. * @dev_priv: i915 private structure
  1386. * @pipe: pipe PLL to enable
  1387. *
  1388. * The PCH PLL needs to be enabled before the PCH transcoder, since it
  1389. * drives the transcoder clock.
  1390. */
  1391. static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc)
  1392. {
  1393. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1394. struct intel_pch_pll *pll;
  1395. int reg;
  1396. u32 val;
  1397. /* PCH PLLs only available on ILK, SNB and IVB */
  1398. BUG_ON(dev_priv->info->gen < 5);
  1399. pll = intel_crtc->pch_pll;
  1400. if (pll == NULL)
  1401. return;
  1402. if (WARN_ON(pll->refcount == 0))
  1403. return;
  1404. DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n",
  1405. pll->pll_reg, pll->active, pll->on,
  1406. intel_crtc->base.base.id);
  1407. /* PCH refclock must be enabled first */
  1408. assert_pch_refclk_enabled(dev_priv);
  1409. if (pll->active++ && pll->on) {
  1410. assert_pch_pll_enabled(dev_priv, pll, NULL);
  1411. return;
  1412. }
  1413. DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg);
  1414. reg = pll->pll_reg;
  1415. val = I915_READ(reg);
  1416. val |= DPLL_VCO_ENABLE;
  1417. I915_WRITE(reg, val);
  1418. POSTING_READ(reg);
  1419. udelay(200);
  1420. pll->on = true;
  1421. }
  1422. static void intel_disable_pch_pll(struct intel_crtc *intel_crtc)
  1423. {
  1424. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  1425. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  1426. int reg;
  1427. u32 val;
  1428. /* PCH only available on ILK+ */
  1429. BUG_ON(dev_priv->info->gen < 5);
  1430. if (pll == NULL)
  1431. return;
  1432. if (WARN_ON(pll->refcount == 0))
  1433. return;
  1434. DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n",
  1435. pll->pll_reg, pll->active, pll->on,
  1436. intel_crtc->base.base.id);
  1437. if (WARN_ON(pll->active == 0)) {
  1438. assert_pch_pll_disabled(dev_priv, pll, NULL);
  1439. return;
  1440. }
  1441. if (--pll->active) {
  1442. assert_pch_pll_enabled(dev_priv, pll, NULL);
  1443. return;
  1444. }
  1445. DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg);
  1446. /* Make sure transcoder isn't still depending on us */
  1447. assert_transcoder_disabled(dev_priv, intel_crtc->pipe);
  1448. reg = pll->pll_reg;
  1449. val = I915_READ(reg);
  1450. val &= ~DPLL_VCO_ENABLE;
  1451. I915_WRITE(reg, val);
  1452. POSTING_READ(reg);
  1453. udelay(200);
  1454. pll->on = false;
  1455. }
  1456. static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1457. enum pipe pipe)
  1458. {
  1459. struct drm_device *dev = dev_priv->dev;
  1460. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  1461. uint32_t reg, val, pipeconf_val;
  1462. /* PCH only available on ILK+ */
  1463. BUG_ON(dev_priv->info->gen < 5);
  1464. /* Make sure PCH DPLL is enabled */
  1465. assert_pch_pll_enabled(dev_priv,
  1466. to_intel_crtc(crtc)->pch_pll,
  1467. to_intel_crtc(crtc));
  1468. /* FDI must be feeding us bits for PCH ports */
  1469. assert_fdi_tx_enabled(dev_priv, pipe);
  1470. assert_fdi_rx_enabled(dev_priv, pipe);
  1471. if (HAS_PCH_CPT(dev)) {
  1472. /* Workaround: Set the timing override bit before enabling the
  1473. * pch transcoder. */
  1474. reg = TRANS_CHICKEN2(pipe);
  1475. val = I915_READ(reg);
  1476. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1477. I915_WRITE(reg, val);
  1478. }
  1479. reg = TRANSCONF(pipe);
  1480. val = I915_READ(reg);
  1481. pipeconf_val = I915_READ(PIPECONF(pipe));
  1482. if (HAS_PCH_IBX(dev_priv->dev)) {
  1483. /*
  1484. * make the BPC in transcoder be consistent with
  1485. * that in pipeconf reg.
  1486. */
  1487. val &= ~PIPECONF_BPC_MASK;
  1488. val |= pipeconf_val & PIPECONF_BPC_MASK;
  1489. }
  1490. val &= ~TRANS_INTERLACE_MASK;
  1491. if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK)
  1492. if (HAS_PCH_IBX(dev_priv->dev) &&
  1493. intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO))
  1494. val |= TRANS_LEGACY_INTERLACED_ILK;
  1495. else
  1496. val |= TRANS_INTERLACED;
  1497. else
  1498. val |= TRANS_PROGRESSIVE;
  1499. I915_WRITE(reg, val | TRANS_ENABLE);
  1500. if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100))
  1501. DRM_ERROR("failed to enable transcoder %d\n", pipe);
  1502. }
  1503. static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv,
  1504. enum transcoder cpu_transcoder)
  1505. {
  1506. u32 val, pipeconf_val;
  1507. /* PCH only available on ILK+ */
  1508. BUG_ON(dev_priv->info->gen < 5);
  1509. /* FDI must be feeding us bits for PCH ports */
  1510. assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder);
  1511. assert_fdi_rx_enabled(dev_priv, TRANSCODER_A);
  1512. /* Workaround: set timing override bit. */
  1513. val = I915_READ(_TRANSA_CHICKEN2);
  1514. val |= TRANS_CHICKEN2_TIMING_OVERRIDE;
  1515. I915_WRITE(_TRANSA_CHICKEN2, val);
  1516. val = TRANS_ENABLE;
  1517. pipeconf_val = I915_READ(PIPECONF(cpu_transcoder));
  1518. if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) ==
  1519. PIPECONF_INTERLACED_ILK)
  1520. val |= TRANS_INTERLACED;
  1521. else
  1522. val |= TRANS_PROGRESSIVE;
  1523. I915_WRITE(TRANSCONF(TRANSCODER_A), val);
  1524. if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100))
  1525. DRM_ERROR("Failed to enable PCH transcoder\n");
  1526. }
  1527. static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv,
  1528. enum pipe pipe)
  1529. {
  1530. struct drm_device *dev = dev_priv->dev;
  1531. uint32_t reg, val;
  1532. /* FDI relies on the transcoder */
  1533. assert_fdi_tx_disabled(dev_priv, pipe);
  1534. assert_fdi_rx_disabled(dev_priv, pipe);
  1535. /* Ports must be off as well */
  1536. assert_pch_ports_disabled(dev_priv, pipe);
  1537. reg = TRANSCONF(pipe);
  1538. val = I915_READ(reg);
  1539. val &= ~TRANS_ENABLE;
  1540. I915_WRITE(reg, val);
  1541. /* wait for PCH transcoder off, transcoder state */
  1542. if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50))
  1543. DRM_ERROR("failed to disable transcoder %d\n", pipe);
  1544. if (!HAS_PCH_IBX(dev)) {
  1545. /* Workaround: Clear the timing override chicken bit again. */
  1546. reg = TRANS_CHICKEN2(pipe);
  1547. val = I915_READ(reg);
  1548. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1549. I915_WRITE(reg, val);
  1550. }
  1551. }
  1552. static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv)
  1553. {
  1554. u32 val;
  1555. val = I915_READ(_TRANSACONF);
  1556. val &= ~TRANS_ENABLE;
  1557. I915_WRITE(_TRANSACONF, val);
  1558. /* wait for PCH transcoder off, transcoder state */
  1559. if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50))
  1560. DRM_ERROR("Failed to disable PCH transcoder\n");
  1561. /* Workaround: clear timing override bit. */
  1562. val = I915_READ(_TRANSA_CHICKEN2);
  1563. val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE;
  1564. I915_WRITE(_TRANSA_CHICKEN2, val);
  1565. }
  1566. /**
  1567. * intel_enable_pipe - enable a pipe, asserting requirements
  1568. * @dev_priv: i915 private structure
  1569. * @pipe: pipe to enable
  1570. * @pch_port: on ILK+, is this pipe driving a PCH port or not
  1571. *
  1572. * Enable @pipe, making sure that various hardware specific requirements
  1573. * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc.
  1574. *
  1575. * @pipe should be %PIPE_A or %PIPE_B.
  1576. *
  1577. * Will wait until the pipe is actually running (i.e. first vblank) before
  1578. * returning.
  1579. */
  1580. static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe,
  1581. bool pch_port)
  1582. {
  1583. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1584. pipe);
  1585. enum pipe pch_transcoder;
  1586. int reg;
  1587. u32 val;
  1588. if (HAS_PCH_LPT(dev_priv->dev))
  1589. pch_transcoder = TRANSCODER_A;
  1590. else
  1591. pch_transcoder = pipe;
  1592. /*
  1593. * A pipe without a PLL won't actually be able to drive bits from
  1594. * a plane. On ILK+ the pipe PLLs are integrated, so we don't
  1595. * need the check.
  1596. */
  1597. if (!HAS_PCH_SPLIT(dev_priv->dev))
  1598. assert_pll_enabled(dev_priv, pipe);
  1599. else {
  1600. if (pch_port) {
  1601. /* if driving the PCH, we need FDI enabled */
  1602. assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder);
  1603. assert_fdi_tx_pll_enabled(dev_priv,
  1604. (enum pipe) cpu_transcoder);
  1605. }
  1606. /* FIXME: assert CPU port conditions for SNB+ */
  1607. }
  1608. reg = PIPECONF(cpu_transcoder);
  1609. val = I915_READ(reg);
  1610. if (val & PIPECONF_ENABLE)
  1611. return;
  1612. I915_WRITE(reg, val | PIPECONF_ENABLE);
  1613. intel_wait_for_vblank(dev_priv->dev, pipe);
  1614. }
  1615. /**
  1616. * intel_disable_pipe - disable a pipe, asserting requirements
  1617. * @dev_priv: i915 private structure
  1618. * @pipe: pipe to disable
  1619. *
  1620. * Disable @pipe, making sure that various hardware specific requirements
  1621. * are met, if applicable, e.g. plane disabled, panel fitter off, etc.
  1622. *
  1623. * @pipe should be %PIPE_A or %PIPE_B.
  1624. *
  1625. * Will wait until the pipe has shut down before returning.
  1626. */
  1627. static void intel_disable_pipe(struct drm_i915_private *dev_priv,
  1628. enum pipe pipe)
  1629. {
  1630. enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
  1631. pipe);
  1632. int reg;
  1633. u32 val;
  1634. /*
  1635. * Make sure planes won't keep trying to pump pixels to us,
  1636. * or we might hang the display.
  1637. */
  1638. assert_planes_disabled(dev_priv, pipe);
  1639. /* Don't disable pipe A or pipe A PLLs if needed */
  1640. if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE))
  1641. return;
  1642. reg = PIPECONF(cpu_transcoder);
  1643. val = I915_READ(reg);
  1644. if ((val & PIPECONF_ENABLE) == 0)
  1645. return;
  1646. I915_WRITE(reg, val & ~PIPECONF_ENABLE);
  1647. intel_wait_for_pipe_off(dev_priv->dev, pipe);
  1648. }
  1649. /*
  1650. * Plane regs are double buffered, going from enabled->disabled needs a
  1651. * trigger in order to latch. The display address reg provides this.
  1652. */
  1653. void intel_flush_display_plane(struct drm_i915_private *dev_priv,
  1654. enum plane plane)
  1655. {
  1656. if (dev_priv->info->gen >= 4)
  1657. I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane)));
  1658. else
  1659. I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane)));
  1660. }
  1661. /**
  1662. * intel_enable_plane - enable a display plane on a given pipe
  1663. * @dev_priv: i915 private structure
  1664. * @plane: plane to enable
  1665. * @pipe: pipe being fed
  1666. *
  1667. * Enable @plane on @pipe, making sure that @pipe is running first.
  1668. */
  1669. static void intel_enable_plane(struct drm_i915_private *dev_priv,
  1670. enum plane plane, enum pipe pipe)
  1671. {
  1672. int reg;
  1673. u32 val;
  1674. /* If the pipe isn't enabled, we can't pump pixels and may hang */
  1675. assert_pipe_enabled(dev_priv, pipe);
  1676. reg = DSPCNTR(plane);
  1677. val = I915_READ(reg);
  1678. if (val & DISPLAY_PLANE_ENABLE)
  1679. return;
  1680. I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE);
  1681. intel_flush_display_plane(dev_priv, plane);
  1682. intel_wait_for_vblank(dev_priv->dev, pipe);
  1683. }
  1684. /**
  1685. * intel_disable_plane - disable a display plane
  1686. * @dev_priv: i915 private structure
  1687. * @plane: plane to disable
  1688. * @pipe: pipe consuming the data
  1689. *
  1690. * Disable @plane; should be an independent operation.
  1691. */
  1692. static void intel_disable_plane(struct drm_i915_private *dev_priv,
  1693. enum plane plane, enum pipe pipe)
  1694. {
  1695. int reg;
  1696. u32 val;
  1697. reg = DSPCNTR(plane);
  1698. val = I915_READ(reg);
  1699. if ((val & DISPLAY_PLANE_ENABLE) == 0)
  1700. return;
  1701. I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE);
  1702. intel_flush_display_plane(dev_priv, plane);
  1703. intel_wait_for_vblank(dev_priv->dev, pipe);
  1704. }
  1705. int
  1706. intel_pin_and_fence_fb_obj(struct drm_device *dev,
  1707. struct drm_i915_gem_object *obj,
  1708. struct intel_ring_buffer *pipelined)
  1709. {
  1710. struct drm_i915_private *dev_priv = dev->dev_private;
  1711. u32 alignment;
  1712. int ret;
  1713. switch (obj->tiling_mode) {
  1714. case I915_TILING_NONE:
  1715. if (IS_BROADWATER(dev) || IS_CRESTLINE(dev))
  1716. alignment = 128 * 1024;
  1717. else if (INTEL_INFO(dev)->gen >= 4)
  1718. alignment = 4 * 1024;
  1719. else
  1720. alignment = 64 * 1024;
  1721. break;
  1722. case I915_TILING_X:
  1723. /* pin() will align the object as required by fence */
  1724. alignment = 0;
  1725. break;
  1726. case I915_TILING_Y:
  1727. /* FIXME: Is this true? */
  1728. DRM_ERROR("Y tiled not allowed for scan out buffers\n");
  1729. return -EINVAL;
  1730. default:
  1731. BUG();
  1732. }
  1733. dev_priv->mm.interruptible = false;
  1734. ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined);
  1735. if (ret)
  1736. goto err_interruptible;
  1737. /* Install a fence for tiled scan-out. Pre-i965 always needs a
  1738. * fence, whereas 965+ only requires a fence if using
  1739. * framebuffer compression. For simplicity, we always install
  1740. * a fence as the cost is not that onerous.
  1741. */
  1742. ret = i915_gem_object_get_fence(obj);
  1743. if (ret)
  1744. goto err_unpin;
  1745. i915_gem_object_pin_fence(obj);
  1746. dev_priv->mm.interruptible = true;
  1747. return 0;
  1748. err_unpin:
  1749. i915_gem_object_unpin(obj);
  1750. err_interruptible:
  1751. dev_priv->mm.interruptible = true;
  1752. return ret;
  1753. }
  1754. void intel_unpin_fb_obj(struct drm_i915_gem_object *obj)
  1755. {
  1756. i915_gem_object_unpin_fence(obj);
  1757. i915_gem_object_unpin(obj);
  1758. }
  1759. /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel
  1760. * is assumed to be a power-of-two. */
  1761. unsigned long intel_gen4_compute_offset_xtiled(int *x, int *y,
  1762. unsigned int bpp,
  1763. unsigned int pitch)
  1764. {
  1765. int tile_rows, tiles;
  1766. tile_rows = *y / 8;
  1767. *y %= 8;
  1768. tiles = *x / (512/bpp);
  1769. *x %= 512/bpp;
  1770. return tile_rows * pitch * 8 + tiles * 4096;
  1771. }
  1772. static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1773. int x, int y)
  1774. {
  1775. struct drm_device *dev = crtc->dev;
  1776. struct drm_i915_private *dev_priv = dev->dev_private;
  1777. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1778. struct intel_framebuffer *intel_fb;
  1779. struct drm_i915_gem_object *obj;
  1780. int plane = intel_crtc->plane;
  1781. unsigned long linear_offset;
  1782. u32 dspcntr;
  1783. u32 reg;
  1784. switch (plane) {
  1785. case 0:
  1786. case 1:
  1787. break;
  1788. default:
  1789. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1790. return -EINVAL;
  1791. }
  1792. intel_fb = to_intel_framebuffer(fb);
  1793. obj = intel_fb->obj;
  1794. reg = DSPCNTR(plane);
  1795. dspcntr = I915_READ(reg);
  1796. /* Mask out pixel format bits in case we change it */
  1797. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1798. switch (fb->pixel_format) {
  1799. case DRM_FORMAT_C8:
  1800. dspcntr |= DISPPLANE_8BPP;
  1801. break;
  1802. case DRM_FORMAT_XRGB1555:
  1803. case DRM_FORMAT_ARGB1555:
  1804. dspcntr |= DISPPLANE_BGRX555;
  1805. break;
  1806. case DRM_FORMAT_RGB565:
  1807. dspcntr |= DISPPLANE_BGRX565;
  1808. break;
  1809. case DRM_FORMAT_XRGB8888:
  1810. case DRM_FORMAT_ARGB8888:
  1811. dspcntr |= DISPPLANE_BGRX888;
  1812. break;
  1813. case DRM_FORMAT_XBGR8888:
  1814. case DRM_FORMAT_ABGR8888:
  1815. dspcntr |= DISPPLANE_RGBX888;
  1816. break;
  1817. case DRM_FORMAT_XRGB2101010:
  1818. case DRM_FORMAT_ARGB2101010:
  1819. dspcntr |= DISPPLANE_BGRX101010;
  1820. break;
  1821. case DRM_FORMAT_XBGR2101010:
  1822. case DRM_FORMAT_ABGR2101010:
  1823. dspcntr |= DISPPLANE_RGBX101010;
  1824. break;
  1825. default:
  1826. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1827. return -EINVAL;
  1828. }
  1829. if (INTEL_INFO(dev)->gen >= 4) {
  1830. if (obj->tiling_mode != I915_TILING_NONE)
  1831. dspcntr |= DISPPLANE_TILED;
  1832. else
  1833. dspcntr &= ~DISPPLANE_TILED;
  1834. }
  1835. I915_WRITE(reg, dspcntr);
  1836. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1837. if (INTEL_INFO(dev)->gen >= 4) {
  1838. intel_crtc->dspaddr_offset =
  1839. intel_gen4_compute_offset_xtiled(&x, &y,
  1840. fb->bits_per_pixel / 8,
  1841. fb->pitches[0]);
  1842. linear_offset -= intel_crtc->dspaddr_offset;
  1843. } else {
  1844. intel_crtc->dspaddr_offset = linear_offset;
  1845. }
  1846. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1847. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1848. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1849. if (INTEL_INFO(dev)->gen >= 4) {
  1850. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1851. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1852. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1853. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1854. } else
  1855. I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset);
  1856. POSTING_READ(reg);
  1857. return 0;
  1858. }
  1859. static int ironlake_update_plane(struct drm_crtc *crtc,
  1860. struct drm_framebuffer *fb, int x, int y)
  1861. {
  1862. struct drm_device *dev = crtc->dev;
  1863. struct drm_i915_private *dev_priv = dev->dev_private;
  1864. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1865. struct intel_framebuffer *intel_fb;
  1866. struct drm_i915_gem_object *obj;
  1867. int plane = intel_crtc->plane;
  1868. unsigned long linear_offset;
  1869. u32 dspcntr;
  1870. u32 reg;
  1871. switch (plane) {
  1872. case 0:
  1873. case 1:
  1874. case 2:
  1875. break;
  1876. default:
  1877. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1878. return -EINVAL;
  1879. }
  1880. intel_fb = to_intel_framebuffer(fb);
  1881. obj = intel_fb->obj;
  1882. reg = DSPCNTR(plane);
  1883. dspcntr = I915_READ(reg);
  1884. /* Mask out pixel format bits in case we change it */
  1885. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1886. switch (fb->pixel_format) {
  1887. case DRM_FORMAT_C8:
  1888. dspcntr |= DISPPLANE_8BPP;
  1889. break;
  1890. case DRM_FORMAT_RGB565:
  1891. dspcntr |= DISPPLANE_BGRX565;
  1892. break;
  1893. case DRM_FORMAT_XRGB8888:
  1894. case DRM_FORMAT_ARGB8888:
  1895. dspcntr |= DISPPLANE_BGRX888;
  1896. break;
  1897. case DRM_FORMAT_XBGR8888:
  1898. case DRM_FORMAT_ABGR8888:
  1899. dspcntr |= DISPPLANE_RGBX888;
  1900. break;
  1901. case DRM_FORMAT_XRGB2101010:
  1902. case DRM_FORMAT_ARGB2101010:
  1903. dspcntr |= DISPPLANE_BGRX101010;
  1904. break;
  1905. case DRM_FORMAT_XBGR2101010:
  1906. case DRM_FORMAT_ABGR2101010:
  1907. dspcntr |= DISPPLANE_RGBX101010;
  1908. break;
  1909. default:
  1910. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1911. return -EINVAL;
  1912. }
  1913. if (obj->tiling_mode != I915_TILING_NONE)
  1914. dspcntr |= DISPPLANE_TILED;
  1915. else
  1916. dspcntr &= ~DISPPLANE_TILED;
  1917. /* must disable */
  1918. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1919. I915_WRITE(reg, dspcntr);
  1920. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1921. intel_crtc->dspaddr_offset =
  1922. intel_gen4_compute_offset_xtiled(&x, &y,
  1923. fb->bits_per_pixel / 8,
  1924. fb->pitches[0]);
  1925. linear_offset -= intel_crtc->dspaddr_offset;
  1926. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1927. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1928. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1929. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1930. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1931. if (IS_HASWELL(dev)) {
  1932. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  1933. } else {
  1934. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1935. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1936. }
  1937. POSTING_READ(reg);
  1938. return 0;
  1939. }
  1940. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1941. static int
  1942. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1943. int x, int y, enum mode_set_atomic state)
  1944. {
  1945. struct drm_device *dev = crtc->dev;
  1946. struct drm_i915_private *dev_priv = dev->dev_private;
  1947. if (dev_priv->display.disable_fbc)
  1948. dev_priv->display.disable_fbc(dev);
  1949. intel_increase_pllclock(crtc);
  1950. return dev_priv->display.update_plane(crtc, fb, x, y);
  1951. }
  1952. static int
  1953. intel_finish_fb(struct drm_framebuffer *old_fb)
  1954. {
  1955. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1956. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1957. bool was_interruptible = dev_priv->mm.interruptible;
  1958. int ret;
  1959. /* Big Hammer, we also need to ensure that any pending
  1960. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1961. * current scanout is retired before unpinning the old
  1962. * framebuffer.
  1963. *
  1964. * This should only fail upon a hung GPU, in which case we
  1965. * can safely continue.
  1966. */
  1967. dev_priv->mm.interruptible = false;
  1968. ret = i915_gem_object_finish_gpu(obj);
  1969. dev_priv->mm.interruptible = was_interruptible;
  1970. return ret;
  1971. }
  1972. static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
  1973. {
  1974. struct drm_device *dev = crtc->dev;
  1975. struct drm_i915_master_private *master_priv;
  1976. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1977. if (!dev->primary->master)
  1978. return;
  1979. master_priv = dev->primary->master->driver_priv;
  1980. if (!master_priv->sarea_priv)
  1981. return;
  1982. switch (intel_crtc->pipe) {
  1983. case 0:
  1984. master_priv->sarea_priv->pipeA_x = x;
  1985. master_priv->sarea_priv->pipeA_y = y;
  1986. break;
  1987. case 1:
  1988. master_priv->sarea_priv->pipeB_x = x;
  1989. master_priv->sarea_priv->pipeB_y = y;
  1990. break;
  1991. default:
  1992. break;
  1993. }
  1994. }
  1995. static int
  1996. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  1997. struct drm_framebuffer *fb)
  1998. {
  1999. struct drm_device *dev = crtc->dev;
  2000. struct drm_i915_private *dev_priv = dev->dev_private;
  2001. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2002. struct drm_framebuffer *old_fb;
  2003. int ret;
  2004. /* no fb bound */
  2005. if (!fb) {
  2006. DRM_ERROR("No FB bound\n");
  2007. return 0;
  2008. }
  2009. if(intel_crtc->plane > dev_priv->num_pipe) {
  2010. DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
  2011. intel_crtc->plane,
  2012. dev_priv->num_pipe);
  2013. return -EINVAL;
  2014. }
  2015. mutex_lock(&dev->struct_mutex);
  2016. ret = intel_pin_and_fence_fb_obj(dev,
  2017. to_intel_framebuffer(fb)->obj,
  2018. NULL);
  2019. if (ret != 0) {
  2020. mutex_unlock(&dev->struct_mutex);
  2021. DRM_ERROR("pin & fence failed\n");
  2022. return ret;
  2023. }
  2024. if (crtc->fb)
  2025. intel_finish_fb(crtc->fb);
  2026. ret = dev_priv->display.update_plane(crtc, fb, x, y);
  2027. if (ret) {
  2028. intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
  2029. mutex_unlock(&dev->struct_mutex);
  2030. DRM_ERROR("failed to update base address\n");
  2031. return ret;
  2032. }
  2033. old_fb = crtc->fb;
  2034. crtc->fb = fb;
  2035. crtc->x = x;
  2036. crtc->y = y;
  2037. if (old_fb) {
  2038. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2039. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2040. }
  2041. intel_update_fbc(dev);
  2042. mutex_unlock(&dev->struct_mutex);
  2043. intel_crtc_update_sarea_pos(crtc, x, y);
  2044. return 0;
  2045. }
  2046. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2047. {
  2048. struct drm_device *dev = crtc->dev;
  2049. struct drm_i915_private *dev_priv = dev->dev_private;
  2050. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2051. int pipe = intel_crtc->pipe;
  2052. u32 reg, temp;
  2053. /* enable normal train */
  2054. reg = FDI_TX_CTL(pipe);
  2055. temp = I915_READ(reg);
  2056. if (IS_IVYBRIDGE(dev)) {
  2057. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2058. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2059. } else {
  2060. temp &= ~FDI_LINK_TRAIN_NONE;
  2061. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2062. }
  2063. I915_WRITE(reg, temp);
  2064. reg = FDI_RX_CTL(pipe);
  2065. temp = I915_READ(reg);
  2066. if (HAS_PCH_CPT(dev)) {
  2067. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2068. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2069. } else {
  2070. temp &= ~FDI_LINK_TRAIN_NONE;
  2071. temp |= FDI_LINK_TRAIN_NONE;
  2072. }
  2073. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2074. /* wait one idle pattern time */
  2075. POSTING_READ(reg);
  2076. udelay(1000);
  2077. /* IVB wants error correction enabled */
  2078. if (IS_IVYBRIDGE(dev))
  2079. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2080. FDI_FE_ERRC_ENABLE);
  2081. }
  2082. static void ivb_modeset_global_resources(struct drm_device *dev)
  2083. {
  2084. struct drm_i915_private *dev_priv = dev->dev_private;
  2085. struct intel_crtc *pipe_B_crtc =
  2086. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2087. struct intel_crtc *pipe_C_crtc =
  2088. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2089. uint32_t temp;
  2090. /* When everything is off disable fdi C so that we could enable fdi B
  2091. * with all lanes. XXX: This misses the case where a pipe is not using
  2092. * any pch resources and so doesn't need any fdi lanes. */
  2093. if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
  2094. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2095. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2096. temp = I915_READ(SOUTH_CHICKEN1);
  2097. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2098. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2099. I915_WRITE(SOUTH_CHICKEN1, temp);
  2100. }
  2101. }
  2102. /* The FDI link training functions for ILK/Ibexpeak. */
  2103. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2104. {
  2105. struct drm_device *dev = crtc->dev;
  2106. struct drm_i915_private *dev_priv = dev->dev_private;
  2107. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2108. int pipe = intel_crtc->pipe;
  2109. int plane = intel_crtc->plane;
  2110. u32 reg, temp, tries;
  2111. /* FDI needs bits from pipe & plane first */
  2112. assert_pipe_enabled(dev_priv, pipe);
  2113. assert_plane_enabled(dev_priv, plane);
  2114. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2115. for train result */
  2116. reg = FDI_RX_IMR(pipe);
  2117. temp = I915_READ(reg);
  2118. temp &= ~FDI_RX_SYMBOL_LOCK;
  2119. temp &= ~FDI_RX_BIT_LOCK;
  2120. I915_WRITE(reg, temp);
  2121. I915_READ(reg);
  2122. udelay(150);
  2123. /* enable CPU FDI TX and PCH FDI RX */
  2124. reg = FDI_TX_CTL(pipe);
  2125. temp = I915_READ(reg);
  2126. temp &= ~(7 << 19);
  2127. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2128. temp &= ~FDI_LINK_TRAIN_NONE;
  2129. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2130. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2131. reg = FDI_RX_CTL(pipe);
  2132. temp = I915_READ(reg);
  2133. temp &= ~FDI_LINK_TRAIN_NONE;
  2134. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2135. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2136. POSTING_READ(reg);
  2137. udelay(150);
  2138. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2139. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2140. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2141. FDI_RX_PHASE_SYNC_POINTER_EN);
  2142. reg = FDI_RX_IIR(pipe);
  2143. for (tries = 0; tries < 5; tries++) {
  2144. temp = I915_READ(reg);
  2145. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2146. if ((temp & FDI_RX_BIT_LOCK)) {
  2147. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2148. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2149. break;
  2150. }
  2151. }
  2152. if (tries == 5)
  2153. DRM_ERROR("FDI train 1 fail!\n");
  2154. /* Train 2 */
  2155. reg = FDI_TX_CTL(pipe);
  2156. temp = I915_READ(reg);
  2157. temp &= ~FDI_LINK_TRAIN_NONE;
  2158. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2159. I915_WRITE(reg, temp);
  2160. reg = FDI_RX_CTL(pipe);
  2161. temp = I915_READ(reg);
  2162. temp &= ~FDI_LINK_TRAIN_NONE;
  2163. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2164. I915_WRITE(reg, temp);
  2165. POSTING_READ(reg);
  2166. udelay(150);
  2167. reg = FDI_RX_IIR(pipe);
  2168. for (tries = 0; tries < 5; tries++) {
  2169. temp = I915_READ(reg);
  2170. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2171. if (temp & FDI_RX_SYMBOL_LOCK) {
  2172. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2173. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2174. break;
  2175. }
  2176. }
  2177. if (tries == 5)
  2178. DRM_ERROR("FDI train 2 fail!\n");
  2179. DRM_DEBUG_KMS("FDI train done\n");
  2180. }
  2181. static const int snb_b_fdi_train_param[] = {
  2182. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2183. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2184. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2185. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2186. };
  2187. /* The FDI link training functions for SNB/Cougarpoint. */
  2188. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2189. {
  2190. struct drm_device *dev = crtc->dev;
  2191. struct drm_i915_private *dev_priv = dev->dev_private;
  2192. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2193. int pipe = intel_crtc->pipe;
  2194. u32 reg, temp, i, retry;
  2195. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2196. for train result */
  2197. reg = FDI_RX_IMR(pipe);
  2198. temp = I915_READ(reg);
  2199. temp &= ~FDI_RX_SYMBOL_LOCK;
  2200. temp &= ~FDI_RX_BIT_LOCK;
  2201. I915_WRITE(reg, temp);
  2202. POSTING_READ(reg);
  2203. udelay(150);
  2204. /* enable CPU FDI TX and PCH FDI RX */
  2205. reg = FDI_TX_CTL(pipe);
  2206. temp = I915_READ(reg);
  2207. temp &= ~(7 << 19);
  2208. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2209. temp &= ~FDI_LINK_TRAIN_NONE;
  2210. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2211. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2212. /* SNB-B */
  2213. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2214. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2215. I915_WRITE(FDI_RX_MISC(pipe),
  2216. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2217. reg = FDI_RX_CTL(pipe);
  2218. temp = I915_READ(reg);
  2219. if (HAS_PCH_CPT(dev)) {
  2220. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2221. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2222. } else {
  2223. temp &= ~FDI_LINK_TRAIN_NONE;
  2224. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2225. }
  2226. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2227. POSTING_READ(reg);
  2228. udelay(150);
  2229. for (i = 0; i < 4; i++) {
  2230. reg = FDI_TX_CTL(pipe);
  2231. temp = I915_READ(reg);
  2232. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2233. temp |= snb_b_fdi_train_param[i];
  2234. I915_WRITE(reg, temp);
  2235. POSTING_READ(reg);
  2236. udelay(500);
  2237. for (retry = 0; retry < 5; retry++) {
  2238. reg = FDI_RX_IIR(pipe);
  2239. temp = I915_READ(reg);
  2240. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2241. if (temp & FDI_RX_BIT_LOCK) {
  2242. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2243. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2244. break;
  2245. }
  2246. udelay(50);
  2247. }
  2248. if (retry < 5)
  2249. break;
  2250. }
  2251. if (i == 4)
  2252. DRM_ERROR("FDI train 1 fail!\n");
  2253. /* Train 2 */
  2254. reg = FDI_TX_CTL(pipe);
  2255. temp = I915_READ(reg);
  2256. temp &= ~FDI_LINK_TRAIN_NONE;
  2257. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2258. if (IS_GEN6(dev)) {
  2259. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2260. /* SNB-B */
  2261. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2262. }
  2263. I915_WRITE(reg, temp);
  2264. reg = FDI_RX_CTL(pipe);
  2265. temp = I915_READ(reg);
  2266. if (HAS_PCH_CPT(dev)) {
  2267. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2268. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2269. } else {
  2270. temp &= ~FDI_LINK_TRAIN_NONE;
  2271. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2272. }
  2273. I915_WRITE(reg, temp);
  2274. POSTING_READ(reg);
  2275. udelay(150);
  2276. for (i = 0; i < 4; i++) {
  2277. reg = FDI_TX_CTL(pipe);
  2278. temp = I915_READ(reg);
  2279. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2280. temp |= snb_b_fdi_train_param[i];
  2281. I915_WRITE(reg, temp);
  2282. POSTING_READ(reg);
  2283. udelay(500);
  2284. for (retry = 0; retry < 5; retry++) {
  2285. reg = FDI_RX_IIR(pipe);
  2286. temp = I915_READ(reg);
  2287. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2288. if (temp & FDI_RX_SYMBOL_LOCK) {
  2289. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2290. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2291. break;
  2292. }
  2293. udelay(50);
  2294. }
  2295. if (retry < 5)
  2296. break;
  2297. }
  2298. if (i == 4)
  2299. DRM_ERROR("FDI train 2 fail!\n");
  2300. DRM_DEBUG_KMS("FDI train done.\n");
  2301. }
  2302. /* Manual link training for Ivy Bridge A0 parts */
  2303. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2304. {
  2305. struct drm_device *dev = crtc->dev;
  2306. struct drm_i915_private *dev_priv = dev->dev_private;
  2307. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2308. int pipe = intel_crtc->pipe;
  2309. u32 reg, temp, i;
  2310. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2311. for train result */
  2312. reg = FDI_RX_IMR(pipe);
  2313. temp = I915_READ(reg);
  2314. temp &= ~FDI_RX_SYMBOL_LOCK;
  2315. temp &= ~FDI_RX_BIT_LOCK;
  2316. I915_WRITE(reg, temp);
  2317. POSTING_READ(reg);
  2318. udelay(150);
  2319. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2320. I915_READ(FDI_RX_IIR(pipe)));
  2321. /* enable CPU FDI TX and PCH FDI RX */
  2322. reg = FDI_TX_CTL(pipe);
  2323. temp = I915_READ(reg);
  2324. temp &= ~(7 << 19);
  2325. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2326. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2327. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2328. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2329. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2330. temp |= FDI_COMPOSITE_SYNC;
  2331. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2332. I915_WRITE(FDI_RX_MISC(pipe),
  2333. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2334. reg = FDI_RX_CTL(pipe);
  2335. temp = I915_READ(reg);
  2336. temp &= ~FDI_LINK_TRAIN_AUTO;
  2337. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2338. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2339. temp |= FDI_COMPOSITE_SYNC;
  2340. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2341. POSTING_READ(reg);
  2342. udelay(150);
  2343. for (i = 0; i < 4; i++) {
  2344. reg = FDI_TX_CTL(pipe);
  2345. temp = I915_READ(reg);
  2346. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2347. temp |= snb_b_fdi_train_param[i];
  2348. I915_WRITE(reg, temp);
  2349. POSTING_READ(reg);
  2350. udelay(500);
  2351. reg = FDI_RX_IIR(pipe);
  2352. temp = I915_READ(reg);
  2353. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2354. if (temp & FDI_RX_BIT_LOCK ||
  2355. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2356. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2357. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
  2358. break;
  2359. }
  2360. }
  2361. if (i == 4)
  2362. DRM_ERROR("FDI train 1 fail!\n");
  2363. /* Train 2 */
  2364. reg = FDI_TX_CTL(pipe);
  2365. temp = I915_READ(reg);
  2366. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2367. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2368. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2369. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2370. I915_WRITE(reg, temp);
  2371. reg = FDI_RX_CTL(pipe);
  2372. temp = I915_READ(reg);
  2373. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2374. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2375. I915_WRITE(reg, temp);
  2376. POSTING_READ(reg);
  2377. udelay(150);
  2378. for (i = 0; i < 4; i++) {
  2379. reg = FDI_TX_CTL(pipe);
  2380. temp = I915_READ(reg);
  2381. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2382. temp |= snb_b_fdi_train_param[i];
  2383. I915_WRITE(reg, temp);
  2384. POSTING_READ(reg);
  2385. udelay(500);
  2386. reg = FDI_RX_IIR(pipe);
  2387. temp = I915_READ(reg);
  2388. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2389. if (temp & FDI_RX_SYMBOL_LOCK) {
  2390. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2391. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
  2392. break;
  2393. }
  2394. }
  2395. if (i == 4)
  2396. DRM_ERROR("FDI train 2 fail!\n");
  2397. DRM_DEBUG_KMS("FDI train done.\n");
  2398. }
  2399. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2400. {
  2401. struct drm_device *dev = intel_crtc->base.dev;
  2402. struct drm_i915_private *dev_priv = dev->dev_private;
  2403. int pipe = intel_crtc->pipe;
  2404. u32 reg, temp;
  2405. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2406. reg = FDI_RX_CTL(pipe);
  2407. temp = I915_READ(reg);
  2408. temp &= ~((0x7 << 19) | (0x7 << 16));
  2409. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2410. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2411. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2412. POSTING_READ(reg);
  2413. udelay(200);
  2414. /* Switch from Rawclk to PCDclk */
  2415. temp = I915_READ(reg);
  2416. I915_WRITE(reg, temp | FDI_PCDCLK);
  2417. POSTING_READ(reg);
  2418. udelay(200);
  2419. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2420. reg = FDI_TX_CTL(pipe);
  2421. temp = I915_READ(reg);
  2422. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2423. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2424. POSTING_READ(reg);
  2425. udelay(100);
  2426. }
  2427. }
  2428. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2429. {
  2430. struct drm_device *dev = intel_crtc->base.dev;
  2431. struct drm_i915_private *dev_priv = dev->dev_private;
  2432. int pipe = intel_crtc->pipe;
  2433. u32 reg, temp;
  2434. /* Switch from PCDclk to Rawclk */
  2435. reg = FDI_RX_CTL(pipe);
  2436. temp = I915_READ(reg);
  2437. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2438. /* Disable CPU FDI TX PLL */
  2439. reg = FDI_TX_CTL(pipe);
  2440. temp = I915_READ(reg);
  2441. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2442. POSTING_READ(reg);
  2443. udelay(100);
  2444. reg = FDI_RX_CTL(pipe);
  2445. temp = I915_READ(reg);
  2446. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2447. /* Wait for the clocks to turn off. */
  2448. POSTING_READ(reg);
  2449. udelay(100);
  2450. }
  2451. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2452. {
  2453. struct drm_device *dev = crtc->dev;
  2454. struct drm_i915_private *dev_priv = dev->dev_private;
  2455. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2456. int pipe = intel_crtc->pipe;
  2457. u32 reg, temp;
  2458. /* disable CPU FDI tx and PCH FDI rx */
  2459. reg = FDI_TX_CTL(pipe);
  2460. temp = I915_READ(reg);
  2461. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2462. POSTING_READ(reg);
  2463. reg = FDI_RX_CTL(pipe);
  2464. temp = I915_READ(reg);
  2465. temp &= ~(0x7 << 16);
  2466. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2467. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2468. POSTING_READ(reg);
  2469. udelay(100);
  2470. /* Ironlake workaround, disable clock pointer after downing FDI */
  2471. if (HAS_PCH_IBX(dev)) {
  2472. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2473. }
  2474. /* still set train pattern 1 */
  2475. reg = FDI_TX_CTL(pipe);
  2476. temp = I915_READ(reg);
  2477. temp &= ~FDI_LINK_TRAIN_NONE;
  2478. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2479. I915_WRITE(reg, temp);
  2480. reg = FDI_RX_CTL(pipe);
  2481. temp = I915_READ(reg);
  2482. if (HAS_PCH_CPT(dev)) {
  2483. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2484. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2485. } else {
  2486. temp &= ~FDI_LINK_TRAIN_NONE;
  2487. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2488. }
  2489. /* BPC in FDI rx is consistent with that in PIPECONF */
  2490. temp &= ~(0x07 << 16);
  2491. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2492. I915_WRITE(reg, temp);
  2493. POSTING_READ(reg);
  2494. udelay(100);
  2495. }
  2496. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2497. {
  2498. struct drm_device *dev = crtc->dev;
  2499. struct drm_i915_private *dev_priv = dev->dev_private;
  2500. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2501. unsigned long flags;
  2502. bool pending;
  2503. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2504. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2505. return false;
  2506. spin_lock_irqsave(&dev->event_lock, flags);
  2507. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2508. spin_unlock_irqrestore(&dev->event_lock, flags);
  2509. return pending;
  2510. }
  2511. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2512. {
  2513. struct drm_device *dev = crtc->dev;
  2514. struct drm_i915_private *dev_priv = dev->dev_private;
  2515. if (crtc->fb == NULL)
  2516. return;
  2517. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2518. wait_event(dev_priv->pending_flip_queue,
  2519. !intel_crtc_has_pending_flip(crtc));
  2520. mutex_lock(&dev->struct_mutex);
  2521. intel_finish_fb(crtc->fb);
  2522. mutex_unlock(&dev->struct_mutex);
  2523. }
  2524. static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
  2525. {
  2526. struct drm_device *dev = crtc->dev;
  2527. struct intel_encoder *intel_encoder;
  2528. /*
  2529. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2530. * must be driven by its own crtc; no sharing is possible.
  2531. */
  2532. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  2533. switch (intel_encoder->type) {
  2534. case INTEL_OUTPUT_EDP:
  2535. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  2536. return false;
  2537. continue;
  2538. }
  2539. }
  2540. return true;
  2541. }
  2542. static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
  2543. {
  2544. return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
  2545. }
  2546. /* Program iCLKIP clock to the desired frequency */
  2547. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2548. {
  2549. struct drm_device *dev = crtc->dev;
  2550. struct drm_i915_private *dev_priv = dev->dev_private;
  2551. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2552. u32 temp;
  2553. mutex_lock(&dev_priv->dpio_lock);
  2554. /* It is necessary to ungate the pixclk gate prior to programming
  2555. * the divisors, and gate it back when it is done.
  2556. */
  2557. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2558. /* Disable SSCCTL */
  2559. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2560. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2561. SBI_SSCCTL_DISABLE,
  2562. SBI_ICLK);
  2563. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2564. if (crtc->mode.clock == 20000) {
  2565. auxdiv = 1;
  2566. divsel = 0x41;
  2567. phaseinc = 0x20;
  2568. } else {
  2569. /* The iCLK virtual clock root frequency is in MHz,
  2570. * but the crtc->mode.clock in in KHz. To get the divisors,
  2571. * it is necessary to divide one by another, so we
  2572. * convert the virtual clock precision to KHz here for higher
  2573. * precision.
  2574. */
  2575. u32 iclk_virtual_root_freq = 172800 * 1000;
  2576. u32 iclk_pi_range = 64;
  2577. u32 desired_divisor, msb_divisor_value, pi_value;
  2578. desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
  2579. msb_divisor_value = desired_divisor / iclk_pi_range;
  2580. pi_value = desired_divisor % iclk_pi_range;
  2581. auxdiv = 0;
  2582. divsel = msb_divisor_value - 2;
  2583. phaseinc = pi_value;
  2584. }
  2585. /* This should not happen with any sane values */
  2586. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2587. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2588. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2589. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2590. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2591. crtc->mode.clock,
  2592. auxdiv,
  2593. divsel,
  2594. phasedir,
  2595. phaseinc);
  2596. /* Program SSCDIVINTPHASE6 */
  2597. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2598. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2599. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2600. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2601. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2602. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2603. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2604. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2605. /* Program SSCAUXDIV */
  2606. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2607. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2608. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2609. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2610. /* Enable modulator and associated divider */
  2611. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2612. temp &= ~SBI_SSCCTL_DISABLE;
  2613. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2614. /* Wait for initialization time */
  2615. udelay(24);
  2616. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2617. mutex_unlock(&dev_priv->dpio_lock);
  2618. }
  2619. /*
  2620. * Enable PCH resources required for PCH ports:
  2621. * - PCH PLLs
  2622. * - FDI training & RX/TX
  2623. * - update transcoder timings
  2624. * - DP transcoding bits
  2625. * - transcoder
  2626. */
  2627. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2628. {
  2629. struct drm_device *dev = crtc->dev;
  2630. struct drm_i915_private *dev_priv = dev->dev_private;
  2631. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2632. int pipe = intel_crtc->pipe;
  2633. u32 reg, temp;
  2634. assert_transcoder_disabled(dev_priv, pipe);
  2635. /* Write the TU size bits before fdi link training, so that error
  2636. * detection works. */
  2637. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2638. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2639. /* For PCH output, training FDI link */
  2640. dev_priv->display.fdi_link_train(crtc);
  2641. /* XXX: pch pll's can be enabled any time before we enable the PCH
  2642. * transcoder, and we actually should do this to not upset any PCH
  2643. * transcoder that already use the clock when we share it.
  2644. *
  2645. * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
  2646. * unconditionally resets the pll - we need that to have the right LVDS
  2647. * enable sequence. */
  2648. ironlake_enable_pch_pll(intel_crtc);
  2649. if (HAS_PCH_CPT(dev)) {
  2650. u32 sel;
  2651. temp = I915_READ(PCH_DPLL_SEL);
  2652. switch (pipe) {
  2653. default:
  2654. case 0:
  2655. temp |= TRANSA_DPLL_ENABLE;
  2656. sel = TRANSA_DPLLB_SEL;
  2657. break;
  2658. case 1:
  2659. temp |= TRANSB_DPLL_ENABLE;
  2660. sel = TRANSB_DPLLB_SEL;
  2661. break;
  2662. case 2:
  2663. temp |= TRANSC_DPLL_ENABLE;
  2664. sel = TRANSC_DPLLB_SEL;
  2665. break;
  2666. }
  2667. if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
  2668. temp |= sel;
  2669. else
  2670. temp &= ~sel;
  2671. I915_WRITE(PCH_DPLL_SEL, temp);
  2672. }
  2673. /* set transcoder timing, panel must allow it */
  2674. assert_panel_unlocked(dev_priv, pipe);
  2675. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2676. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2677. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2678. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2679. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2680. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2681. I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
  2682. intel_fdi_normal_train(crtc);
  2683. /* For PCH DP, enable TRANS_DP_CTL */
  2684. if (HAS_PCH_CPT(dev) &&
  2685. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  2686. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2687. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  2688. reg = TRANS_DP_CTL(pipe);
  2689. temp = I915_READ(reg);
  2690. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2691. TRANS_DP_SYNC_MASK |
  2692. TRANS_DP_BPC_MASK);
  2693. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2694. TRANS_DP_ENH_FRAMING);
  2695. temp |= bpc << 9; /* same format but at 11:9 */
  2696. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2697. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2698. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2699. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2700. switch (intel_trans_dp_port_sel(crtc)) {
  2701. case PCH_DP_B:
  2702. temp |= TRANS_DP_PORT_SEL_B;
  2703. break;
  2704. case PCH_DP_C:
  2705. temp |= TRANS_DP_PORT_SEL_C;
  2706. break;
  2707. case PCH_DP_D:
  2708. temp |= TRANS_DP_PORT_SEL_D;
  2709. break;
  2710. default:
  2711. BUG();
  2712. }
  2713. I915_WRITE(reg, temp);
  2714. }
  2715. ironlake_enable_pch_transcoder(dev_priv, pipe);
  2716. }
  2717. static void lpt_pch_enable(struct drm_crtc *crtc)
  2718. {
  2719. struct drm_device *dev = crtc->dev;
  2720. struct drm_i915_private *dev_priv = dev->dev_private;
  2721. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2722. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  2723. assert_transcoder_disabled(dev_priv, TRANSCODER_A);
  2724. lpt_program_iclkip(crtc);
  2725. /* Set transcoder timing. */
  2726. I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
  2727. I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
  2728. I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
  2729. I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
  2730. I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
  2731. I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
  2732. I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2733. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  2734. }
  2735. static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
  2736. {
  2737. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  2738. if (pll == NULL)
  2739. return;
  2740. if (pll->refcount == 0) {
  2741. WARN(1, "bad PCH PLL refcount\n");
  2742. return;
  2743. }
  2744. --pll->refcount;
  2745. intel_crtc->pch_pll = NULL;
  2746. }
  2747. static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
  2748. {
  2749. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  2750. struct intel_pch_pll *pll;
  2751. int i;
  2752. pll = intel_crtc->pch_pll;
  2753. if (pll) {
  2754. DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
  2755. intel_crtc->base.base.id, pll->pll_reg);
  2756. goto prepare;
  2757. }
  2758. if (HAS_PCH_IBX(dev_priv->dev)) {
  2759. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  2760. i = intel_crtc->pipe;
  2761. pll = &dev_priv->pch_plls[i];
  2762. DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
  2763. intel_crtc->base.base.id, pll->pll_reg);
  2764. goto found;
  2765. }
  2766. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2767. pll = &dev_priv->pch_plls[i];
  2768. /* Only want to check enabled timings first */
  2769. if (pll->refcount == 0)
  2770. continue;
  2771. if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
  2772. fp == I915_READ(pll->fp0_reg)) {
  2773. DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
  2774. intel_crtc->base.base.id,
  2775. pll->pll_reg, pll->refcount, pll->active);
  2776. goto found;
  2777. }
  2778. }
  2779. /* Ok no matching timings, maybe there's a free one? */
  2780. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2781. pll = &dev_priv->pch_plls[i];
  2782. if (pll->refcount == 0) {
  2783. DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
  2784. intel_crtc->base.base.id, pll->pll_reg);
  2785. goto found;
  2786. }
  2787. }
  2788. return NULL;
  2789. found:
  2790. intel_crtc->pch_pll = pll;
  2791. pll->refcount++;
  2792. DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
  2793. prepare: /* separate function? */
  2794. DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
  2795. /* Wait for the clocks to stabilize before rewriting the regs */
  2796. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2797. POSTING_READ(pll->pll_reg);
  2798. udelay(150);
  2799. I915_WRITE(pll->fp0_reg, fp);
  2800. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2801. pll->on = false;
  2802. return pll;
  2803. }
  2804. void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
  2805. {
  2806. struct drm_i915_private *dev_priv = dev->dev_private;
  2807. int dslreg = PIPEDSL(pipe);
  2808. u32 temp;
  2809. temp = I915_READ(dslreg);
  2810. udelay(500);
  2811. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  2812. if (wait_for(I915_READ(dslreg) != temp, 5))
  2813. DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
  2814. }
  2815. }
  2816. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2817. {
  2818. struct drm_device *dev = crtc->dev;
  2819. struct drm_i915_private *dev_priv = dev->dev_private;
  2820. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2821. struct intel_encoder *encoder;
  2822. int pipe = intel_crtc->pipe;
  2823. int plane = intel_crtc->plane;
  2824. u32 temp;
  2825. bool is_pch_port;
  2826. WARN_ON(!crtc->enabled);
  2827. if (intel_crtc->active)
  2828. return;
  2829. intel_crtc->active = true;
  2830. intel_update_watermarks(dev);
  2831. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2832. temp = I915_READ(PCH_LVDS);
  2833. if ((temp & LVDS_PORT_EN) == 0)
  2834. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2835. }
  2836. is_pch_port = ironlake_crtc_driving_pch(crtc);
  2837. if (is_pch_port) {
  2838. /* Note: FDI PLL enabling _must_ be done before we enable the
  2839. * cpu pipes, hence this is separate from all the other fdi/pch
  2840. * enabling. */
  2841. ironlake_fdi_pll_enable(intel_crtc);
  2842. } else {
  2843. assert_fdi_tx_disabled(dev_priv, pipe);
  2844. assert_fdi_rx_disabled(dev_priv, pipe);
  2845. }
  2846. for_each_encoder_on_crtc(dev, crtc, encoder)
  2847. if (encoder->pre_enable)
  2848. encoder->pre_enable(encoder);
  2849. /* Enable panel fitting for LVDS */
  2850. if (dev_priv->pch_pf_size &&
  2851. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2852. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2853. /* Force use of hard-coded filter coefficients
  2854. * as some pre-programmed values are broken,
  2855. * e.g. x201.
  2856. */
  2857. if (IS_IVYBRIDGE(dev))
  2858. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2859. PF_PIPE_SEL_IVB(pipe));
  2860. else
  2861. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2862. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2863. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2864. }
  2865. /*
  2866. * On ILK+ LUT must be loaded before the pipe is running but with
  2867. * clocks enabled
  2868. */
  2869. intel_crtc_load_lut(crtc);
  2870. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2871. intel_enable_plane(dev_priv, plane, pipe);
  2872. if (is_pch_port)
  2873. ironlake_pch_enable(crtc);
  2874. mutex_lock(&dev->struct_mutex);
  2875. intel_update_fbc(dev);
  2876. mutex_unlock(&dev->struct_mutex);
  2877. intel_crtc_update_cursor(crtc, true);
  2878. for_each_encoder_on_crtc(dev, crtc, encoder)
  2879. encoder->enable(encoder);
  2880. if (HAS_PCH_CPT(dev))
  2881. intel_cpt_verify_modeset(dev, intel_crtc->pipe);
  2882. /*
  2883. * There seems to be a race in PCH platform hw (at least on some
  2884. * outputs) where an enabled pipe still completes any pageflip right
  2885. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2886. * as the first vblank happend, everything works as expected. Hence just
  2887. * wait for one vblank before returning to avoid strange things
  2888. * happening.
  2889. */
  2890. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2891. }
  2892. static void haswell_crtc_enable(struct drm_crtc *crtc)
  2893. {
  2894. struct drm_device *dev = crtc->dev;
  2895. struct drm_i915_private *dev_priv = dev->dev_private;
  2896. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2897. struct intel_encoder *encoder;
  2898. int pipe = intel_crtc->pipe;
  2899. int plane = intel_crtc->plane;
  2900. bool is_pch_port;
  2901. WARN_ON(!crtc->enabled);
  2902. if (intel_crtc->active)
  2903. return;
  2904. intel_crtc->active = true;
  2905. intel_update_watermarks(dev);
  2906. is_pch_port = haswell_crtc_driving_pch(crtc);
  2907. if (is_pch_port)
  2908. dev_priv->display.fdi_link_train(crtc);
  2909. for_each_encoder_on_crtc(dev, crtc, encoder)
  2910. if (encoder->pre_enable)
  2911. encoder->pre_enable(encoder);
  2912. intel_ddi_enable_pipe_clock(intel_crtc);
  2913. /* Enable panel fitting for eDP */
  2914. if (dev_priv->pch_pf_size &&
  2915. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  2916. /* Force use of hard-coded filter coefficients
  2917. * as some pre-programmed values are broken,
  2918. * e.g. x201.
  2919. */
  2920. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2921. PF_PIPE_SEL_IVB(pipe));
  2922. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2923. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2924. }
  2925. /*
  2926. * On ILK+ LUT must be loaded before the pipe is running but with
  2927. * clocks enabled
  2928. */
  2929. intel_crtc_load_lut(crtc);
  2930. intel_ddi_set_pipe_settings(crtc);
  2931. intel_ddi_enable_pipe_func(crtc);
  2932. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2933. intel_enable_plane(dev_priv, plane, pipe);
  2934. if (is_pch_port)
  2935. lpt_pch_enable(crtc);
  2936. mutex_lock(&dev->struct_mutex);
  2937. intel_update_fbc(dev);
  2938. mutex_unlock(&dev->struct_mutex);
  2939. intel_crtc_update_cursor(crtc, true);
  2940. for_each_encoder_on_crtc(dev, crtc, encoder)
  2941. encoder->enable(encoder);
  2942. /*
  2943. * There seems to be a race in PCH platform hw (at least on some
  2944. * outputs) where an enabled pipe still completes any pageflip right
  2945. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2946. * as the first vblank happend, everything works as expected. Hence just
  2947. * wait for one vblank before returning to avoid strange things
  2948. * happening.
  2949. */
  2950. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2951. }
  2952. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2953. {
  2954. struct drm_device *dev = crtc->dev;
  2955. struct drm_i915_private *dev_priv = dev->dev_private;
  2956. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2957. struct intel_encoder *encoder;
  2958. int pipe = intel_crtc->pipe;
  2959. int plane = intel_crtc->plane;
  2960. u32 reg, temp;
  2961. if (!intel_crtc->active)
  2962. return;
  2963. for_each_encoder_on_crtc(dev, crtc, encoder)
  2964. encoder->disable(encoder);
  2965. intel_crtc_wait_for_pending_flips(crtc);
  2966. drm_vblank_off(dev, pipe);
  2967. intel_crtc_update_cursor(crtc, false);
  2968. intel_disable_plane(dev_priv, plane, pipe);
  2969. if (dev_priv->cfb_plane == plane)
  2970. intel_disable_fbc(dev);
  2971. intel_disable_pipe(dev_priv, pipe);
  2972. /* Disable PF */
  2973. I915_WRITE(PF_CTL(pipe), 0);
  2974. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2975. for_each_encoder_on_crtc(dev, crtc, encoder)
  2976. if (encoder->post_disable)
  2977. encoder->post_disable(encoder);
  2978. ironlake_fdi_disable(crtc);
  2979. ironlake_disable_pch_transcoder(dev_priv, pipe);
  2980. if (HAS_PCH_CPT(dev)) {
  2981. /* disable TRANS_DP_CTL */
  2982. reg = TRANS_DP_CTL(pipe);
  2983. temp = I915_READ(reg);
  2984. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2985. temp |= TRANS_DP_PORT_SEL_NONE;
  2986. I915_WRITE(reg, temp);
  2987. /* disable DPLL_SEL */
  2988. temp = I915_READ(PCH_DPLL_SEL);
  2989. switch (pipe) {
  2990. case 0:
  2991. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
  2992. break;
  2993. case 1:
  2994. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  2995. break;
  2996. case 2:
  2997. /* C shares PLL A or B */
  2998. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  2999. break;
  3000. default:
  3001. BUG(); /* wtf */
  3002. }
  3003. I915_WRITE(PCH_DPLL_SEL, temp);
  3004. }
  3005. /* disable PCH DPLL */
  3006. intel_disable_pch_pll(intel_crtc);
  3007. ironlake_fdi_pll_disable(intel_crtc);
  3008. intel_crtc->active = false;
  3009. intel_update_watermarks(dev);
  3010. mutex_lock(&dev->struct_mutex);
  3011. intel_update_fbc(dev);
  3012. mutex_unlock(&dev->struct_mutex);
  3013. }
  3014. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3015. {
  3016. struct drm_device *dev = crtc->dev;
  3017. struct drm_i915_private *dev_priv = dev->dev_private;
  3018. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3019. struct intel_encoder *encoder;
  3020. int pipe = intel_crtc->pipe;
  3021. int plane = intel_crtc->plane;
  3022. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3023. bool is_pch_port;
  3024. if (!intel_crtc->active)
  3025. return;
  3026. is_pch_port = haswell_crtc_driving_pch(crtc);
  3027. for_each_encoder_on_crtc(dev, crtc, encoder)
  3028. encoder->disable(encoder);
  3029. intel_crtc_wait_for_pending_flips(crtc);
  3030. drm_vblank_off(dev, pipe);
  3031. intel_crtc_update_cursor(crtc, false);
  3032. intel_disable_plane(dev_priv, plane, pipe);
  3033. if (dev_priv->cfb_plane == plane)
  3034. intel_disable_fbc(dev);
  3035. intel_disable_pipe(dev_priv, pipe);
  3036. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3037. /* Disable PF */
  3038. I915_WRITE(PF_CTL(pipe), 0);
  3039. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3040. intel_ddi_disable_pipe_clock(intel_crtc);
  3041. for_each_encoder_on_crtc(dev, crtc, encoder)
  3042. if (encoder->post_disable)
  3043. encoder->post_disable(encoder);
  3044. if (is_pch_port) {
  3045. lpt_disable_pch_transcoder(dev_priv);
  3046. intel_ddi_fdi_disable(crtc);
  3047. }
  3048. intel_crtc->active = false;
  3049. intel_update_watermarks(dev);
  3050. mutex_lock(&dev->struct_mutex);
  3051. intel_update_fbc(dev);
  3052. mutex_unlock(&dev->struct_mutex);
  3053. }
  3054. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3055. {
  3056. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3057. intel_put_pch_pll(intel_crtc);
  3058. }
  3059. static void haswell_crtc_off(struct drm_crtc *crtc)
  3060. {
  3061. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3062. /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
  3063. * start using it. */
  3064. intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
  3065. intel_ddi_put_crtc_pll(crtc);
  3066. }
  3067. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3068. {
  3069. if (!enable && intel_crtc->overlay) {
  3070. struct drm_device *dev = intel_crtc->base.dev;
  3071. struct drm_i915_private *dev_priv = dev->dev_private;
  3072. mutex_lock(&dev->struct_mutex);
  3073. dev_priv->mm.interruptible = false;
  3074. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3075. dev_priv->mm.interruptible = true;
  3076. mutex_unlock(&dev->struct_mutex);
  3077. }
  3078. /* Let userspace switch the overlay on again. In most cases userspace
  3079. * has to recompute where to put it anyway.
  3080. */
  3081. }
  3082. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3083. {
  3084. struct drm_device *dev = crtc->dev;
  3085. struct drm_i915_private *dev_priv = dev->dev_private;
  3086. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3087. struct intel_encoder *encoder;
  3088. int pipe = intel_crtc->pipe;
  3089. int plane = intel_crtc->plane;
  3090. WARN_ON(!crtc->enabled);
  3091. if (intel_crtc->active)
  3092. return;
  3093. intel_crtc->active = true;
  3094. intel_update_watermarks(dev);
  3095. intel_enable_pll(dev_priv, pipe);
  3096. for_each_encoder_on_crtc(dev, crtc, encoder)
  3097. if (encoder->pre_enable)
  3098. encoder->pre_enable(encoder);
  3099. intel_enable_pipe(dev_priv, pipe, false);
  3100. intel_enable_plane(dev_priv, plane, pipe);
  3101. intel_crtc_load_lut(crtc);
  3102. intel_update_fbc(dev);
  3103. /* Give the overlay scaler a chance to enable if it's on this pipe */
  3104. intel_crtc_dpms_overlay(intel_crtc, true);
  3105. intel_crtc_update_cursor(crtc, true);
  3106. for_each_encoder_on_crtc(dev, crtc, encoder)
  3107. encoder->enable(encoder);
  3108. }
  3109. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  3110. {
  3111. struct drm_device *dev = crtc->dev;
  3112. struct drm_i915_private *dev_priv = dev->dev_private;
  3113. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3114. struct intel_encoder *encoder;
  3115. int pipe = intel_crtc->pipe;
  3116. int plane = intel_crtc->plane;
  3117. u32 pctl;
  3118. if (!intel_crtc->active)
  3119. return;
  3120. for_each_encoder_on_crtc(dev, crtc, encoder)
  3121. encoder->disable(encoder);
  3122. /* Give the overlay scaler a chance to disable if it's on this pipe */
  3123. intel_crtc_wait_for_pending_flips(crtc);
  3124. drm_vblank_off(dev, pipe);
  3125. intel_crtc_dpms_overlay(intel_crtc, false);
  3126. intel_crtc_update_cursor(crtc, false);
  3127. if (dev_priv->cfb_plane == plane)
  3128. intel_disable_fbc(dev);
  3129. intel_disable_plane(dev_priv, plane, pipe);
  3130. intel_disable_pipe(dev_priv, pipe);
  3131. /* Disable pannel fitter if it is on this pipe. */
  3132. pctl = I915_READ(PFIT_CONTROL);
  3133. if ((pctl & PFIT_ENABLE) &&
  3134. ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
  3135. I915_WRITE(PFIT_CONTROL, 0);
  3136. intel_disable_pll(dev_priv, pipe);
  3137. intel_crtc->active = false;
  3138. intel_update_fbc(dev);
  3139. intel_update_watermarks(dev);
  3140. }
  3141. static void i9xx_crtc_off(struct drm_crtc *crtc)
  3142. {
  3143. }
  3144. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  3145. bool enabled)
  3146. {
  3147. struct drm_device *dev = crtc->dev;
  3148. struct drm_i915_master_private *master_priv;
  3149. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3150. int pipe = intel_crtc->pipe;
  3151. if (!dev->primary->master)
  3152. return;
  3153. master_priv = dev->primary->master->driver_priv;
  3154. if (!master_priv->sarea_priv)
  3155. return;
  3156. switch (pipe) {
  3157. case 0:
  3158. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  3159. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  3160. break;
  3161. case 1:
  3162. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  3163. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  3164. break;
  3165. default:
  3166. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  3167. break;
  3168. }
  3169. }
  3170. /**
  3171. * Sets the power management mode of the pipe and plane.
  3172. */
  3173. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  3174. {
  3175. struct drm_device *dev = crtc->dev;
  3176. struct drm_i915_private *dev_priv = dev->dev_private;
  3177. struct intel_encoder *intel_encoder;
  3178. bool enable = false;
  3179. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3180. enable |= intel_encoder->connectors_active;
  3181. if (enable)
  3182. dev_priv->display.crtc_enable(crtc);
  3183. else
  3184. dev_priv->display.crtc_disable(crtc);
  3185. intel_crtc_update_sarea(crtc, enable);
  3186. }
  3187. static void intel_crtc_noop(struct drm_crtc *crtc)
  3188. {
  3189. }
  3190. static void intel_crtc_disable(struct drm_crtc *crtc)
  3191. {
  3192. struct drm_device *dev = crtc->dev;
  3193. struct drm_connector *connector;
  3194. struct drm_i915_private *dev_priv = dev->dev_private;
  3195. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3196. /* crtc should still be enabled when we disable it. */
  3197. WARN_ON(!crtc->enabled);
  3198. intel_crtc->eld_vld = false;
  3199. dev_priv->display.crtc_disable(crtc);
  3200. intel_crtc_update_sarea(crtc, false);
  3201. dev_priv->display.off(crtc);
  3202. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  3203. assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
  3204. if (crtc->fb) {
  3205. mutex_lock(&dev->struct_mutex);
  3206. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  3207. mutex_unlock(&dev->struct_mutex);
  3208. crtc->fb = NULL;
  3209. }
  3210. /* Update computed state. */
  3211. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3212. if (!connector->encoder || !connector->encoder->crtc)
  3213. continue;
  3214. if (connector->encoder->crtc != crtc)
  3215. continue;
  3216. connector->dpms = DRM_MODE_DPMS_OFF;
  3217. to_intel_encoder(connector->encoder)->connectors_active = false;
  3218. }
  3219. }
  3220. void intel_modeset_disable(struct drm_device *dev)
  3221. {
  3222. struct drm_crtc *crtc;
  3223. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3224. if (crtc->enabled)
  3225. intel_crtc_disable(crtc);
  3226. }
  3227. }
  3228. void intel_encoder_noop(struct drm_encoder *encoder)
  3229. {
  3230. }
  3231. void intel_encoder_destroy(struct drm_encoder *encoder)
  3232. {
  3233. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  3234. drm_encoder_cleanup(encoder);
  3235. kfree(intel_encoder);
  3236. }
  3237. /* Simple dpms helper for encodres with just one connector, no cloning and only
  3238. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  3239. * state of the entire output pipe. */
  3240. void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  3241. {
  3242. if (mode == DRM_MODE_DPMS_ON) {
  3243. encoder->connectors_active = true;
  3244. intel_crtc_update_dpms(encoder->base.crtc);
  3245. } else {
  3246. encoder->connectors_active = false;
  3247. intel_crtc_update_dpms(encoder->base.crtc);
  3248. }
  3249. }
  3250. /* Cross check the actual hw state with our own modeset state tracking (and it's
  3251. * internal consistency). */
  3252. static void intel_connector_check_state(struct intel_connector *connector)
  3253. {
  3254. if (connector->get_hw_state(connector)) {
  3255. struct intel_encoder *encoder = connector->encoder;
  3256. struct drm_crtc *crtc;
  3257. bool encoder_enabled;
  3258. enum pipe pipe;
  3259. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3260. connector->base.base.id,
  3261. drm_get_connector_name(&connector->base));
  3262. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  3263. "wrong connector dpms state\n");
  3264. WARN(connector->base.encoder != &encoder->base,
  3265. "active connector not linked to encoder\n");
  3266. WARN(!encoder->connectors_active,
  3267. "encoder->connectors_active not set\n");
  3268. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  3269. WARN(!encoder_enabled, "encoder not enabled\n");
  3270. if (WARN_ON(!encoder->base.crtc))
  3271. return;
  3272. crtc = encoder->base.crtc;
  3273. WARN(!crtc->enabled, "crtc not enabled\n");
  3274. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  3275. WARN(pipe != to_intel_crtc(crtc)->pipe,
  3276. "encoder active on the wrong pipe\n");
  3277. }
  3278. }
  3279. /* Even simpler default implementation, if there's really no special case to
  3280. * consider. */
  3281. void intel_connector_dpms(struct drm_connector *connector, int mode)
  3282. {
  3283. struct intel_encoder *encoder = intel_attached_encoder(connector);
  3284. /* All the simple cases only support two dpms states. */
  3285. if (mode != DRM_MODE_DPMS_ON)
  3286. mode = DRM_MODE_DPMS_OFF;
  3287. if (mode == connector->dpms)
  3288. return;
  3289. connector->dpms = mode;
  3290. /* Only need to change hw state when actually enabled */
  3291. if (encoder->base.crtc)
  3292. intel_encoder_dpms(encoder, mode);
  3293. else
  3294. WARN_ON(encoder->connectors_active != false);
  3295. intel_modeset_check_state(connector->dev);
  3296. }
  3297. /* Simple connector->get_hw_state implementation for encoders that support only
  3298. * one connector and no cloning and hence the encoder state determines the state
  3299. * of the connector. */
  3300. bool intel_connector_get_hw_state(struct intel_connector *connector)
  3301. {
  3302. enum pipe pipe = 0;
  3303. struct intel_encoder *encoder = connector->encoder;
  3304. return encoder->get_hw_state(encoder, &pipe);
  3305. }
  3306. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  3307. const struct drm_display_mode *mode,
  3308. struct drm_display_mode *adjusted_mode)
  3309. {
  3310. struct drm_device *dev = crtc->dev;
  3311. if (HAS_PCH_SPLIT(dev)) {
  3312. /* FDI link clock is fixed at 2.7G */
  3313. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  3314. return false;
  3315. }
  3316. /* All interlaced capable intel hw wants timings in frames. Note though
  3317. * that intel_lvds_mode_fixup does some funny tricks with the crtc
  3318. * timings, so we need to be careful not to clobber these.*/
  3319. if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
  3320. drm_mode_set_crtcinfo(adjusted_mode, 0);
  3321. /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
  3322. * with a hsync front porch of 0.
  3323. */
  3324. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  3325. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  3326. return false;
  3327. return true;
  3328. }
  3329. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  3330. {
  3331. return 400000; /* FIXME */
  3332. }
  3333. static int i945_get_display_clock_speed(struct drm_device *dev)
  3334. {
  3335. return 400000;
  3336. }
  3337. static int i915_get_display_clock_speed(struct drm_device *dev)
  3338. {
  3339. return 333000;
  3340. }
  3341. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  3342. {
  3343. return 200000;
  3344. }
  3345. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  3346. {
  3347. u16 gcfgc = 0;
  3348. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3349. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  3350. return 133000;
  3351. else {
  3352. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  3353. case GC_DISPLAY_CLOCK_333_MHZ:
  3354. return 333000;
  3355. default:
  3356. case GC_DISPLAY_CLOCK_190_200_MHZ:
  3357. return 190000;
  3358. }
  3359. }
  3360. }
  3361. static int i865_get_display_clock_speed(struct drm_device *dev)
  3362. {
  3363. return 266000;
  3364. }
  3365. static int i855_get_display_clock_speed(struct drm_device *dev)
  3366. {
  3367. u16 hpllcc = 0;
  3368. /* Assume that the hardware is in the high speed state. This
  3369. * should be the default.
  3370. */
  3371. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  3372. case GC_CLOCK_133_200:
  3373. case GC_CLOCK_100_200:
  3374. return 200000;
  3375. case GC_CLOCK_166_250:
  3376. return 250000;
  3377. case GC_CLOCK_100_133:
  3378. return 133000;
  3379. }
  3380. /* Shouldn't happen */
  3381. return 0;
  3382. }
  3383. static int i830_get_display_clock_speed(struct drm_device *dev)
  3384. {
  3385. return 133000;
  3386. }
  3387. static void
  3388. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  3389. {
  3390. while (*num > 0xffffff || *den > 0xffffff) {
  3391. *num >>= 1;
  3392. *den >>= 1;
  3393. }
  3394. }
  3395. void
  3396. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  3397. int pixel_clock, int link_clock,
  3398. struct intel_link_m_n *m_n)
  3399. {
  3400. m_n->tu = 64;
  3401. m_n->gmch_m = bits_per_pixel * pixel_clock;
  3402. m_n->gmch_n = link_clock * nlanes * 8;
  3403. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  3404. m_n->link_m = pixel_clock;
  3405. m_n->link_n = link_clock;
  3406. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  3407. }
  3408. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3409. {
  3410. if (i915_panel_use_ssc >= 0)
  3411. return i915_panel_use_ssc != 0;
  3412. return dev_priv->lvds_use_ssc
  3413. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  3414. }
  3415. /**
  3416. * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
  3417. * @crtc: CRTC structure
  3418. * @mode: requested mode
  3419. *
  3420. * A pipe may be connected to one or more outputs. Based on the depth of the
  3421. * attached framebuffer, choose a good color depth to use on the pipe.
  3422. *
  3423. * If possible, match the pipe depth to the fb depth. In some cases, this
  3424. * isn't ideal, because the connected output supports a lesser or restricted
  3425. * set of depths. Resolve that here:
  3426. * LVDS typically supports only 6bpc, so clamp down in that case
  3427. * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
  3428. * Displays may support a restricted set as well, check EDID and clamp as
  3429. * appropriate.
  3430. * DP may want to dither down to 6bpc to fit larger modes
  3431. *
  3432. * RETURNS:
  3433. * Dithering requirement (i.e. false if display bpc and pipe bpc match,
  3434. * true if they don't match).
  3435. */
  3436. static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
  3437. struct drm_framebuffer *fb,
  3438. unsigned int *pipe_bpp,
  3439. struct drm_display_mode *mode)
  3440. {
  3441. struct drm_device *dev = crtc->dev;
  3442. struct drm_i915_private *dev_priv = dev->dev_private;
  3443. struct drm_connector *connector;
  3444. struct intel_encoder *intel_encoder;
  3445. unsigned int display_bpc = UINT_MAX, bpc;
  3446. /* Walk the encoders & connectors on this crtc, get min bpc */
  3447. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  3448. if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
  3449. unsigned int lvds_bpc;
  3450. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
  3451. LVDS_A3_POWER_UP)
  3452. lvds_bpc = 8;
  3453. else
  3454. lvds_bpc = 6;
  3455. if (lvds_bpc < display_bpc) {
  3456. DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
  3457. display_bpc = lvds_bpc;
  3458. }
  3459. continue;
  3460. }
  3461. /* Not one of the known troublemakers, check the EDID */
  3462. list_for_each_entry(connector, &dev->mode_config.connector_list,
  3463. head) {
  3464. if (connector->encoder != &intel_encoder->base)
  3465. continue;
  3466. /* Don't use an invalid EDID bpc value */
  3467. if (connector->display_info.bpc &&
  3468. connector->display_info.bpc < display_bpc) {
  3469. DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
  3470. display_bpc = connector->display_info.bpc;
  3471. }
  3472. }
  3473. if (intel_encoder->type == INTEL_OUTPUT_EDP) {
  3474. /* Use VBT settings if we have an eDP panel */
  3475. unsigned int edp_bpc = dev_priv->edp.bpp / 3;
  3476. if (edp_bpc && edp_bpc < display_bpc) {
  3477. DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
  3478. display_bpc = edp_bpc;
  3479. }
  3480. continue;
  3481. }
  3482. /*
  3483. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  3484. * through, clamp it down. (Note: >12bpc will be caught below.)
  3485. */
  3486. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  3487. if (display_bpc > 8 && display_bpc < 12) {
  3488. DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
  3489. display_bpc = 12;
  3490. } else {
  3491. DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
  3492. display_bpc = 8;
  3493. }
  3494. }
  3495. }
  3496. if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  3497. DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
  3498. display_bpc = 6;
  3499. }
  3500. /*
  3501. * We could just drive the pipe at the highest bpc all the time and
  3502. * enable dithering as needed, but that costs bandwidth. So choose
  3503. * the minimum value that expresses the full color range of the fb but
  3504. * also stays within the max display bpc discovered above.
  3505. */
  3506. switch (fb->depth) {
  3507. case 8:
  3508. bpc = 8; /* since we go through a colormap */
  3509. break;
  3510. case 15:
  3511. case 16:
  3512. bpc = 6; /* min is 18bpp */
  3513. break;
  3514. case 24:
  3515. bpc = 8;
  3516. break;
  3517. case 30:
  3518. bpc = 10;
  3519. break;
  3520. case 48:
  3521. bpc = 12;
  3522. break;
  3523. default:
  3524. DRM_DEBUG("unsupported depth, assuming 24 bits\n");
  3525. bpc = min((unsigned int)8, display_bpc);
  3526. break;
  3527. }
  3528. display_bpc = min(display_bpc, bpc);
  3529. DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
  3530. bpc, display_bpc);
  3531. *pipe_bpp = display_bpc * 3;
  3532. return display_bpc != bpc;
  3533. }
  3534. static int vlv_get_refclk(struct drm_crtc *crtc)
  3535. {
  3536. struct drm_device *dev = crtc->dev;
  3537. struct drm_i915_private *dev_priv = dev->dev_private;
  3538. int refclk = 27000; /* for DP & HDMI */
  3539. return 100000; /* only one validated so far */
  3540. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  3541. refclk = 96000;
  3542. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3543. if (intel_panel_use_ssc(dev_priv))
  3544. refclk = 100000;
  3545. else
  3546. refclk = 96000;
  3547. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  3548. refclk = 100000;
  3549. }
  3550. return refclk;
  3551. }
  3552. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  3553. {
  3554. struct drm_device *dev = crtc->dev;
  3555. struct drm_i915_private *dev_priv = dev->dev_private;
  3556. int refclk;
  3557. if (IS_VALLEYVIEW(dev)) {
  3558. refclk = vlv_get_refclk(crtc);
  3559. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3560. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3561. refclk = dev_priv->lvds_ssc_freq * 1000;
  3562. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3563. refclk / 1000);
  3564. } else if (!IS_GEN2(dev)) {
  3565. refclk = 96000;
  3566. } else {
  3567. refclk = 48000;
  3568. }
  3569. return refclk;
  3570. }
  3571. static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
  3572. intel_clock_t *clock)
  3573. {
  3574. /* SDVO TV has fixed PLL values depend on its clock range,
  3575. this mirrors vbios setting. */
  3576. if (adjusted_mode->clock >= 100000
  3577. && adjusted_mode->clock < 140500) {
  3578. clock->p1 = 2;
  3579. clock->p2 = 10;
  3580. clock->n = 3;
  3581. clock->m1 = 16;
  3582. clock->m2 = 8;
  3583. } else if (adjusted_mode->clock >= 140500
  3584. && adjusted_mode->clock <= 200000) {
  3585. clock->p1 = 1;
  3586. clock->p2 = 10;
  3587. clock->n = 6;
  3588. clock->m1 = 12;
  3589. clock->m2 = 8;
  3590. }
  3591. }
  3592. static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
  3593. intel_clock_t *clock,
  3594. intel_clock_t *reduced_clock)
  3595. {
  3596. struct drm_device *dev = crtc->dev;
  3597. struct drm_i915_private *dev_priv = dev->dev_private;
  3598. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3599. int pipe = intel_crtc->pipe;
  3600. u32 fp, fp2 = 0;
  3601. if (IS_PINEVIEW(dev)) {
  3602. fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
  3603. if (reduced_clock)
  3604. fp2 = (1 << reduced_clock->n) << 16 |
  3605. reduced_clock->m1 << 8 | reduced_clock->m2;
  3606. } else {
  3607. fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
  3608. if (reduced_clock)
  3609. fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
  3610. reduced_clock->m2;
  3611. }
  3612. I915_WRITE(FP0(pipe), fp);
  3613. intel_crtc->lowfreq_avail = false;
  3614. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3615. reduced_clock && i915_powersave) {
  3616. I915_WRITE(FP1(pipe), fp2);
  3617. intel_crtc->lowfreq_avail = true;
  3618. } else {
  3619. I915_WRITE(FP1(pipe), fp);
  3620. }
  3621. }
  3622. static void vlv_update_pll(struct drm_crtc *crtc,
  3623. struct drm_display_mode *mode,
  3624. struct drm_display_mode *adjusted_mode,
  3625. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3626. int num_connectors)
  3627. {
  3628. struct drm_device *dev = crtc->dev;
  3629. struct drm_i915_private *dev_priv = dev->dev_private;
  3630. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3631. int pipe = intel_crtc->pipe;
  3632. u32 dpll, mdiv, pdiv;
  3633. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  3634. bool is_sdvo;
  3635. u32 temp;
  3636. mutex_lock(&dev_priv->dpio_lock);
  3637. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3638. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3639. dpll = DPLL_VGA_MODE_DIS;
  3640. dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
  3641. dpll |= DPLL_REFA_CLK_ENABLE_VLV;
  3642. dpll |= DPLL_INTEGRATED_CLOCK_VLV;
  3643. I915_WRITE(DPLL(pipe), dpll);
  3644. POSTING_READ(DPLL(pipe));
  3645. bestn = clock->n;
  3646. bestm1 = clock->m1;
  3647. bestm2 = clock->m2;
  3648. bestp1 = clock->p1;
  3649. bestp2 = clock->p2;
  3650. /*
  3651. * In Valleyview PLL and program lane counter registers are exposed
  3652. * through DPIO interface
  3653. */
  3654. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  3655. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  3656. mdiv |= ((bestn << DPIO_N_SHIFT));
  3657. mdiv |= (1 << DPIO_POST_DIV_SHIFT);
  3658. mdiv |= (1 << DPIO_K_SHIFT);
  3659. mdiv |= DPIO_ENABLE_CALIBRATION;
  3660. intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
  3661. intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
  3662. pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
  3663. (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
  3664. (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
  3665. (5 << DPIO_CLK_BIAS_CTL_SHIFT);
  3666. intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
  3667. intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
  3668. dpll |= DPLL_VCO_ENABLE;
  3669. I915_WRITE(DPLL(pipe), dpll);
  3670. POSTING_READ(DPLL(pipe));
  3671. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  3672. DRM_ERROR("DPLL %d failed to lock\n", pipe);
  3673. intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
  3674. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3675. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3676. I915_WRITE(DPLL(pipe), dpll);
  3677. /* Wait for the clocks to stabilize. */
  3678. POSTING_READ(DPLL(pipe));
  3679. udelay(150);
  3680. temp = 0;
  3681. if (is_sdvo) {
  3682. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3683. if (temp > 1)
  3684. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3685. else
  3686. temp = 0;
  3687. }
  3688. I915_WRITE(DPLL_MD(pipe), temp);
  3689. POSTING_READ(DPLL_MD(pipe));
  3690. /* Now program lane control registers */
  3691. if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
  3692. || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  3693. {
  3694. temp = 0x1000C4;
  3695. if(pipe == 1)
  3696. temp |= (1 << 21);
  3697. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
  3698. }
  3699. if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
  3700. {
  3701. temp = 0x1000C4;
  3702. if(pipe == 1)
  3703. temp |= (1 << 21);
  3704. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
  3705. }
  3706. mutex_unlock(&dev_priv->dpio_lock);
  3707. }
  3708. static void i9xx_update_pll(struct drm_crtc *crtc,
  3709. struct drm_display_mode *mode,
  3710. struct drm_display_mode *adjusted_mode,
  3711. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3712. int num_connectors)
  3713. {
  3714. struct drm_device *dev = crtc->dev;
  3715. struct drm_i915_private *dev_priv = dev->dev_private;
  3716. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3717. struct intel_encoder *encoder;
  3718. int pipe = intel_crtc->pipe;
  3719. u32 dpll;
  3720. bool is_sdvo;
  3721. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3722. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3723. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3724. dpll = DPLL_VGA_MODE_DIS;
  3725. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3726. dpll |= DPLLB_MODE_LVDS;
  3727. else
  3728. dpll |= DPLLB_MODE_DAC_SERIAL;
  3729. if (is_sdvo) {
  3730. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3731. if (pixel_multiplier > 1) {
  3732. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3733. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3734. }
  3735. dpll |= DPLL_DVO_HIGH_SPEED;
  3736. }
  3737. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3738. dpll |= DPLL_DVO_HIGH_SPEED;
  3739. /* compute bitmask from p1 value */
  3740. if (IS_PINEVIEW(dev))
  3741. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3742. else {
  3743. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3744. if (IS_G4X(dev) && reduced_clock)
  3745. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3746. }
  3747. switch (clock->p2) {
  3748. case 5:
  3749. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3750. break;
  3751. case 7:
  3752. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3753. break;
  3754. case 10:
  3755. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3756. break;
  3757. case 14:
  3758. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3759. break;
  3760. }
  3761. if (INTEL_INFO(dev)->gen >= 4)
  3762. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3763. if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3764. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3765. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3766. /* XXX: just matching BIOS for now */
  3767. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3768. dpll |= 3;
  3769. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3770. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3771. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3772. else
  3773. dpll |= PLL_REF_INPUT_DREFCLK;
  3774. dpll |= DPLL_VCO_ENABLE;
  3775. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3776. POSTING_READ(DPLL(pipe));
  3777. udelay(150);
  3778. for_each_encoder_on_crtc(dev, crtc, encoder)
  3779. if (encoder->pre_pll_enable)
  3780. encoder->pre_pll_enable(encoder);
  3781. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3782. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3783. I915_WRITE(DPLL(pipe), dpll);
  3784. /* Wait for the clocks to stabilize. */
  3785. POSTING_READ(DPLL(pipe));
  3786. udelay(150);
  3787. if (INTEL_INFO(dev)->gen >= 4) {
  3788. u32 temp = 0;
  3789. if (is_sdvo) {
  3790. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3791. if (temp > 1)
  3792. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3793. else
  3794. temp = 0;
  3795. }
  3796. I915_WRITE(DPLL_MD(pipe), temp);
  3797. } else {
  3798. /* The pixel multiplier can only be updated once the
  3799. * DPLL is enabled and the clocks are stable.
  3800. *
  3801. * So write it again.
  3802. */
  3803. I915_WRITE(DPLL(pipe), dpll);
  3804. }
  3805. }
  3806. static void i8xx_update_pll(struct drm_crtc *crtc,
  3807. struct drm_display_mode *adjusted_mode,
  3808. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3809. int num_connectors)
  3810. {
  3811. struct drm_device *dev = crtc->dev;
  3812. struct drm_i915_private *dev_priv = dev->dev_private;
  3813. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3814. struct intel_encoder *encoder;
  3815. int pipe = intel_crtc->pipe;
  3816. u32 dpll;
  3817. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3818. dpll = DPLL_VGA_MODE_DIS;
  3819. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3820. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3821. } else {
  3822. if (clock->p1 == 2)
  3823. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3824. else
  3825. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3826. if (clock->p2 == 4)
  3827. dpll |= PLL_P2_DIVIDE_BY_4;
  3828. }
  3829. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3830. /* XXX: just matching BIOS for now */
  3831. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3832. dpll |= 3;
  3833. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3834. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3835. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3836. else
  3837. dpll |= PLL_REF_INPUT_DREFCLK;
  3838. dpll |= DPLL_VCO_ENABLE;
  3839. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3840. POSTING_READ(DPLL(pipe));
  3841. udelay(150);
  3842. for_each_encoder_on_crtc(dev, crtc, encoder)
  3843. if (encoder->pre_pll_enable)
  3844. encoder->pre_pll_enable(encoder);
  3845. I915_WRITE(DPLL(pipe), dpll);
  3846. /* Wait for the clocks to stabilize. */
  3847. POSTING_READ(DPLL(pipe));
  3848. udelay(150);
  3849. /* The pixel multiplier can only be updated once the
  3850. * DPLL is enabled and the clocks are stable.
  3851. *
  3852. * So write it again.
  3853. */
  3854. I915_WRITE(DPLL(pipe), dpll);
  3855. }
  3856. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
  3857. struct drm_display_mode *mode,
  3858. struct drm_display_mode *adjusted_mode)
  3859. {
  3860. struct drm_device *dev = intel_crtc->base.dev;
  3861. struct drm_i915_private *dev_priv = dev->dev_private;
  3862. enum pipe pipe = intel_crtc->pipe;
  3863. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3864. uint32_t vsyncshift;
  3865. if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  3866. /* the chip adds 2 halflines automatically */
  3867. adjusted_mode->crtc_vtotal -= 1;
  3868. adjusted_mode->crtc_vblank_end -= 1;
  3869. vsyncshift = adjusted_mode->crtc_hsync_start
  3870. - adjusted_mode->crtc_htotal / 2;
  3871. } else {
  3872. vsyncshift = 0;
  3873. }
  3874. if (INTEL_INFO(dev)->gen > 3)
  3875. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  3876. I915_WRITE(HTOTAL(cpu_transcoder),
  3877. (adjusted_mode->crtc_hdisplay - 1) |
  3878. ((adjusted_mode->crtc_htotal - 1) << 16));
  3879. I915_WRITE(HBLANK(cpu_transcoder),
  3880. (adjusted_mode->crtc_hblank_start - 1) |
  3881. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3882. I915_WRITE(HSYNC(cpu_transcoder),
  3883. (adjusted_mode->crtc_hsync_start - 1) |
  3884. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3885. I915_WRITE(VTOTAL(cpu_transcoder),
  3886. (adjusted_mode->crtc_vdisplay - 1) |
  3887. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3888. I915_WRITE(VBLANK(cpu_transcoder),
  3889. (adjusted_mode->crtc_vblank_start - 1) |
  3890. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3891. I915_WRITE(VSYNC(cpu_transcoder),
  3892. (adjusted_mode->crtc_vsync_start - 1) |
  3893. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3894. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  3895. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  3896. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  3897. * bits. */
  3898. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  3899. (pipe == PIPE_B || pipe == PIPE_C))
  3900. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  3901. /* pipesrc controls the size that is scaled from, which should
  3902. * always be the user's requested size.
  3903. */
  3904. I915_WRITE(PIPESRC(pipe),
  3905. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3906. }
  3907. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  3908. struct drm_display_mode *mode,
  3909. struct drm_display_mode *adjusted_mode,
  3910. int x, int y,
  3911. struct drm_framebuffer *fb)
  3912. {
  3913. struct drm_device *dev = crtc->dev;
  3914. struct drm_i915_private *dev_priv = dev->dev_private;
  3915. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3916. int pipe = intel_crtc->pipe;
  3917. int plane = intel_crtc->plane;
  3918. int refclk, num_connectors = 0;
  3919. intel_clock_t clock, reduced_clock;
  3920. u32 dspcntr, pipeconf;
  3921. bool ok, has_reduced_clock = false, is_sdvo = false;
  3922. bool is_lvds = false, is_tv = false, is_dp = false;
  3923. struct intel_encoder *encoder;
  3924. const intel_limit_t *limit;
  3925. int ret;
  3926. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3927. switch (encoder->type) {
  3928. case INTEL_OUTPUT_LVDS:
  3929. is_lvds = true;
  3930. break;
  3931. case INTEL_OUTPUT_SDVO:
  3932. case INTEL_OUTPUT_HDMI:
  3933. is_sdvo = true;
  3934. if (encoder->needs_tv_clock)
  3935. is_tv = true;
  3936. break;
  3937. case INTEL_OUTPUT_TVOUT:
  3938. is_tv = true;
  3939. break;
  3940. case INTEL_OUTPUT_DISPLAYPORT:
  3941. is_dp = true;
  3942. break;
  3943. }
  3944. num_connectors++;
  3945. }
  3946. refclk = i9xx_get_refclk(crtc, num_connectors);
  3947. /*
  3948. * Returns a set of divisors for the desired target clock with the given
  3949. * refclk, or FALSE. The returned values represent the clock equation:
  3950. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3951. */
  3952. limit = intel_limit(crtc, refclk);
  3953. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  3954. &clock);
  3955. if (!ok) {
  3956. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3957. return -EINVAL;
  3958. }
  3959. /* Ensure that the cursor is valid for the new mode before changing... */
  3960. intel_crtc_update_cursor(crtc, true);
  3961. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3962. /*
  3963. * Ensure we match the reduced clock's P to the target clock.
  3964. * If the clocks don't match, we can't switch the display clock
  3965. * by using the FP0/FP1. In such case we will disable the LVDS
  3966. * downclock feature.
  3967. */
  3968. has_reduced_clock = limit->find_pll(limit, crtc,
  3969. dev_priv->lvds_downclock,
  3970. refclk,
  3971. &clock,
  3972. &reduced_clock);
  3973. }
  3974. if (is_sdvo && is_tv)
  3975. i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
  3976. if (IS_GEN2(dev))
  3977. i8xx_update_pll(crtc, adjusted_mode, &clock,
  3978. has_reduced_clock ? &reduced_clock : NULL,
  3979. num_connectors);
  3980. else if (IS_VALLEYVIEW(dev))
  3981. vlv_update_pll(crtc, mode, adjusted_mode, &clock,
  3982. has_reduced_clock ? &reduced_clock : NULL,
  3983. num_connectors);
  3984. else
  3985. i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
  3986. has_reduced_clock ? &reduced_clock : NULL,
  3987. num_connectors);
  3988. /* setup pipeconf */
  3989. pipeconf = I915_READ(PIPECONF(pipe));
  3990. /* Set up the display plane register */
  3991. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3992. if (pipe == 0)
  3993. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3994. else
  3995. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3996. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  3997. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  3998. * core speed.
  3999. *
  4000. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  4001. * pipe == 0 check?
  4002. */
  4003. if (mode->clock >
  4004. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  4005. pipeconf |= PIPECONF_DOUBLE_WIDE;
  4006. else
  4007. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  4008. }
  4009. /* default to 8bpc */
  4010. pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
  4011. if (is_dp) {
  4012. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4013. pipeconf |= PIPECONF_6BPC |
  4014. PIPECONF_DITHER_EN |
  4015. PIPECONF_DITHER_TYPE_SP;
  4016. }
  4017. }
  4018. if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  4019. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4020. pipeconf |= PIPECONF_6BPC |
  4021. PIPECONF_ENABLE |
  4022. I965_PIPECONF_ACTIVE;
  4023. }
  4024. }
  4025. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4026. drm_mode_debug_printmodeline(mode);
  4027. if (HAS_PIPE_CXSR(dev)) {
  4028. if (intel_crtc->lowfreq_avail) {
  4029. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4030. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4031. } else {
  4032. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4033. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4034. }
  4035. }
  4036. pipeconf &= ~PIPECONF_INTERLACE_MASK;
  4037. if (!IS_GEN2(dev) &&
  4038. adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4039. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4040. else
  4041. pipeconf |= PIPECONF_PROGRESSIVE;
  4042. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4043. /* pipesrc and dspsize control the size that is scaled from,
  4044. * which should always be the user's requested size.
  4045. */
  4046. I915_WRITE(DSPSIZE(plane),
  4047. ((mode->vdisplay - 1) << 16) |
  4048. (mode->hdisplay - 1));
  4049. I915_WRITE(DSPPOS(plane), 0);
  4050. I915_WRITE(PIPECONF(pipe), pipeconf);
  4051. POSTING_READ(PIPECONF(pipe));
  4052. intel_enable_pipe(dev_priv, pipe, false);
  4053. intel_wait_for_vblank(dev, pipe);
  4054. I915_WRITE(DSPCNTR(plane), dspcntr);
  4055. POSTING_READ(DSPCNTR(plane));
  4056. ret = intel_pipe_set_base(crtc, x, y, fb);
  4057. intel_update_watermarks(dev);
  4058. return ret;
  4059. }
  4060. static void ironlake_init_pch_refclk(struct drm_device *dev)
  4061. {
  4062. struct drm_i915_private *dev_priv = dev->dev_private;
  4063. struct drm_mode_config *mode_config = &dev->mode_config;
  4064. struct intel_encoder *encoder;
  4065. u32 temp;
  4066. bool has_lvds = false;
  4067. bool has_cpu_edp = false;
  4068. bool has_pch_edp = false;
  4069. bool has_panel = false;
  4070. bool has_ck505 = false;
  4071. bool can_ssc = false;
  4072. /* We need to take the global config into account */
  4073. list_for_each_entry(encoder, &mode_config->encoder_list,
  4074. base.head) {
  4075. switch (encoder->type) {
  4076. case INTEL_OUTPUT_LVDS:
  4077. has_panel = true;
  4078. has_lvds = true;
  4079. break;
  4080. case INTEL_OUTPUT_EDP:
  4081. has_panel = true;
  4082. if (intel_encoder_is_pch_edp(&encoder->base))
  4083. has_pch_edp = true;
  4084. else
  4085. has_cpu_edp = true;
  4086. break;
  4087. }
  4088. }
  4089. if (HAS_PCH_IBX(dev)) {
  4090. has_ck505 = dev_priv->display_clock_mode;
  4091. can_ssc = has_ck505;
  4092. } else {
  4093. has_ck505 = false;
  4094. can_ssc = true;
  4095. }
  4096. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
  4097. has_panel, has_lvds, has_pch_edp, has_cpu_edp,
  4098. has_ck505);
  4099. /* Ironlake: try to setup display ref clock before DPLL
  4100. * enabling. This is only under driver's control after
  4101. * PCH B stepping, previous chipset stepping should be
  4102. * ignoring this setting.
  4103. */
  4104. temp = I915_READ(PCH_DREF_CONTROL);
  4105. /* Always enable nonspread source */
  4106. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4107. if (has_ck505)
  4108. temp |= DREF_NONSPREAD_CK505_ENABLE;
  4109. else
  4110. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4111. if (has_panel) {
  4112. temp &= ~DREF_SSC_SOURCE_MASK;
  4113. temp |= DREF_SSC_SOURCE_ENABLE;
  4114. /* SSC must be turned on before enabling the CPU output */
  4115. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4116. DRM_DEBUG_KMS("Using SSC on panel\n");
  4117. temp |= DREF_SSC1_ENABLE;
  4118. } else
  4119. temp &= ~DREF_SSC1_ENABLE;
  4120. /* Get SSC going before enabling the outputs */
  4121. I915_WRITE(PCH_DREF_CONTROL, temp);
  4122. POSTING_READ(PCH_DREF_CONTROL);
  4123. udelay(200);
  4124. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4125. /* Enable CPU source on CPU attached eDP */
  4126. if (has_cpu_edp) {
  4127. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4128. DRM_DEBUG_KMS("Using SSC on eDP\n");
  4129. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4130. }
  4131. else
  4132. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4133. } else
  4134. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4135. I915_WRITE(PCH_DREF_CONTROL, temp);
  4136. POSTING_READ(PCH_DREF_CONTROL);
  4137. udelay(200);
  4138. } else {
  4139. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  4140. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4141. /* Turn off CPU output */
  4142. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4143. I915_WRITE(PCH_DREF_CONTROL, temp);
  4144. POSTING_READ(PCH_DREF_CONTROL);
  4145. udelay(200);
  4146. /* Turn off the SSC source */
  4147. temp &= ~DREF_SSC_SOURCE_MASK;
  4148. temp |= DREF_SSC_SOURCE_DISABLE;
  4149. /* Turn off SSC1 */
  4150. temp &= ~ DREF_SSC1_ENABLE;
  4151. I915_WRITE(PCH_DREF_CONTROL, temp);
  4152. POSTING_READ(PCH_DREF_CONTROL);
  4153. udelay(200);
  4154. }
  4155. }
  4156. /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
  4157. static void lpt_init_pch_refclk(struct drm_device *dev)
  4158. {
  4159. struct drm_i915_private *dev_priv = dev->dev_private;
  4160. struct drm_mode_config *mode_config = &dev->mode_config;
  4161. struct intel_encoder *encoder;
  4162. bool has_vga = false;
  4163. bool is_sdv = false;
  4164. u32 tmp;
  4165. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  4166. switch (encoder->type) {
  4167. case INTEL_OUTPUT_ANALOG:
  4168. has_vga = true;
  4169. break;
  4170. }
  4171. }
  4172. if (!has_vga)
  4173. return;
  4174. mutex_lock(&dev_priv->dpio_lock);
  4175. /* XXX: Rip out SDV support once Haswell ships for real. */
  4176. if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
  4177. is_sdv = true;
  4178. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4179. tmp &= ~SBI_SSCCTL_DISABLE;
  4180. tmp |= SBI_SSCCTL_PATHALT;
  4181. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4182. udelay(24);
  4183. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4184. tmp &= ~SBI_SSCCTL_PATHALT;
  4185. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4186. if (!is_sdv) {
  4187. tmp = I915_READ(SOUTH_CHICKEN2);
  4188. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  4189. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4190. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  4191. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  4192. DRM_ERROR("FDI mPHY reset assert timeout\n");
  4193. tmp = I915_READ(SOUTH_CHICKEN2);
  4194. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  4195. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4196. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  4197. FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
  4198. 100))
  4199. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  4200. }
  4201. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  4202. tmp &= ~(0xFF << 24);
  4203. tmp |= (0x12 << 24);
  4204. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  4205. if (!is_sdv) {
  4206. tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
  4207. tmp &= ~(0x3 << 6);
  4208. tmp |= (1 << 6) | (1 << 0);
  4209. intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
  4210. }
  4211. if (is_sdv) {
  4212. tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
  4213. tmp |= 0x7FFF;
  4214. intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
  4215. }
  4216. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  4217. tmp |= (1 << 11);
  4218. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  4219. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  4220. tmp |= (1 << 11);
  4221. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  4222. if (is_sdv) {
  4223. tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
  4224. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4225. intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
  4226. tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
  4227. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4228. intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
  4229. tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
  4230. tmp |= (0x3F << 8);
  4231. intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
  4232. tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
  4233. tmp |= (0x3F << 8);
  4234. intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
  4235. }
  4236. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  4237. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4238. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  4239. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  4240. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4241. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  4242. if (!is_sdv) {
  4243. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  4244. tmp &= ~(7 << 13);
  4245. tmp |= (5 << 13);
  4246. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  4247. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  4248. tmp &= ~(7 << 13);
  4249. tmp |= (5 << 13);
  4250. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  4251. }
  4252. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  4253. tmp &= ~0xFF;
  4254. tmp |= 0x1C;
  4255. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  4256. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  4257. tmp &= ~0xFF;
  4258. tmp |= 0x1C;
  4259. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  4260. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  4261. tmp &= ~(0xFF << 16);
  4262. tmp |= (0x1C << 16);
  4263. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  4264. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  4265. tmp &= ~(0xFF << 16);
  4266. tmp |= (0x1C << 16);
  4267. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  4268. if (!is_sdv) {
  4269. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  4270. tmp |= (1 << 27);
  4271. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  4272. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  4273. tmp |= (1 << 27);
  4274. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  4275. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  4276. tmp &= ~(0xF << 28);
  4277. tmp |= (4 << 28);
  4278. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  4279. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  4280. tmp &= ~(0xF << 28);
  4281. tmp |= (4 << 28);
  4282. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  4283. }
  4284. /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
  4285. tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
  4286. tmp |= SBI_DBUFF0_ENABLE;
  4287. intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
  4288. mutex_unlock(&dev_priv->dpio_lock);
  4289. }
  4290. /*
  4291. * Initialize reference clocks when the driver loads
  4292. */
  4293. void intel_init_pch_refclk(struct drm_device *dev)
  4294. {
  4295. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4296. ironlake_init_pch_refclk(dev);
  4297. else if (HAS_PCH_LPT(dev))
  4298. lpt_init_pch_refclk(dev);
  4299. }
  4300. static int ironlake_get_refclk(struct drm_crtc *crtc)
  4301. {
  4302. struct drm_device *dev = crtc->dev;
  4303. struct drm_i915_private *dev_priv = dev->dev_private;
  4304. struct intel_encoder *encoder;
  4305. struct intel_encoder *edp_encoder = NULL;
  4306. int num_connectors = 0;
  4307. bool is_lvds = false;
  4308. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4309. switch (encoder->type) {
  4310. case INTEL_OUTPUT_LVDS:
  4311. is_lvds = true;
  4312. break;
  4313. case INTEL_OUTPUT_EDP:
  4314. edp_encoder = encoder;
  4315. break;
  4316. }
  4317. num_connectors++;
  4318. }
  4319. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4320. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  4321. dev_priv->lvds_ssc_freq);
  4322. return dev_priv->lvds_ssc_freq * 1000;
  4323. }
  4324. return 120000;
  4325. }
  4326. static void ironlake_set_pipeconf(struct drm_crtc *crtc,
  4327. struct drm_display_mode *adjusted_mode,
  4328. bool dither)
  4329. {
  4330. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4331. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4332. int pipe = intel_crtc->pipe;
  4333. uint32_t val;
  4334. val = I915_READ(PIPECONF(pipe));
  4335. val &= ~PIPECONF_BPC_MASK;
  4336. switch (intel_crtc->bpp) {
  4337. case 18:
  4338. val |= PIPECONF_6BPC;
  4339. break;
  4340. case 24:
  4341. val |= PIPECONF_8BPC;
  4342. break;
  4343. case 30:
  4344. val |= PIPECONF_10BPC;
  4345. break;
  4346. case 36:
  4347. val |= PIPECONF_12BPC;
  4348. break;
  4349. default:
  4350. /* Case prevented by intel_choose_pipe_bpp_dither. */
  4351. BUG();
  4352. }
  4353. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4354. if (dither)
  4355. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4356. val &= ~PIPECONF_INTERLACE_MASK;
  4357. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4358. val |= PIPECONF_INTERLACED_ILK;
  4359. else
  4360. val |= PIPECONF_PROGRESSIVE;
  4361. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4362. val |= PIPECONF_COLOR_RANGE_SELECT;
  4363. else
  4364. val &= ~PIPECONF_COLOR_RANGE_SELECT;
  4365. I915_WRITE(PIPECONF(pipe), val);
  4366. POSTING_READ(PIPECONF(pipe));
  4367. }
  4368. static void haswell_set_pipeconf(struct drm_crtc *crtc,
  4369. struct drm_display_mode *adjusted_mode,
  4370. bool dither)
  4371. {
  4372. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4373. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4374. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4375. uint32_t val;
  4376. val = I915_READ(PIPECONF(cpu_transcoder));
  4377. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4378. if (dither)
  4379. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4380. val &= ~PIPECONF_INTERLACE_MASK_HSW;
  4381. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4382. val |= PIPECONF_INTERLACED_ILK;
  4383. else
  4384. val |= PIPECONF_PROGRESSIVE;
  4385. I915_WRITE(PIPECONF(cpu_transcoder), val);
  4386. POSTING_READ(PIPECONF(cpu_transcoder));
  4387. }
  4388. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  4389. struct drm_display_mode *adjusted_mode,
  4390. intel_clock_t *clock,
  4391. bool *has_reduced_clock,
  4392. intel_clock_t *reduced_clock)
  4393. {
  4394. struct drm_device *dev = crtc->dev;
  4395. struct drm_i915_private *dev_priv = dev->dev_private;
  4396. struct intel_encoder *intel_encoder;
  4397. int refclk;
  4398. const intel_limit_t *limit;
  4399. bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
  4400. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4401. switch (intel_encoder->type) {
  4402. case INTEL_OUTPUT_LVDS:
  4403. is_lvds = true;
  4404. break;
  4405. case INTEL_OUTPUT_SDVO:
  4406. case INTEL_OUTPUT_HDMI:
  4407. is_sdvo = true;
  4408. if (intel_encoder->needs_tv_clock)
  4409. is_tv = true;
  4410. break;
  4411. case INTEL_OUTPUT_TVOUT:
  4412. is_tv = true;
  4413. break;
  4414. }
  4415. }
  4416. refclk = ironlake_get_refclk(crtc);
  4417. /*
  4418. * Returns a set of divisors for the desired target clock with the given
  4419. * refclk, or FALSE. The returned values represent the clock equation:
  4420. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  4421. */
  4422. limit = intel_limit(crtc, refclk);
  4423. ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  4424. clock);
  4425. if (!ret)
  4426. return false;
  4427. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4428. /*
  4429. * Ensure we match the reduced clock's P to the target clock.
  4430. * If the clocks don't match, we can't switch the display clock
  4431. * by using the FP0/FP1. In such case we will disable the LVDS
  4432. * downclock feature.
  4433. */
  4434. *has_reduced_clock = limit->find_pll(limit, crtc,
  4435. dev_priv->lvds_downclock,
  4436. refclk,
  4437. clock,
  4438. reduced_clock);
  4439. }
  4440. if (is_sdvo && is_tv)
  4441. i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
  4442. return true;
  4443. }
  4444. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  4445. {
  4446. struct drm_i915_private *dev_priv = dev->dev_private;
  4447. uint32_t temp;
  4448. temp = I915_READ(SOUTH_CHICKEN1);
  4449. if (temp & FDI_BC_BIFURCATION_SELECT)
  4450. return;
  4451. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  4452. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  4453. temp |= FDI_BC_BIFURCATION_SELECT;
  4454. DRM_DEBUG_KMS("enabling fdi C rx\n");
  4455. I915_WRITE(SOUTH_CHICKEN1, temp);
  4456. POSTING_READ(SOUTH_CHICKEN1);
  4457. }
  4458. static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
  4459. {
  4460. struct drm_device *dev = intel_crtc->base.dev;
  4461. struct drm_i915_private *dev_priv = dev->dev_private;
  4462. struct intel_crtc *pipe_B_crtc =
  4463. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4464. DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
  4465. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4466. if (intel_crtc->fdi_lanes > 4) {
  4467. DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
  4468. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4469. /* Clamp lanes to avoid programming the hw with bogus values. */
  4470. intel_crtc->fdi_lanes = 4;
  4471. return false;
  4472. }
  4473. if (dev_priv->num_pipe == 2)
  4474. return true;
  4475. switch (intel_crtc->pipe) {
  4476. case PIPE_A:
  4477. return true;
  4478. case PIPE_B:
  4479. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4480. intel_crtc->fdi_lanes > 2) {
  4481. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4482. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4483. /* Clamp lanes to avoid programming the hw with bogus values. */
  4484. intel_crtc->fdi_lanes = 2;
  4485. return false;
  4486. }
  4487. if (intel_crtc->fdi_lanes > 2)
  4488. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  4489. else
  4490. cpt_enable_fdi_bc_bifurcation(dev);
  4491. return true;
  4492. case PIPE_C:
  4493. if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
  4494. if (intel_crtc->fdi_lanes > 2) {
  4495. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4496. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4497. /* Clamp lanes to avoid programming the hw with bogus values. */
  4498. intel_crtc->fdi_lanes = 2;
  4499. return false;
  4500. }
  4501. } else {
  4502. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4503. return false;
  4504. }
  4505. cpt_enable_fdi_bc_bifurcation(dev);
  4506. return true;
  4507. default:
  4508. BUG();
  4509. }
  4510. }
  4511. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  4512. {
  4513. /*
  4514. * Account for spread spectrum to avoid
  4515. * oversubscribing the link. Max center spread
  4516. * is 2.5%; use 5% for safety's sake.
  4517. */
  4518. u32 bps = target_clock * bpp * 21 / 20;
  4519. return bps / (link_bw * 8) + 1;
  4520. }
  4521. static void ironlake_set_m_n(struct drm_crtc *crtc,
  4522. struct drm_display_mode *mode,
  4523. struct drm_display_mode *adjusted_mode)
  4524. {
  4525. struct drm_device *dev = crtc->dev;
  4526. struct drm_i915_private *dev_priv = dev->dev_private;
  4527. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4528. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4529. struct intel_encoder *intel_encoder, *edp_encoder = NULL;
  4530. struct intel_link_m_n m_n = {0};
  4531. int target_clock, pixel_multiplier, lane, link_bw;
  4532. bool is_dp = false, is_cpu_edp = false;
  4533. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4534. switch (intel_encoder->type) {
  4535. case INTEL_OUTPUT_DISPLAYPORT:
  4536. is_dp = true;
  4537. break;
  4538. case INTEL_OUTPUT_EDP:
  4539. is_dp = true;
  4540. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4541. is_cpu_edp = true;
  4542. edp_encoder = intel_encoder;
  4543. break;
  4544. }
  4545. }
  4546. /* FDI link */
  4547. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4548. lane = 0;
  4549. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4550. according to current link config */
  4551. if (is_cpu_edp) {
  4552. intel_edp_link_config(edp_encoder, &lane, &link_bw);
  4553. } else {
  4554. /* FDI is a binary signal running at ~2.7GHz, encoding
  4555. * each output octet as 10 bits. The actual frequency
  4556. * is stored as a divider into a 100MHz clock, and the
  4557. * mode pixel clock is stored in units of 1KHz.
  4558. * Hence the bw of each lane in terms of the mode signal
  4559. * is:
  4560. */
  4561. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4562. }
  4563. /* [e]DP over FDI requires target mode clock instead of link clock. */
  4564. if (edp_encoder)
  4565. target_clock = intel_edp_target_clock(edp_encoder, mode);
  4566. else if (is_dp)
  4567. target_clock = mode->clock;
  4568. else
  4569. target_clock = adjusted_mode->clock;
  4570. if (!lane)
  4571. lane = ironlake_get_lanes_required(target_clock, link_bw,
  4572. intel_crtc->bpp);
  4573. intel_crtc->fdi_lanes = lane;
  4574. if (pixel_multiplier > 1)
  4575. link_bw *= pixel_multiplier;
  4576. intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
  4577. I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4578. I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
  4579. I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
  4580. I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
  4581. }
  4582. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  4583. struct drm_display_mode *adjusted_mode,
  4584. intel_clock_t *clock, u32 fp)
  4585. {
  4586. struct drm_crtc *crtc = &intel_crtc->base;
  4587. struct drm_device *dev = crtc->dev;
  4588. struct drm_i915_private *dev_priv = dev->dev_private;
  4589. struct intel_encoder *intel_encoder;
  4590. uint32_t dpll;
  4591. int factor, pixel_multiplier, num_connectors = 0;
  4592. bool is_lvds = false, is_sdvo = false, is_tv = false;
  4593. bool is_dp = false, is_cpu_edp = false;
  4594. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4595. switch (intel_encoder->type) {
  4596. case INTEL_OUTPUT_LVDS:
  4597. is_lvds = true;
  4598. break;
  4599. case INTEL_OUTPUT_SDVO:
  4600. case INTEL_OUTPUT_HDMI:
  4601. is_sdvo = true;
  4602. if (intel_encoder->needs_tv_clock)
  4603. is_tv = true;
  4604. break;
  4605. case INTEL_OUTPUT_TVOUT:
  4606. is_tv = true;
  4607. break;
  4608. case INTEL_OUTPUT_DISPLAYPORT:
  4609. is_dp = true;
  4610. break;
  4611. case INTEL_OUTPUT_EDP:
  4612. is_dp = true;
  4613. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4614. is_cpu_edp = true;
  4615. break;
  4616. }
  4617. num_connectors++;
  4618. }
  4619. /* Enable autotuning of the PLL clock (if permissible) */
  4620. factor = 21;
  4621. if (is_lvds) {
  4622. if ((intel_panel_use_ssc(dev_priv) &&
  4623. dev_priv->lvds_ssc_freq == 100) ||
  4624. intel_is_dual_link_lvds(dev))
  4625. factor = 25;
  4626. } else if (is_sdvo && is_tv)
  4627. factor = 20;
  4628. if (clock->m < factor * clock->n)
  4629. fp |= FP_CB_TUNE;
  4630. dpll = 0;
  4631. if (is_lvds)
  4632. dpll |= DPLLB_MODE_LVDS;
  4633. else
  4634. dpll |= DPLLB_MODE_DAC_SERIAL;
  4635. if (is_sdvo) {
  4636. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4637. if (pixel_multiplier > 1) {
  4638. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4639. }
  4640. dpll |= DPLL_DVO_HIGH_SPEED;
  4641. }
  4642. if (is_dp && !is_cpu_edp)
  4643. dpll |= DPLL_DVO_HIGH_SPEED;
  4644. /* compute bitmask from p1 value */
  4645. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4646. /* also FPA1 */
  4647. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4648. switch (clock->p2) {
  4649. case 5:
  4650. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4651. break;
  4652. case 7:
  4653. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4654. break;
  4655. case 10:
  4656. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4657. break;
  4658. case 14:
  4659. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4660. break;
  4661. }
  4662. if (is_sdvo && is_tv)
  4663. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4664. else if (is_tv)
  4665. /* XXX: just matching BIOS for now */
  4666. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4667. dpll |= 3;
  4668. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4669. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4670. else
  4671. dpll |= PLL_REF_INPUT_DREFCLK;
  4672. return dpll;
  4673. }
  4674. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  4675. struct drm_display_mode *mode,
  4676. struct drm_display_mode *adjusted_mode,
  4677. int x, int y,
  4678. struct drm_framebuffer *fb)
  4679. {
  4680. struct drm_device *dev = crtc->dev;
  4681. struct drm_i915_private *dev_priv = dev->dev_private;
  4682. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4683. int pipe = intel_crtc->pipe;
  4684. int plane = intel_crtc->plane;
  4685. int num_connectors = 0;
  4686. intel_clock_t clock, reduced_clock;
  4687. u32 dpll, fp = 0, fp2 = 0;
  4688. bool ok, has_reduced_clock = false;
  4689. bool is_lvds = false, is_dp = false, is_cpu_edp = false;
  4690. struct intel_encoder *encoder;
  4691. int ret;
  4692. bool dither, fdi_config_ok;
  4693. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4694. switch (encoder->type) {
  4695. case INTEL_OUTPUT_LVDS:
  4696. is_lvds = true;
  4697. break;
  4698. case INTEL_OUTPUT_DISPLAYPORT:
  4699. is_dp = true;
  4700. break;
  4701. case INTEL_OUTPUT_EDP:
  4702. is_dp = true;
  4703. if (!intel_encoder_is_pch_edp(&encoder->base))
  4704. is_cpu_edp = true;
  4705. break;
  4706. }
  4707. num_connectors++;
  4708. }
  4709. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  4710. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  4711. ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
  4712. &has_reduced_clock, &reduced_clock);
  4713. if (!ok) {
  4714. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  4715. return -EINVAL;
  4716. }
  4717. /* Ensure that the cursor is valid for the new mode before changing... */
  4718. intel_crtc_update_cursor(crtc, true);
  4719. /* determine panel color depth */
  4720. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4721. adjusted_mode);
  4722. if (is_lvds && dev_priv->lvds_dither)
  4723. dither = true;
  4724. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4725. if (has_reduced_clock)
  4726. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4727. reduced_clock.m2;
  4728. dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
  4729. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4730. drm_mode_debug_printmodeline(mode);
  4731. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  4732. if (!is_cpu_edp) {
  4733. struct intel_pch_pll *pll;
  4734. pll = intel_get_pch_pll(intel_crtc, dpll, fp);
  4735. if (pll == NULL) {
  4736. DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
  4737. pipe);
  4738. return -EINVAL;
  4739. }
  4740. } else
  4741. intel_put_pch_pll(intel_crtc);
  4742. if (is_dp && !is_cpu_edp)
  4743. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4744. for_each_encoder_on_crtc(dev, crtc, encoder)
  4745. if (encoder->pre_pll_enable)
  4746. encoder->pre_pll_enable(encoder);
  4747. if (intel_crtc->pch_pll) {
  4748. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4749. /* Wait for the clocks to stabilize. */
  4750. POSTING_READ(intel_crtc->pch_pll->pll_reg);
  4751. udelay(150);
  4752. /* The pixel multiplier can only be updated once the
  4753. * DPLL is enabled and the clocks are stable.
  4754. *
  4755. * So write it again.
  4756. */
  4757. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4758. }
  4759. intel_crtc->lowfreq_avail = false;
  4760. if (intel_crtc->pch_pll) {
  4761. if (is_lvds && has_reduced_clock && i915_powersave) {
  4762. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
  4763. intel_crtc->lowfreq_avail = true;
  4764. } else {
  4765. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
  4766. }
  4767. }
  4768. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4769. /* Note, this also computes intel_crtc->fdi_lanes which is used below in
  4770. * ironlake_check_fdi_lanes. */
  4771. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4772. fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
  4773. ironlake_set_pipeconf(crtc, adjusted_mode, dither);
  4774. intel_wait_for_vblank(dev, pipe);
  4775. /* Set up the display plane register */
  4776. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4777. POSTING_READ(DSPCNTR(plane));
  4778. ret = intel_pipe_set_base(crtc, x, y, fb);
  4779. intel_update_watermarks(dev);
  4780. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4781. return fdi_config_ok ? ret : -EINVAL;
  4782. }
  4783. static void haswell_modeset_global_resources(struct drm_device *dev)
  4784. {
  4785. struct drm_i915_private *dev_priv = dev->dev_private;
  4786. bool enable = false;
  4787. struct intel_crtc *crtc;
  4788. struct intel_encoder *encoder;
  4789. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  4790. if (crtc->pipe != PIPE_A && crtc->base.enabled)
  4791. enable = true;
  4792. /* XXX: Should check for edp transcoder here, but thanks to init
  4793. * sequence that's not yet available. Just in case desktop eDP
  4794. * on PORT D is possible on haswell, too. */
  4795. }
  4796. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  4797. base.head) {
  4798. if (encoder->type != INTEL_OUTPUT_EDP &&
  4799. encoder->connectors_active)
  4800. enable = true;
  4801. }
  4802. /* Even the eDP panel fitter is outside the always-on well. */
  4803. if (dev_priv->pch_pf_size)
  4804. enable = true;
  4805. intel_set_power_well(dev, enable);
  4806. }
  4807. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  4808. struct drm_display_mode *mode,
  4809. struct drm_display_mode *adjusted_mode,
  4810. int x, int y,
  4811. struct drm_framebuffer *fb)
  4812. {
  4813. struct drm_device *dev = crtc->dev;
  4814. struct drm_i915_private *dev_priv = dev->dev_private;
  4815. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4816. int pipe = intel_crtc->pipe;
  4817. int plane = intel_crtc->plane;
  4818. int num_connectors = 0;
  4819. bool is_dp = false, is_cpu_edp = false;
  4820. struct intel_encoder *encoder;
  4821. int ret;
  4822. bool dither;
  4823. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4824. switch (encoder->type) {
  4825. case INTEL_OUTPUT_DISPLAYPORT:
  4826. is_dp = true;
  4827. break;
  4828. case INTEL_OUTPUT_EDP:
  4829. is_dp = true;
  4830. if (!intel_encoder_is_pch_edp(&encoder->base))
  4831. is_cpu_edp = true;
  4832. break;
  4833. }
  4834. num_connectors++;
  4835. }
  4836. /* We are not sure yet this won't happen. */
  4837. WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
  4838. INTEL_PCH_TYPE(dev));
  4839. WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
  4840. num_connectors, pipe_name(pipe));
  4841. WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
  4842. (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
  4843. WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
  4844. if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
  4845. return -EINVAL;
  4846. /* Ensure that the cursor is valid for the new mode before changing... */
  4847. intel_crtc_update_cursor(crtc, true);
  4848. /* determine panel color depth */
  4849. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4850. adjusted_mode);
  4851. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4852. drm_mode_debug_printmodeline(mode);
  4853. if (is_dp && !is_cpu_edp)
  4854. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4855. intel_crtc->lowfreq_avail = false;
  4856. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4857. if (!is_dp || is_cpu_edp)
  4858. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4859. haswell_set_pipeconf(crtc, adjusted_mode, dither);
  4860. /* Set up the display plane register */
  4861. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4862. POSTING_READ(DSPCNTR(plane));
  4863. ret = intel_pipe_set_base(crtc, x, y, fb);
  4864. intel_update_watermarks(dev);
  4865. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4866. return ret;
  4867. }
  4868. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  4869. struct drm_display_mode *mode,
  4870. struct drm_display_mode *adjusted_mode,
  4871. int x, int y,
  4872. struct drm_framebuffer *fb)
  4873. {
  4874. struct drm_device *dev = crtc->dev;
  4875. struct drm_i915_private *dev_priv = dev->dev_private;
  4876. struct drm_encoder_helper_funcs *encoder_funcs;
  4877. struct intel_encoder *encoder;
  4878. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4879. int pipe = intel_crtc->pipe;
  4880. int ret;
  4881. if (IS_HASWELL(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  4882. intel_crtc->cpu_transcoder = TRANSCODER_EDP;
  4883. else
  4884. intel_crtc->cpu_transcoder = pipe;
  4885. drm_vblank_pre_modeset(dev, pipe);
  4886. ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
  4887. x, y, fb);
  4888. drm_vblank_post_modeset(dev, pipe);
  4889. if (ret != 0)
  4890. return ret;
  4891. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4892. DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
  4893. encoder->base.base.id,
  4894. drm_get_encoder_name(&encoder->base),
  4895. mode->base.id, mode->name);
  4896. encoder_funcs = encoder->base.helper_private;
  4897. encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
  4898. }
  4899. return 0;
  4900. }
  4901. static bool intel_eld_uptodate(struct drm_connector *connector,
  4902. int reg_eldv, uint32_t bits_eldv,
  4903. int reg_elda, uint32_t bits_elda,
  4904. int reg_edid)
  4905. {
  4906. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4907. uint8_t *eld = connector->eld;
  4908. uint32_t i;
  4909. i = I915_READ(reg_eldv);
  4910. i &= bits_eldv;
  4911. if (!eld[0])
  4912. return !i;
  4913. if (!i)
  4914. return false;
  4915. i = I915_READ(reg_elda);
  4916. i &= ~bits_elda;
  4917. I915_WRITE(reg_elda, i);
  4918. for (i = 0; i < eld[2]; i++)
  4919. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  4920. return false;
  4921. return true;
  4922. }
  4923. static void g4x_write_eld(struct drm_connector *connector,
  4924. struct drm_crtc *crtc)
  4925. {
  4926. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4927. uint8_t *eld = connector->eld;
  4928. uint32_t eldv;
  4929. uint32_t len;
  4930. uint32_t i;
  4931. i = I915_READ(G4X_AUD_VID_DID);
  4932. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  4933. eldv = G4X_ELDV_DEVCL_DEVBLC;
  4934. else
  4935. eldv = G4X_ELDV_DEVCTG;
  4936. if (intel_eld_uptodate(connector,
  4937. G4X_AUD_CNTL_ST, eldv,
  4938. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  4939. G4X_HDMIW_HDMIEDID))
  4940. return;
  4941. i = I915_READ(G4X_AUD_CNTL_ST);
  4942. i &= ~(eldv | G4X_ELD_ADDR);
  4943. len = (i >> 9) & 0x1f; /* ELD buffer size */
  4944. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4945. if (!eld[0])
  4946. return;
  4947. len = min_t(uint8_t, eld[2], len);
  4948. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  4949. for (i = 0; i < len; i++)
  4950. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  4951. i = I915_READ(G4X_AUD_CNTL_ST);
  4952. i |= eldv;
  4953. I915_WRITE(G4X_AUD_CNTL_ST, i);
  4954. }
  4955. static void haswell_write_eld(struct drm_connector *connector,
  4956. struct drm_crtc *crtc)
  4957. {
  4958. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4959. uint8_t *eld = connector->eld;
  4960. struct drm_device *dev = crtc->dev;
  4961. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4962. uint32_t eldv;
  4963. uint32_t i;
  4964. int len;
  4965. int pipe = to_intel_crtc(crtc)->pipe;
  4966. int tmp;
  4967. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  4968. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  4969. int aud_config = HSW_AUD_CFG(pipe);
  4970. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  4971. DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
  4972. /* Audio output enable */
  4973. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  4974. tmp = I915_READ(aud_cntrl_st2);
  4975. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  4976. I915_WRITE(aud_cntrl_st2, tmp);
  4977. /* Wait for 1 vertical blank */
  4978. intel_wait_for_vblank(dev, pipe);
  4979. /* Set ELD valid state */
  4980. tmp = I915_READ(aud_cntrl_st2);
  4981. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
  4982. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  4983. I915_WRITE(aud_cntrl_st2, tmp);
  4984. tmp = I915_READ(aud_cntrl_st2);
  4985. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
  4986. /* Enable HDMI mode */
  4987. tmp = I915_READ(aud_config);
  4988. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
  4989. /* clear N_programing_enable and N_value_index */
  4990. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  4991. I915_WRITE(aud_config, tmp);
  4992. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  4993. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  4994. intel_crtc->eld_vld = true;
  4995. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  4996. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  4997. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  4998. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  4999. } else
  5000. I915_WRITE(aud_config, 0);
  5001. if (intel_eld_uptodate(connector,
  5002. aud_cntrl_st2, eldv,
  5003. aud_cntl_st, IBX_ELD_ADDRESS,
  5004. hdmiw_hdmiedid))
  5005. return;
  5006. i = I915_READ(aud_cntrl_st2);
  5007. i &= ~eldv;
  5008. I915_WRITE(aud_cntrl_st2, i);
  5009. if (!eld[0])
  5010. return;
  5011. i = I915_READ(aud_cntl_st);
  5012. i &= ~IBX_ELD_ADDRESS;
  5013. I915_WRITE(aud_cntl_st, i);
  5014. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5015. DRM_DEBUG_DRIVER("port num:%d\n", i);
  5016. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5017. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5018. for (i = 0; i < len; i++)
  5019. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5020. i = I915_READ(aud_cntrl_st2);
  5021. i |= eldv;
  5022. I915_WRITE(aud_cntrl_st2, i);
  5023. }
  5024. static void ironlake_write_eld(struct drm_connector *connector,
  5025. struct drm_crtc *crtc)
  5026. {
  5027. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  5028. uint8_t *eld = connector->eld;
  5029. uint32_t eldv;
  5030. uint32_t i;
  5031. int len;
  5032. int hdmiw_hdmiedid;
  5033. int aud_config;
  5034. int aud_cntl_st;
  5035. int aud_cntrl_st2;
  5036. int pipe = to_intel_crtc(crtc)->pipe;
  5037. if (HAS_PCH_IBX(connector->dev)) {
  5038. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  5039. aud_config = IBX_AUD_CFG(pipe);
  5040. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  5041. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  5042. } else {
  5043. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  5044. aud_config = CPT_AUD_CFG(pipe);
  5045. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  5046. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  5047. }
  5048. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  5049. i = I915_READ(aud_cntl_st);
  5050. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5051. if (!i) {
  5052. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  5053. /* operate blindly on all ports */
  5054. eldv = IBX_ELD_VALIDB;
  5055. eldv |= IBX_ELD_VALIDB << 4;
  5056. eldv |= IBX_ELD_VALIDB << 8;
  5057. } else {
  5058. DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
  5059. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  5060. }
  5061. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  5062. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  5063. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  5064. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  5065. } else
  5066. I915_WRITE(aud_config, 0);
  5067. if (intel_eld_uptodate(connector,
  5068. aud_cntrl_st2, eldv,
  5069. aud_cntl_st, IBX_ELD_ADDRESS,
  5070. hdmiw_hdmiedid))
  5071. return;
  5072. i = I915_READ(aud_cntrl_st2);
  5073. i &= ~eldv;
  5074. I915_WRITE(aud_cntrl_st2, i);
  5075. if (!eld[0])
  5076. return;
  5077. i = I915_READ(aud_cntl_st);
  5078. i &= ~IBX_ELD_ADDRESS;
  5079. I915_WRITE(aud_cntl_st, i);
  5080. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5081. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5082. for (i = 0; i < len; i++)
  5083. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5084. i = I915_READ(aud_cntrl_st2);
  5085. i |= eldv;
  5086. I915_WRITE(aud_cntrl_st2, i);
  5087. }
  5088. void intel_write_eld(struct drm_encoder *encoder,
  5089. struct drm_display_mode *mode)
  5090. {
  5091. struct drm_crtc *crtc = encoder->crtc;
  5092. struct drm_connector *connector;
  5093. struct drm_device *dev = encoder->dev;
  5094. struct drm_i915_private *dev_priv = dev->dev_private;
  5095. connector = drm_select_eld(encoder, mode);
  5096. if (!connector)
  5097. return;
  5098. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5099. connector->base.id,
  5100. drm_get_connector_name(connector),
  5101. connector->encoder->base.id,
  5102. drm_get_encoder_name(connector->encoder));
  5103. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  5104. if (dev_priv->display.write_eld)
  5105. dev_priv->display.write_eld(connector, crtc);
  5106. }
  5107. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  5108. void intel_crtc_load_lut(struct drm_crtc *crtc)
  5109. {
  5110. struct drm_device *dev = crtc->dev;
  5111. struct drm_i915_private *dev_priv = dev->dev_private;
  5112. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5113. int palreg = PALETTE(intel_crtc->pipe);
  5114. int i;
  5115. /* The clocks have to be on to load the palette. */
  5116. if (!crtc->enabled || !intel_crtc->active)
  5117. return;
  5118. /* use legacy palette for Ironlake */
  5119. if (HAS_PCH_SPLIT(dev))
  5120. palreg = LGC_PALETTE(intel_crtc->pipe);
  5121. for (i = 0; i < 256; i++) {
  5122. I915_WRITE(palreg + 4 * i,
  5123. (intel_crtc->lut_r[i] << 16) |
  5124. (intel_crtc->lut_g[i] << 8) |
  5125. intel_crtc->lut_b[i]);
  5126. }
  5127. }
  5128. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  5129. {
  5130. struct drm_device *dev = crtc->dev;
  5131. struct drm_i915_private *dev_priv = dev->dev_private;
  5132. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5133. bool visible = base != 0;
  5134. u32 cntl;
  5135. if (intel_crtc->cursor_visible == visible)
  5136. return;
  5137. cntl = I915_READ(_CURACNTR);
  5138. if (visible) {
  5139. /* On these chipsets we can only modify the base whilst
  5140. * the cursor is disabled.
  5141. */
  5142. I915_WRITE(_CURABASE, base);
  5143. cntl &= ~(CURSOR_FORMAT_MASK);
  5144. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  5145. cntl |= CURSOR_ENABLE |
  5146. CURSOR_GAMMA_ENABLE |
  5147. CURSOR_FORMAT_ARGB;
  5148. } else
  5149. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  5150. I915_WRITE(_CURACNTR, cntl);
  5151. intel_crtc->cursor_visible = visible;
  5152. }
  5153. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  5154. {
  5155. struct drm_device *dev = crtc->dev;
  5156. struct drm_i915_private *dev_priv = dev->dev_private;
  5157. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5158. int pipe = intel_crtc->pipe;
  5159. bool visible = base != 0;
  5160. if (intel_crtc->cursor_visible != visible) {
  5161. uint32_t cntl = I915_READ(CURCNTR(pipe));
  5162. if (base) {
  5163. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  5164. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5165. cntl |= pipe << 28; /* Connect to correct pipe */
  5166. } else {
  5167. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5168. cntl |= CURSOR_MODE_DISABLE;
  5169. }
  5170. I915_WRITE(CURCNTR(pipe), cntl);
  5171. intel_crtc->cursor_visible = visible;
  5172. }
  5173. /* and commit changes on next vblank */
  5174. I915_WRITE(CURBASE(pipe), base);
  5175. }
  5176. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  5177. {
  5178. struct drm_device *dev = crtc->dev;
  5179. struct drm_i915_private *dev_priv = dev->dev_private;
  5180. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5181. int pipe = intel_crtc->pipe;
  5182. bool visible = base != 0;
  5183. if (intel_crtc->cursor_visible != visible) {
  5184. uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
  5185. if (base) {
  5186. cntl &= ~CURSOR_MODE;
  5187. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5188. } else {
  5189. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5190. cntl |= CURSOR_MODE_DISABLE;
  5191. }
  5192. I915_WRITE(CURCNTR_IVB(pipe), cntl);
  5193. intel_crtc->cursor_visible = visible;
  5194. }
  5195. /* and commit changes on next vblank */
  5196. I915_WRITE(CURBASE_IVB(pipe), base);
  5197. }
  5198. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  5199. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  5200. bool on)
  5201. {
  5202. struct drm_device *dev = crtc->dev;
  5203. struct drm_i915_private *dev_priv = dev->dev_private;
  5204. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5205. int pipe = intel_crtc->pipe;
  5206. int x = intel_crtc->cursor_x;
  5207. int y = intel_crtc->cursor_y;
  5208. u32 base, pos;
  5209. bool visible;
  5210. pos = 0;
  5211. if (on && crtc->enabled && crtc->fb) {
  5212. base = intel_crtc->cursor_addr;
  5213. if (x > (int) crtc->fb->width)
  5214. base = 0;
  5215. if (y > (int) crtc->fb->height)
  5216. base = 0;
  5217. } else
  5218. base = 0;
  5219. if (x < 0) {
  5220. if (x + intel_crtc->cursor_width < 0)
  5221. base = 0;
  5222. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  5223. x = -x;
  5224. }
  5225. pos |= x << CURSOR_X_SHIFT;
  5226. if (y < 0) {
  5227. if (y + intel_crtc->cursor_height < 0)
  5228. base = 0;
  5229. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  5230. y = -y;
  5231. }
  5232. pos |= y << CURSOR_Y_SHIFT;
  5233. visible = base != 0;
  5234. if (!visible && !intel_crtc->cursor_visible)
  5235. return;
  5236. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  5237. I915_WRITE(CURPOS_IVB(pipe), pos);
  5238. ivb_update_cursor(crtc, base);
  5239. } else {
  5240. I915_WRITE(CURPOS(pipe), pos);
  5241. if (IS_845G(dev) || IS_I865G(dev))
  5242. i845_update_cursor(crtc, base);
  5243. else
  5244. i9xx_update_cursor(crtc, base);
  5245. }
  5246. }
  5247. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  5248. struct drm_file *file,
  5249. uint32_t handle,
  5250. uint32_t width, uint32_t height)
  5251. {
  5252. struct drm_device *dev = crtc->dev;
  5253. struct drm_i915_private *dev_priv = dev->dev_private;
  5254. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5255. struct drm_i915_gem_object *obj;
  5256. uint32_t addr;
  5257. int ret;
  5258. /* if we want to turn off the cursor ignore width and height */
  5259. if (!handle) {
  5260. DRM_DEBUG_KMS("cursor off\n");
  5261. addr = 0;
  5262. obj = NULL;
  5263. mutex_lock(&dev->struct_mutex);
  5264. goto finish;
  5265. }
  5266. /* Currently we only support 64x64 cursors */
  5267. if (width != 64 || height != 64) {
  5268. DRM_ERROR("we currently only support 64x64 cursors\n");
  5269. return -EINVAL;
  5270. }
  5271. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  5272. if (&obj->base == NULL)
  5273. return -ENOENT;
  5274. if (obj->base.size < width * height * 4) {
  5275. DRM_ERROR("buffer is to small\n");
  5276. ret = -ENOMEM;
  5277. goto fail;
  5278. }
  5279. /* we only need to pin inside GTT if cursor is non-phy */
  5280. mutex_lock(&dev->struct_mutex);
  5281. if (!dev_priv->info->cursor_needs_physical) {
  5282. if (obj->tiling_mode) {
  5283. DRM_ERROR("cursor cannot be tiled\n");
  5284. ret = -EINVAL;
  5285. goto fail_locked;
  5286. }
  5287. ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
  5288. if (ret) {
  5289. DRM_ERROR("failed to move cursor bo into the GTT\n");
  5290. goto fail_locked;
  5291. }
  5292. ret = i915_gem_object_put_fence(obj);
  5293. if (ret) {
  5294. DRM_ERROR("failed to release fence for cursor");
  5295. goto fail_unpin;
  5296. }
  5297. addr = obj->gtt_offset;
  5298. } else {
  5299. int align = IS_I830(dev) ? 16 * 1024 : 256;
  5300. ret = i915_gem_attach_phys_object(dev, obj,
  5301. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  5302. align);
  5303. if (ret) {
  5304. DRM_ERROR("failed to attach phys object\n");
  5305. goto fail_locked;
  5306. }
  5307. addr = obj->phys_obj->handle->busaddr;
  5308. }
  5309. if (IS_GEN2(dev))
  5310. I915_WRITE(CURSIZE, (height << 12) | width);
  5311. finish:
  5312. if (intel_crtc->cursor_bo) {
  5313. if (dev_priv->info->cursor_needs_physical) {
  5314. if (intel_crtc->cursor_bo != obj)
  5315. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  5316. } else
  5317. i915_gem_object_unpin(intel_crtc->cursor_bo);
  5318. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  5319. }
  5320. mutex_unlock(&dev->struct_mutex);
  5321. intel_crtc->cursor_addr = addr;
  5322. intel_crtc->cursor_bo = obj;
  5323. intel_crtc->cursor_width = width;
  5324. intel_crtc->cursor_height = height;
  5325. intel_crtc_update_cursor(crtc, true);
  5326. return 0;
  5327. fail_unpin:
  5328. i915_gem_object_unpin(obj);
  5329. fail_locked:
  5330. mutex_unlock(&dev->struct_mutex);
  5331. fail:
  5332. drm_gem_object_unreference_unlocked(&obj->base);
  5333. return ret;
  5334. }
  5335. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  5336. {
  5337. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5338. intel_crtc->cursor_x = x;
  5339. intel_crtc->cursor_y = y;
  5340. intel_crtc_update_cursor(crtc, true);
  5341. return 0;
  5342. }
  5343. /** Sets the color ramps on behalf of RandR */
  5344. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  5345. u16 blue, int regno)
  5346. {
  5347. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5348. intel_crtc->lut_r[regno] = red >> 8;
  5349. intel_crtc->lut_g[regno] = green >> 8;
  5350. intel_crtc->lut_b[regno] = blue >> 8;
  5351. }
  5352. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  5353. u16 *blue, int regno)
  5354. {
  5355. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5356. *red = intel_crtc->lut_r[regno] << 8;
  5357. *green = intel_crtc->lut_g[regno] << 8;
  5358. *blue = intel_crtc->lut_b[regno] << 8;
  5359. }
  5360. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  5361. u16 *blue, uint32_t start, uint32_t size)
  5362. {
  5363. int end = (start + size > 256) ? 256 : start + size, i;
  5364. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5365. for (i = start; i < end; i++) {
  5366. intel_crtc->lut_r[i] = red[i] >> 8;
  5367. intel_crtc->lut_g[i] = green[i] >> 8;
  5368. intel_crtc->lut_b[i] = blue[i] >> 8;
  5369. }
  5370. intel_crtc_load_lut(crtc);
  5371. }
  5372. /**
  5373. * Get a pipe with a simple mode set on it for doing load-based monitor
  5374. * detection.
  5375. *
  5376. * It will be up to the load-detect code to adjust the pipe as appropriate for
  5377. * its requirements. The pipe will be connected to no other encoders.
  5378. *
  5379. * Currently this code will only succeed if there is a pipe with no encoders
  5380. * configured for it. In the future, it could choose to temporarily disable
  5381. * some outputs to free up a pipe for its use.
  5382. *
  5383. * \return crtc, or NULL if no pipes are available.
  5384. */
  5385. /* VESA 640x480x72Hz mode to set on the pipe */
  5386. static struct drm_display_mode load_detect_mode = {
  5387. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  5388. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  5389. };
  5390. static struct drm_framebuffer *
  5391. intel_framebuffer_create(struct drm_device *dev,
  5392. struct drm_mode_fb_cmd2 *mode_cmd,
  5393. struct drm_i915_gem_object *obj)
  5394. {
  5395. struct intel_framebuffer *intel_fb;
  5396. int ret;
  5397. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  5398. if (!intel_fb) {
  5399. drm_gem_object_unreference_unlocked(&obj->base);
  5400. return ERR_PTR(-ENOMEM);
  5401. }
  5402. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  5403. if (ret) {
  5404. drm_gem_object_unreference_unlocked(&obj->base);
  5405. kfree(intel_fb);
  5406. return ERR_PTR(ret);
  5407. }
  5408. return &intel_fb->base;
  5409. }
  5410. static u32
  5411. intel_framebuffer_pitch_for_width(int width, int bpp)
  5412. {
  5413. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  5414. return ALIGN(pitch, 64);
  5415. }
  5416. static u32
  5417. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  5418. {
  5419. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  5420. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  5421. }
  5422. static struct drm_framebuffer *
  5423. intel_framebuffer_create_for_mode(struct drm_device *dev,
  5424. struct drm_display_mode *mode,
  5425. int depth, int bpp)
  5426. {
  5427. struct drm_i915_gem_object *obj;
  5428. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  5429. obj = i915_gem_alloc_object(dev,
  5430. intel_framebuffer_size_for_mode(mode, bpp));
  5431. if (obj == NULL)
  5432. return ERR_PTR(-ENOMEM);
  5433. mode_cmd.width = mode->hdisplay;
  5434. mode_cmd.height = mode->vdisplay;
  5435. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  5436. bpp);
  5437. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  5438. return intel_framebuffer_create(dev, &mode_cmd, obj);
  5439. }
  5440. static struct drm_framebuffer *
  5441. mode_fits_in_fbdev(struct drm_device *dev,
  5442. struct drm_display_mode *mode)
  5443. {
  5444. struct drm_i915_private *dev_priv = dev->dev_private;
  5445. struct drm_i915_gem_object *obj;
  5446. struct drm_framebuffer *fb;
  5447. if (dev_priv->fbdev == NULL)
  5448. return NULL;
  5449. obj = dev_priv->fbdev->ifb.obj;
  5450. if (obj == NULL)
  5451. return NULL;
  5452. fb = &dev_priv->fbdev->ifb.base;
  5453. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  5454. fb->bits_per_pixel))
  5455. return NULL;
  5456. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  5457. return NULL;
  5458. return fb;
  5459. }
  5460. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  5461. struct drm_display_mode *mode,
  5462. struct intel_load_detect_pipe *old)
  5463. {
  5464. struct intel_crtc *intel_crtc;
  5465. struct intel_encoder *intel_encoder =
  5466. intel_attached_encoder(connector);
  5467. struct drm_crtc *possible_crtc;
  5468. struct drm_encoder *encoder = &intel_encoder->base;
  5469. struct drm_crtc *crtc = NULL;
  5470. struct drm_device *dev = encoder->dev;
  5471. struct drm_framebuffer *fb;
  5472. int i = -1;
  5473. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5474. connector->base.id, drm_get_connector_name(connector),
  5475. encoder->base.id, drm_get_encoder_name(encoder));
  5476. /*
  5477. * Algorithm gets a little messy:
  5478. *
  5479. * - if the connector already has an assigned crtc, use it (but make
  5480. * sure it's on first)
  5481. *
  5482. * - try to find the first unused crtc that can drive this connector,
  5483. * and use that if we find one
  5484. */
  5485. /* See if we already have a CRTC for this connector */
  5486. if (encoder->crtc) {
  5487. crtc = encoder->crtc;
  5488. mutex_lock(&crtc->mutex);
  5489. old->dpms_mode = connector->dpms;
  5490. old->load_detect_temp = false;
  5491. /* Make sure the crtc and connector are running */
  5492. if (connector->dpms != DRM_MODE_DPMS_ON)
  5493. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  5494. return true;
  5495. }
  5496. /* Find an unused one (if possible) */
  5497. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  5498. i++;
  5499. if (!(encoder->possible_crtcs & (1 << i)))
  5500. continue;
  5501. if (!possible_crtc->enabled) {
  5502. crtc = possible_crtc;
  5503. break;
  5504. }
  5505. }
  5506. /*
  5507. * If we didn't find an unused CRTC, don't use any.
  5508. */
  5509. if (!crtc) {
  5510. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  5511. return false;
  5512. }
  5513. mutex_lock(&crtc->mutex);
  5514. intel_encoder->new_crtc = to_intel_crtc(crtc);
  5515. to_intel_connector(connector)->new_encoder = intel_encoder;
  5516. intel_crtc = to_intel_crtc(crtc);
  5517. old->dpms_mode = connector->dpms;
  5518. old->load_detect_temp = true;
  5519. old->release_fb = NULL;
  5520. if (!mode)
  5521. mode = &load_detect_mode;
  5522. /* We need a framebuffer large enough to accommodate all accesses
  5523. * that the plane may generate whilst we perform load detection.
  5524. * We can not rely on the fbcon either being present (we get called
  5525. * during its initialisation to detect all boot displays, or it may
  5526. * not even exist) or that it is large enough to satisfy the
  5527. * requested mode.
  5528. */
  5529. fb = mode_fits_in_fbdev(dev, mode);
  5530. if (fb == NULL) {
  5531. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  5532. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  5533. old->release_fb = fb;
  5534. } else
  5535. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  5536. if (IS_ERR(fb)) {
  5537. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  5538. mutex_unlock(&crtc->mutex);
  5539. return false;
  5540. }
  5541. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  5542. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  5543. if (old->release_fb)
  5544. old->release_fb->funcs->destroy(old->release_fb);
  5545. mutex_unlock(&crtc->mutex);
  5546. return false;
  5547. }
  5548. /* let the connector get through one full cycle before testing */
  5549. intel_wait_for_vblank(dev, intel_crtc->pipe);
  5550. return true;
  5551. }
  5552. void intel_release_load_detect_pipe(struct drm_connector *connector,
  5553. struct intel_load_detect_pipe *old)
  5554. {
  5555. struct intel_encoder *intel_encoder =
  5556. intel_attached_encoder(connector);
  5557. struct drm_encoder *encoder = &intel_encoder->base;
  5558. struct drm_crtc *crtc = encoder->crtc;
  5559. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5560. connector->base.id, drm_get_connector_name(connector),
  5561. encoder->base.id, drm_get_encoder_name(encoder));
  5562. if (old->load_detect_temp) {
  5563. to_intel_connector(connector)->new_encoder = NULL;
  5564. intel_encoder->new_crtc = NULL;
  5565. intel_set_mode(crtc, NULL, 0, 0, NULL);
  5566. if (old->release_fb) {
  5567. drm_framebuffer_unregister_private(old->release_fb);
  5568. drm_framebuffer_unreference(old->release_fb);
  5569. }
  5570. mutex_unlock(&crtc->mutex);
  5571. return;
  5572. }
  5573. /* Switch crtc and encoder back off if necessary */
  5574. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  5575. connector->funcs->dpms(connector, old->dpms_mode);
  5576. mutex_unlock(&crtc->mutex);
  5577. }
  5578. /* Returns the clock of the currently programmed mode of the given pipe. */
  5579. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  5580. {
  5581. struct drm_i915_private *dev_priv = dev->dev_private;
  5582. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5583. int pipe = intel_crtc->pipe;
  5584. u32 dpll = I915_READ(DPLL(pipe));
  5585. u32 fp;
  5586. intel_clock_t clock;
  5587. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  5588. fp = I915_READ(FP0(pipe));
  5589. else
  5590. fp = I915_READ(FP1(pipe));
  5591. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  5592. if (IS_PINEVIEW(dev)) {
  5593. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  5594. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5595. } else {
  5596. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  5597. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5598. }
  5599. if (!IS_GEN2(dev)) {
  5600. if (IS_PINEVIEW(dev))
  5601. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  5602. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  5603. else
  5604. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  5605. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5606. switch (dpll & DPLL_MODE_MASK) {
  5607. case DPLLB_MODE_DAC_SERIAL:
  5608. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  5609. 5 : 10;
  5610. break;
  5611. case DPLLB_MODE_LVDS:
  5612. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  5613. 7 : 14;
  5614. break;
  5615. default:
  5616. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  5617. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  5618. return 0;
  5619. }
  5620. /* XXX: Handle the 100Mhz refclk */
  5621. intel_clock(dev, 96000, &clock);
  5622. } else {
  5623. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  5624. if (is_lvds) {
  5625. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  5626. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5627. clock.p2 = 14;
  5628. if ((dpll & PLL_REF_INPUT_MASK) ==
  5629. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  5630. /* XXX: might not be 66MHz */
  5631. intel_clock(dev, 66000, &clock);
  5632. } else
  5633. intel_clock(dev, 48000, &clock);
  5634. } else {
  5635. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  5636. clock.p1 = 2;
  5637. else {
  5638. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  5639. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  5640. }
  5641. if (dpll & PLL_P2_DIVIDE_BY_4)
  5642. clock.p2 = 4;
  5643. else
  5644. clock.p2 = 2;
  5645. intel_clock(dev, 48000, &clock);
  5646. }
  5647. }
  5648. /* XXX: It would be nice to validate the clocks, but we can't reuse
  5649. * i830PllIsValid() because it relies on the xf86_config connector
  5650. * configuration being accurate, which it isn't necessarily.
  5651. */
  5652. return clock.dot;
  5653. }
  5654. /** Returns the currently programmed mode of the given pipe. */
  5655. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  5656. struct drm_crtc *crtc)
  5657. {
  5658. struct drm_i915_private *dev_priv = dev->dev_private;
  5659. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5660. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  5661. struct drm_display_mode *mode;
  5662. int htot = I915_READ(HTOTAL(cpu_transcoder));
  5663. int hsync = I915_READ(HSYNC(cpu_transcoder));
  5664. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  5665. int vsync = I915_READ(VSYNC(cpu_transcoder));
  5666. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  5667. if (!mode)
  5668. return NULL;
  5669. mode->clock = intel_crtc_clock_get(dev, crtc);
  5670. mode->hdisplay = (htot & 0xffff) + 1;
  5671. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  5672. mode->hsync_start = (hsync & 0xffff) + 1;
  5673. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  5674. mode->vdisplay = (vtot & 0xffff) + 1;
  5675. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  5676. mode->vsync_start = (vsync & 0xffff) + 1;
  5677. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  5678. drm_mode_set_name(mode);
  5679. return mode;
  5680. }
  5681. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5682. {
  5683. struct drm_device *dev = crtc->dev;
  5684. drm_i915_private_t *dev_priv = dev->dev_private;
  5685. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5686. int pipe = intel_crtc->pipe;
  5687. int dpll_reg = DPLL(pipe);
  5688. int dpll;
  5689. if (HAS_PCH_SPLIT(dev))
  5690. return;
  5691. if (!dev_priv->lvds_downclock_avail)
  5692. return;
  5693. dpll = I915_READ(dpll_reg);
  5694. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5695. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5696. assert_panel_unlocked(dev_priv, pipe);
  5697. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5698. I915_WRITE(dpll_reg, dpll);
  5699. intel_wait_for_vblank(dev, pipe);
  5700. dpll = I915_READ(dpll_reg);
  5701. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5702. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5703. }
  5704. }
  5705. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5706. {
  5707. struct drm_device *dev = crtc->dev;
  5708. drm_i915_private_t *dev_priv = dev->dev_private;
  5709. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5710. if (HAS_PCH_SPLIT(dev))
  5711. return;
  5712. if (!dev_priv->lvds_downclock_avail)
  5713. return;
  5714. /*
  5715. * Since this is called by a timer, we should never get here in
  5716. * the manual case.
  5717. */
  5718. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5719. int pipe = intel_crtc->pipe;
  5720. int dpll_reg = DPLL(pipe);
  5721. int dpll;
  5722. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5723. assert_panel_unlocked(dev_priv, pipe);
  5724. dpll = I915_READ(dpll_reg);
  5725. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5726. I915_WRITE(dpll_reg, dpll);
  5727. intel_wait_for_vblank(dev, pipe);
  5728. dpll = I915_READ(dpll_reg);
  5729. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5730. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5731. }
  5732. }
  5733. void intel_mark_busy(struct drm_device *dev)
  5734. {
  5735. i915_update_gfx_val(dev->dev_private);
  5736. }
  5737. void intel_mark_idle(struct drm_device *dev)
  5738. {
  5739. struct drm_crtc *crtc;
  5740. if (!i915_powersave)
  5741. return;
  5742. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5743. if (!crtc->fb)
  5744. continue;
  5745. intel_decrease_pllclock(crtc);
  5746. }
  5747. }
  5748. void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
  5749. {
  5750. struct drm_device *dev = obj->base.dev;
  5751. struct drm_crtc *crtc;
  5752. if (!i915_powersave)
  5753. return;
  5754. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5755. if (!crtc->fb)
  5756. continue;
  5757. if (to_intel_framebuffer(crtc->fb)->obj == obj)
  5758. intel_increase_pllclock(crtc);
  5759. }
  5760. }
  5761. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5762. {
  5763. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5764. struct drm_device *dev = crtc->dev;
  5765. struct intel_unpin_work *work;
  5766. unsigned long flags;
  5767. spin_lock_irqsave(&dev->event_lock, flags);
  5768. work = intel_crtc->unpin_work;
  5769. intel_crtc->unpin_work = NULL;
  5770. spin_unlock_irqrestore(&dev->event_lock, flags);
  5771. if (work) {
  5772. cancel_work_sync(&work->work);
  5773. kfree(work);
  5774. }
  5775. drm_crtc_cleanup(crtc);
  5776. kfree(intel_crtc);
  5777. }
  5778. static void intel_unpin_work_fn(struct work_struct *__work)
  5779. {
  5780. struct intel_unpin_work *work =
  5781. container_of(__work, struct intel_unpin_work, work);
  5782. struct drm_device *dev = work->crtc->dev;
  5783. mutex_lock(&dev->struct_mutex);
  5784. intel_unpin_fb_obj(work->old_fb_obj);
  5785. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5786. drm_gem_object_unreference(&work->old_fb_obj->base);
  5787. intel_update_fbc(dev);
  5788. mutex_unlock(&dev->struct_mutex);
  5789. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  5790. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  5791. kfree(work);
  5792. }
  5793. static void do_intel_finish_page_flip(struct drm_device *dev,
  5794. struct drm_crtc *crtc)
  5795. {
  5796. drm_i915_private_t *dev_priv = dev->dev_private;
  5797. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5798. struct intel_unpin_work *work;
  5799. struct drm_i915_gem_object *obj;
  5800. unsigned long flags;
  5801. /* Ignore early vblank irqs */
  5802. if (intel_crtc == NULL)
  5803. return;
  5804. spin_lock_irqsave(&dev->event_lock, flags);
  5805. work = intel_crtc->unpin_work;
  5806. /* Ensure we don't miss a work->pending update ... */
  5807. smp_rmb();
  5808. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  5809. spin_unlock_irqrestore(&dev->event_lock, flags);
  5810. return;
  5811. }
  5812. /* and that the unpin work is consistent wrt ->pending. */
  5813. smp_rmb();
  5814. intel_crtc->unpin_work = NULL;
  5815. if (work->event)
  5816. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  5817. drm_vblank_put(dev, intel_crtc->pipe);
  5818. spin_unlock_irqrestore(&dev->event_lock, flags);
  5819. obj = work->old_fb_obj;
  5820. wake_up_all(&dev_priv->pending_flip_queue);
  5821. queue_work(dev_priv->wq, &work->work);
  5822. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5823. }
  5824. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5825. {
  5826. drm_i915_private_t *dev_priv = dev->dev_private;
  5827. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5828. do_intel_finish_page_flip(dev, crtc);
  5829. }
  5830. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5831. {
  5832. drm_i915_private_t *dev_priv = dev->dev_private;
  5833. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5834. do_intel_finish_page_flip(dev, crtc);
  5835. }
  5836. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5837. {
  5838. drm_i915_private_t *dev_priv = dev->dev_private;
  5839. struct intel_crtc *intel_crtc =
  5840. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5841. unsigned long flags;
  5842. /* NB: An MMIO update of the plane base pointer will also
  5843. * generate a page-flip completion irq, i.e. every modeset
  5844. * is also accompanied by a spurious intel_prepare_page_flip().
  5845. */
  5846. spin_lock_irqsave(&dev->event_lock, flags);
  5847. if (intel_crtc->unpin_work)
  5848. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  5849. spin_unlock_irqrestore(&dev->event_lock, flags);
  5850. }
  5851. inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  5852. {
  5853. /* Ensure that the work item is consistent when activating it ... */
  5854. smp_wmb();
  5855. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  5856. /* and that it is marked active as soon as the irq could fire. */
  5857. smp_wmb();
  5858. }
  5859. static int intel_gen2_queue_flip(struct drm_device *dev,
  5860. struct drm_crtc *crtc,
  5861. struct drm_framebuffer *fb,
  5862. struct drm_i915_gem_object *obj)
  5863. {
  5864. struct drm_i915_private *dev_priv = dev->dev_private;
  5865. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5866. u32 flip_mask;
  5867. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5868. int ret;
  5869. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5870. if (ret)
  5871. goto err;
  5872. ret = intel_ring_begin(ring, 6);
  5873. if (ret)
  5874. goto err_unpin;
  5875. /* Can't queue multiple flips, so wait for the previous
  5876. * one to finish before executing the next.
  5877. */
  5878. if (intel_crtc->plane)
  5879. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5880. else
  5881. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5882. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5883. intel_ring_emit(ring, MI_NOOP);
  5884. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5885. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5886. intel_ring_emit(ring, fb->pitches[0]);
  5887. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5888. intel_ring_emit(ring, 0); /* aux display base address, unused */
  5889. intel_mark_page_flip_active(intel_crtc);
  5890. intel_ring_advance(ring);
  5891. return 0;
  5892. err_unpin:
  5893. intel_unpin_fb_obj(obj);
  5894. err:
  5895. return ret;
  5896. }
  5897. static int intel_gen3_queue_flip(struct drm_device *dev,
  5898. struct drm_crtc *crtc,
  5899. struct drm_framebuffer *fb,
  5900. struct drm_i915_gem_object *obj)
  5901. {
  5902. struct drm_i915_private *dev_priv = dev->dev_private;
  5903. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5904. u32 flip_mask;
  5905. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5906. int ret;
  5907. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5908. if (ret)
  5909. goto err;
  5910. ret = intel_ring_begin(ring, 6);
  5911. if (ret)
  5912. goto err_unpin;
  5913. if (intel_crtc->plane)
  5914. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5915. else
  5916. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5917. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5918. intel_ring_emit(ring, MI_NOOP);
  5919. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  5920. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5921. intel_ring_emit(ring, fb->pitches[0]);
  5922. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5923. intel_ring_emit(ring, MI_NOOP);
  5924. intel_mark_page_flip_active(intel_crtc);
  5925. intel_ring_advance(ring);
  5926. return 0;
  5927. err_unpin:
  5928. intel_unpin_fb_obj(obj);
  5929. err:
  5930. return ret;
  5931. }
  5932. static int intel_gen4_queue_flip(struct drm_device *dev,
  5933. struct drm_crtc *crtc,
  5934. struct drm_framebuffer *fb,
  5935. struct drm_i915_gem_object *obj)
  5936. {
  5937. struct drm_i915_private *dev_priv = dev->dev_private;
  5938. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5939. uint32_t pf, pipesrc;
  5940. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5941. int ret;
  5942. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5943. if (ret)
  5944. goto err;
  5945. ret = intel_ring_begin(ring, 4);
  5946. if (ret)
  5947. goto err_unpin;
  5948. /* i965+ uses the linear or tiled offsets from the
  5949. * Display Registers (which do not change across a page-flip)
  5950. * so we need only reprogram the base address.
  5951. */
  5952. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5953. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5954. intel_ring_emit(ring, fb->pitches[0]);
  5955. intel_ring_emit(ring,
  5956. (obj->gtt_offset + intel_crtc->dspaddr_offset) |
  5957. obj->tiling_mode);
  5958. /* XXX Enabling the panel-fitter across page-flip is so far
  5959. * untested on non-native modes, so ignore it for now.
  5960. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  5961. */
  5962. pf = 0;
  5963. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  5964. intel_ring_emit(ring, pf | pipesrc);
  5965. intel_mark_page_flip_active(intel_crtc);
  5966. intel_ring_advance(ring);
  5967. return 0;
  5968. err_unpin:
  5969. intel_unpin_fb_obj(obj);
  5970. err:
  5971. return ret;
  5972. }
  5973. static int intel_gen6_queue_flip(struct drm_device *dev,
  5974. struct drm_crtc *crtc,
  5975. struct drm_framebuffer *fb,
  5976. struct drm_i915_gem_object *obj)
  5977. {
  5978. struct drm_i915_private *dev_priv = dev->dev_private;
  5979. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5980. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5981. uint32_t pf, pipesrc;
  5982. int ret;
  5983. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5984. if (ret)
  5985. goto err;
  5986. ret = intel_ring_begin(ring, 4);
  5987. if (ret)
  5988. goto err_unpin;
  5989. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5990. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5991. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  5992. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5993. /* Contrary to the suggestions in the documentation,
  5994. * "Enable Panel Fitter" does not seem to be required when page
  5995. * flipping with a non-native mode, and worse causes a normal
  5996. * modeset to fail.
  5997. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  5998. */
  5999. pf = 0;
  6000. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  6001. intel_ring_emit(ring, pf | pipesrc);
  6002. intel_mark_page_flip_active(intel_crtc);
  6003. intel_ring_advance(ring);
  6004. return 0;
  6005. err_unpin:
  6006. intel_unpin_fb_obj(obj);
  6007. err:
  6008. return ret;
  6009. }
  6010. /*
  6011. * On gen7 we currently use the blit ring because (in early silicon at least)
  6012. * the render ring doesn't give us interrpts for page flip completion, which
  6013. * means clients will hang after the first flip is queued. Fortunately the
  6014. * blit ring generates interrupts properly, so use it instead.
  6015. */
  6016. static int intel_gen7_queue_flip(struct drm_device *dev,
  6017. struct drm_crtc *crtc,
  6018. struct drm_framebuffer *fb,
  6019. struct drm_i915_gem_object *obj)
  6020. {
  6021. struct drm_i915_private *dev_priv = dev->dev_private;
  6022. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6023. struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
  6024. uint32_t plane_bit = 0;
  6025. int ret;
  6026. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  6027. if (ret)
  6028. goto err;
  6029. switch(intel_crtc->plane) {
  6030. case PLANE_A:
  6031. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  6032. break;
  6033. case PLANE_B:
  6034. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  6035. break;
  6036. case PLANE_C:
  6037. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  6038. break;
  6039. default:
  6040. WARN_ONCE(1, "unknown plane in flip command\n");
  6041. ret = -ENODEV;
  6042. goto err_unpin;
  6043. }
  6044. ret = intel_ring_begin(ring, 4);
  6045. if (ret)
  6046. goto err_unpin;
  6047. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  6048. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  6049. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  6050. intel_ring_emit(ring, (MI_NOOP));
  6051. intel_mark_page_flip_active(intel_crtc);
  6052. intel_ring_advance(ring);
  6053. return 0;
  6054. err_unpin:
  6055. intel_unpin_fb_obj(obj);
  6056. err:
  6057. return ret;
  6058. }
  6059. static int intel_default_queue_flip(struct drm_device *dev,
  6060. struct drm_crtc *crtc,
  6061. struct drm_framebuffer *fb,
  6062. struct drm_i915_gem_object *obj)
  6063. {
  6064. return -ENODEV;
  6065. }
  6066. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  6067. struct drm_framebuffer *fb,
  6068. struct drm_pending_vblank_event *event)
  6069. {
  6070. struct drm_device *dev = crtc->dev;
  6071. struct drm_i915_private *dev_priv = dev->dev_private;
  6072. struct intel_framebuffer *intel_fb;
  6073. struct drm_i915_gem_object *obj;
  6074. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6075. struct intel_unpin_work *work;
  6076. unsigned long flags;
  6077. int ret;
  6078. /* Can't change pixel format via MI display flips. */
  6079. if (fb->pixel_format != crtc->fb->pixel_format)
  6080. return -EINVAL;
  6081. /*
  6082. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  6083. * Note that pitch changes could also affect these register.
  6084. */
  6085. if (INTEL_INFO(dev)->gen > 3 &&
  6086. (fb->offsets[0] != crtc->fb->offsets[0] ||
  6087. fb->pitches[0] != crtc->fb->pitches[0]))
  6088. return -EINVAL;
  6089. work = kzalloc(sizeof *work, GFP_KERNEL);
  6090. if (work == NULL)
  6091. return -ENOMEM;
  6092. work->event = event;
  6093. work->crtc = crtc;
  6094. intel_fb = to_intel_framebuffer(crtc->fb);
  6095. work->old_fb_obj = intel_fb->obj;
  6096. INIT_WORK(&work->work, intel_unpin_work_fn);
  6097. ret = drm_vblank_get(dev, intel_crtc->pipe);
  6098. if (ret)
  6099. goto free_work;
  6100. /* We borrow the event spin lock for protecting unpin_work */
  6101. spin_lock_irqsave(&dev->event_lock, flags);
  6102. if (intel_crtc->unpin_work) {
  6103. spin_unlock_irqrestore(&dev->event_lock, flags);
  6104. kfree(work);
  6105. drm_vblank_put(dev, intel_crtc->pipe);
  6106. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  6107. return -EBUSY;
  6108. }
  6109. intel_crtc->unpin_work = work;
  6110. spin_unlock_irqrestore(&dev->event_lock, flags);
  6111. intel_fb = to_intel_framebuffer(fb);
  6112. obj = intel_fb->obj;
  6113. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  6114. flush_workqueue(dev_priv->wq);
  6115. ret = i915_mutex_lock_interruptible(dev);
  6116. if (ret)
  6117. goto cleanup;
  6118. /* Reference the objects for the scheduled work. */
  6119. drm_gem_object_reference(&work->old_fb_obj->base);
  6120. drm_gem_object_reference(&obj->base);
  6121. crtc->fb = fb;
  6122. work->pending_flip_obj = obj;
  6123. work->enable_stall_check = true;
  6124. atomic_inc(&intel_crtc->unpin_work_count);
  6125. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  6126. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
  6127. if (ret)
  6128. goto cleanup_pending;
  6129. intel_disable_fbc(dev);
  6130. intel_mark_fb_busy(obj);
  6131. mutex_unlock(&dev->struct_mutex);
  6132. trace_i915_flip_request(intel_crtc->plane, obj);
  6133. return 0;
  6134. cleanup_pending:
  6135. atomic_dec(&intel_crtc->unpin_work_count);
  6136. drm_gem_object_unreference(&work->old_fb_obj->base);
  6137. drm_gem_object_unreference(&obj->base);
  6138. mutex_unlock(&dev->struct_mutex);
  6139. cleanup:
  6140. spin_lock_irqsave(&dev->event_lock, flags);
  6141. intel_crtc->unpin_work = NULL;
  6142. spin_unlock_irqrestore(&dev->event_lock, flags);
  6143. drm_vblank_put(dev, intel_crtc->pipe);
  6144. free_work:
  6145. kfree(work);
  6146. return ret;
  6147. }
  6148. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  6149. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  6150. .load_lut = intel_crtc_load_lut,
  6151. .disable = intel_crtc_noop,
  6152. };
  6153. bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
  6154. {
  6155. struct intel_encoder *other_encoder;
  6156. struct drm_crtc *crtc = &encoder->new_crtc->base;
  6157. if (WARN_ON(!crtc))
  6158. return false;
  6159. list_for_each_entry(other_encoder,
  6160. &crtc->dev->mode_config.encoder_list,
  6161. base.head) {
  6162. if (&other_encoder->new_crtc->base != crtc ||
  6163. encoder == other_encoder)
  6164. continue;
  6165. else
  6166. return true;
  6167. }
  6168. return false;
  6169. }
  6170. static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
  6171. struct drm_crtc *crtc)
  6172. {
  6173. struct drm_device *dev;
  6174. struct drm_crtc *tmp;
  6175. int crtc_mask = 1;
  6176. WARN(!crtc, "checking null crtc?\n");
  6177. dev = crtc->dev;
  6178. list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
  6179. if (tmp == crtc)
  6180. break;
  6181. crtc_mask <<= 1;
  6182. }
  6183. if (encoder->possible_crtcs & crtc_mask)
  6184. return true;
  6185. return false;
  6186. }
  6187. /**
  6188. * intel_modeset_update_staged_output_state
  6189. *
  6190. * Updates the staged output configuration state, e.g. after we've read out the
  6191. * current hw state.
  6192. */
  6193. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  6194. {
  6195. struct intel_encoder *encoder;
  6196. struct intel_connector *connector;
  6197. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6198. base.head) {
  6199. connector->new_encoder =
  6200. to_intel_encoder(connector->base.encoder);
  6201. }
  6202. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6203. base.head) {
  6204. encoder->new_crtc =
  6205. to_intel_crtc(encoder->base.crtc);
  6206. }
  6207. }
  6208. /**
  6209. * intel_modeset_commit_output_state
  6210. *
  6211. * This function copies the stage display pipe configuration to the real one.
  6212. */
  6213. static void intel_modeset_commit_output_state(struct drm_device *dev)
  6214. {
  6215. struct intel_encoder *encoder;
  6216. struct intel_connector *connector;
  6217. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6218. base.head) {
  6219. connector->base.encoder = &connector->new_encoder->base;
  6220. }
  6221. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6222. base.head) {
  6223. encoder->base.crtc = &encoder->new_crtc->base;
  6224. }
  6225. }
  6226. static struct drm_display_mode *
  6227. intel_modeset_adjusted_mode(struct drm_crtc *crtc,
  6228. struct drm_display_mode *mode)
  6229. {
  6230. struct drm_device *dev = crtc->dev;
  6231. struct drm_display_mode *adjusted_mode;
  6232. struct drm_encoder_helper_funcs *encoder_funcs;
  6233. struct intel_encoder *encoder;
  6234. adjusted_mode = drm_mode_duplicate(dev, mode);
  6235. if (!adjusted_mode)
  6236. return ERR_PTR(-ENOMEM);
  6237. /* Pass our mode to the connectors and the CRTC to give them a chance to
  6238. * adjust it according to limitations or connector properties, and also
  6239. * a chance to reject the mode entirely.
  6240. */
  6241. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6242. base.head) {
  6243. if (&encoder->new_crtc->base != crtc)
  6244. continue;
  6245. encoder_funcs = encoder->base.helper_private;
  6246. if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
  6247. adjusted_mode))) {
  6248. DRM_DEBUG_KMS("Encoder fixup failed\n");
  6249. goto fail;
  6250. }
  6251. }
  6252. if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
  6253. DRM_DEBUG_KMS("CRTC fixup failed\n");
  6254. goto fail;
  6255. }
  6256. DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
  6257. return adjusted_mode;
  6258. fail:
  6259. drm_mode_destroy(dev, adjusted_mode);
  6260. return ERR_PTR(-EINVAL);
  6261. }
  6262. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  6263. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  6264. static void
  6265. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  6266. unsigned *prepare_pipes, unsigned *disable_pipes)
  6267. {
  6268. struct intel_crtc *intel_crtc;
  6269. struct drm_device *dev = crtc->dev;
  6270. struct intel_encoder *encoder;
  6271. struct intel_connector *connector;
  6272. struct drm_crtc *tmp_crtc;
  6273. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  6274. /* Check which crtcs have changed outputs connected to them, these need
  6275. * to be part of the prepare_pipes mask. We don't (yet) support global
  6276. * modeset across multiple crtcs, so modeset_pipes will only have one
  6277. * bit set at most. */
  6278. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6279. base.head) {
  6280. if (connector->base.encoder == &connector->new_encoder->base)
  6281. continue;
  6282. if (connector->base.encoder) {
  6283. tmp_crtc = connector->base.encoder->crtc;
  6284. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6285. }
  6286. if (connector->new_encoder)
  6287. *prepare_pipes |=
  6288. 1 << connector->new_encoder->new_crtc->pipe;
  6289. }
  6290. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6291. base.head) {
  6292. if (encoder->base.crtc == &encoder->new_crtc->base)
  6293. continue;
  6294. if (encoder->base.crtc) {
  6295. tmp_crtc = encoder->base.crtc;
  6296. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6297. }
  6298. if (encoder->new_crtc)
  6299. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  6300. }
  6301. /* Check for any pipes that will be fully disabled ... */
  6302. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6303. base.head) {
  6304. bool used = false;
  6305. /* Don't try to disable disabled crtcs. */
  6306. if (!intel_crtc->base.enabled)
  6307. continue;
  6308. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6309. base.head) {
  6310. if (encoder->new_crtc == intel_crtc)
  6311. used = true;
  6312. }
  6313. if (!used)
  6314. *disable_pipes |= 1 << intel_crtc->pipe;
  6315. }
  6316. /* set_mode is also used to update properties on life display pipes. */
  6317. intel_crtc = to_intel_crtc(crtc);
  6318. if (crtc->enabled)
  6319. *prepare_pipes |= 1 << intel_crtc->pipe;
  6320. /* We only support modeset on one single crtc, hence we need to do that
  6321. * only for the passed in crtc iff we change anything else than just
  6322. * disable crtcs.
  6323. *
  6324. * This is actually not true, to be fully compatible with the old crtc
  6325. * helper we automatically disable _any_ output (i.e. doesn't need to be
  6326. * connected to the crtc we're modesetting on) if it's disconnected.
  6327. * Which is a rather nutty api (since changed the output configuration
  6328. * without userspace's explicit request can lead to confusion), but
  6329. * alas. Hence we currently need to modeset on all pipes we prepare. */
  6330. if (*prepare_pipes)
  6331. *modeset_pipes = *prepare_pipes;
  6332. /* ... and mask these out. */
  6333. *modeset_pipes &= ~(*disable_pipes);
  6334. *prepare_pipes &= ~(*disable_pipes);
  6335. }
  6336. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  6337. {
  6338. struct drm_encoder *encoder;
  6339. struct drm_device *dev = crtc->dev;
  6340. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  6341. if (encoder->crtc == crtc)
  6342. return true;
  6343. return false;
  6344. }
  6345. static void
  6346. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  6347. {
  6348. struct intel_encoder *intel_encoder;
  6349. struct intel_crtc *intel_crtc;
  6350. struct drm_connector *connector;
  6351. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  6352. base.head) {
  6353. if (!intel_encoder->base.crtc)
  6354. continue;
  6355. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  6356. if (prepare_pipes & (1 << intel_crtc->pipe))
  6357. intel_encoder->connectors_active = false;
  6358. }
  6359. intel_modeset_commit_output_state(dev);
  6360. /* Update computed state. */
  6361. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6362. base.head) {
  6363. intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
  6364. }
  6365. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6366. if (!connector->encoder || !connector->encoder->crtc)
  6367. continue;
  6368. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  6369. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  6370. struct drm_property *dpms_property =
  6371. dev->mode_config.dpms_property;
  6372. connector->dpms = DRM_MODE_DPMS_ON;
  6373. drm_object_property_set_value(&connector->base,
  6374. dpms_property,
  6375. DRM_MODE_DPMS_ON);
  6376. intel_encoder = to_intel_encoder(connector->encoder);
  6377. intel_encoder->connectors_active = true;
  6378. }
  6379. }
  6380. }
  6381. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  6382. list_for_each_entry((intel_crtc), \
  6383. &(dev)->mode_config.crtc_list, \
  6384. base.head) \
  6385. if (mask & (1 <<(intel_crtc)->pipe)) \
  6386. void
  6387. intel_modeset_check_state(struct drm_device *dev)
  6388. {
  6389. struct intel_crtc *crtc;
  6390. struct intel_encoder *encoder;
  6391. struct intel_connector *connector;
  6392. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6393. base.head) {
  6394. /* This also checks the encoder/connector hw state with the
  6395. * ->get_hw_state callbacks. */
  6396. intel_connector_check_state(connector);
  6397. WARN(&connector->new_encoder->base != connector->base.encoder,
  6398. "connector's staged encoder doesn't match current encoder\n");
  6399. }
  6400. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6401. base.head) {
  6402. bool enabled = false;
  6403. bool active = false;
  6404. enum pipe pipe, tracked_pipe;
  6405. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  6406. encoder->base.base.id,
  6407. drm_get_encoder_name(&encoder->base));
  6408. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  6409. "encoder's stage crtc doesn't match current crtc\n");
  6410. WARN(encoder->connectors_active && !encoder->base.crtc,
  6411. "encoder's active_connectors set, but no crtc\n");
  6412. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6413. base.head) {
  6414. if (connector->base.encoder != &encoder->base)
  6415. continue;
  6416. enabled = true;
  6417. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  6418. active = true;
  6419. }
  6420. WARN(!!encoder->base.crtc != enabled,
  6421. "encoder's enabled state mismatch "
  6422. "(expected %i, found %i)\n",
  6423. !!encoder->base.crtc, enabled);
  6424. WARN(active && !encoder->base.crtc,
  6425. "active encoder with no crtc\n");
  6426. WARN(encoder->connectors_active != active,
  6427. "encoder's computed active state doesn't match tracked active state "
  6428. "(expected %i, found %i)\n", active, encoder->connectors_active);
  6429. active = encoder->get_hw_state(encoder, &pipe);
  6430. WARN(active != encoder->connectors_active,
  6431. "encoder's hw state doesn't match sw tracking "
  6432. "(expected %i, found %i)\n",
  6433. encoder->connectors_active, active);
  6434. if (!encoder->base.crtc)
  6435. continue;
  6436. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  6437. WARN(active && pipe != tracked_pipe,
  6438. "active encoder's pipe doesn't match"
  6439. "(expected %i, found %i)\n",
  6440. tracked_pipe, pipe);
  6441. }
  6442. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  6443. base.head) {
  6444. bool enabled = false;
  6445. bool active = false;
  6446. DRM_DEBUG_KMS("[CRTC:%d]\n",
  6447. crtc->base.base.id);
  6448. WARN(crtc->active && !crtc->base.enabled,
  6449. "active crtc, but not enabled in sw tracking\n");
  6450. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6451. base.head) {
  6452. if (encoder->base.crtc != &crtc->base)
  6453. continue;
  6454. enabled = true;
  6455. if (encoder->connectors_active)
  6456. active = true;
  6457. }
  6458. WARN(active != crtc->active,
  6459. "crtc's computed active state doesn't match tracked active state "
  6460. "(expected %i, found %i)\n", active, crtc->active);
  6461. WARN(enabled != crtc->base.enabled,
  6462. "crtc's computed enabled state doesn't match tracked enabled state "
  6463. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  6464. assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
  6465. }
  6466. }
  6467. int intel_set_mode(struct drm_crtc *crtc,
  6468. struct drm_display_mode *mode,
  6469. int x, int y, struct drm_framebuffer *fb)
  6470. {
  6471. struct drm_device *dev = crtc->dev;
  6472. drm_i915_private_t *dev_priv = dev->dev_private;
  6473. struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
  6474. struct intel_crtc *intel_crtc;
  6475. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  6476. int ret = 0;
  6477. saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL);
  6478. if (!saved_mode)
  6479. return -ENOMEM;
  6480. saved_hwmode = saved_mode + 1;
  6481. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  6482. &prepare_pipes, &disable_pipes);
  6483. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  6484. modeset_pipes, prepare_pipes, disable_pipes);
  6485. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  6486. intel_crtc_disable(&intel_crtc->base);
  6487. *saved_hwmode = crtc->hwmode;
  6488. *saved_mode = crtc->mode;
  6489. /* Hack: Because we don't (yet) support global modeset on multiple
  6490. * crtcs, we don't keep track of the new mode for more than one crtc.
  6491. * Hence simply check whether any bit is set in modeset_pipes in all the
  6492. * pieces of code that are not yet converted to deal with mutliple crtcs
  6493. * changing their mode at the same time. */
  6494. adjusted_mode = NULL;
  6495. if (modeset_pipes) {
  6496. adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
  6497. if (IS_ERR(adjusted_mode)) {
  6498. ret = PTR_ERR(adjusted_mode);
  6499. goto out;
  6500. }
  6501. }
  6502. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  6503. if (intel_crtc->base.enabled)
  6504. dev_priv->display.crtc_disable(&intel_crtc->base);
  6505. }
  6506. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  6507. * to set it here already despite that we pass it down the callchain.
  6508. */
  6509. if (modeset_pipes)
  6510. crtc->mode = *mode;
  6511. /* Only after disabling all output pipelines that will be changed can we
  6512. * update the the output configuration. */
  6513. intel_modeset_update_state(dev, prepare_pipes);
  6514. if (dev_priv->display.modeset_global_resources)
  6515. dev_priv->display.modeset_global_resources(dev);
  6516. /* Set up the DPLL and any encoders state that needs to adjust or depend
  6517. * on the DPLL.
  6518. */
  6519. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  6520. ret = intel_crtc_mode_set(&intel_crtc->base,
  6521. mode, adjusted_mode,
  6522. x, y, fb);
  6523. if (ret)
  6524. goto done;
  6525. }
  6526. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  6527. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
  6528. dev_priv->display.crtc_enable(&intel_crtc->base);
  6529. if (modeset_pipes) {
  6530. /* Store real post-adjustment hardware mode. */
  6531. crtc->hwmode = *adjusted_mode;
  6532. /* Calculate and store various constants which
  6533. * are later needed by vblank and swap-completion
  6534. * timestamping. They are derived from true hwmode.
  6535. */
  6536. drm_calc_timestamping_constants(crtc);
  6537. }
  6538. /* FIXME: add subpixel order */
  6539. done:
  6540. drm_mode_destroy(dev, adjusted_mode);
  6541. if (ret && crtc->enabled) {
  6542. crtc->hwmode = *saved_hwmode;
  6543. crtc->mode = *saved_mode;
  6544. } else {
  6545. intel_modeset_check_state(dev);
  6546. }
  6547. out:
  6548. kfree(saved_mode);
  6549. return ret;
  6550. }
  6551. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  6552. {
  6553. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
  6554. }
  6555. #undef for_each_intel_crtc_masked
  6556. static void intel_set_config_free(struct intel_set_config *config)
  6557. {
  6558. if (!config)
  6559. return;
  6560. kfree(config->save_connector_encoders);
  6561. kfree(config->save_encoder_crtcs);
  6562. kfree(config);
  6563. }
  6564. static int intel_set_config_save_state(struct drm_device *dev,
  6565. struct intel_set_config *config)
  6566. {
  6567. struct drm_encoder *encoder;
  6568. struct drm_connector *connector;
  6569. int count;
  6570. config->save_encoder_crtcs =
  6571. kcalloc(dev->mode_config.num_encoder,
  6572. sizeof(struct drm_crtc *), GFP_KERNEL);
  6573. if (!config->save_encoder_crtcs)
  6574. return -ENOMEM;
  6575. config->save_connector_encoders =
  6576. kcalloc(dev->mode_config.num_connector,
  6577. sizeof(struct drm_encoder *), GFP_KERNEL);
  6578. if (!config->save_connector_encoders)
  6579. return -ENOMEM;
  6580. /* Copy data. Note that driver private data is not affected.
  6581. * Should anything bad happen only the expected state is
  6582. * restored, not the drivers personal bookkeeping.
  6583. */
  6584. count = 0;
  6585. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  6586. config->save_encoder_crtcs[count++] = encoder->crtc;
  6587. }
  6588. count = 0;
  6589. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6590. config->save_connector_encoders[count++] = connector->encoder;
  6591. }
  6592. return 0;
  6593. }
  6594. static void intel_set_config_restore_state(struct drm_device *dev,
  6595. struct intel_set_config *config)
  6596. {
  6597. struct intel_encoder *encoder;
  6598. struct intel_connector *connector;
  6599. int count;
  6600. count = 0;
  6601. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  6602. encoder->new_crtc =
  6603. to_intel_crtc(config->save_encoder_crtcs[count++]);
  6604. }
  6605. count = 0;
  6606. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  6607. connector->new_encoder =
  6608. to_intel_encoder(config->save_connector_encoders[count++]);
  6609. }
  6610. }
  6611. static void
  6612. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  6613. struct intel_set_config *config)
  6614. {
  6615. /* We should be able to check here if the fb has the same properties
  6616. * and then just flip_or_move it */
  6617. if (set->crtc->fb != set->fb) {
  6618. /* If we have no fb then treat it as a full mode set */
  6619. if (set->crtc->fb == NULL) {
  6620. DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
  6621. config->mode_changed = true;
  6622. } else if (set->fb == NULL) {
  6623. config->mode_changed = true;
  6624. } else if (set->fb->depth != set->crtc->fb->depth) {
  6625. config->mode_changed = true;
  6626. } else if (set->fb->bits_per_pixel !=
  6627. set->crtc->fb->bits_per_pixel) {
  6628. config->mode_changed = true;
  6629. } else
  6630. config->fb_changed = true;
  6631. }
  6632. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  6633. config->fb_changed = true;
  6634. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  6635. DRM_DEBUG_KMS("modes are different, full mode set\n");
  6636. drm_mode_debug_printmodeline(&set->crtc->mode);
  6637. drm_mode_debug_printmodeline(set->mode);
  6638. config->mode_changed = true;
  6639. }
  6640. }
  6641. static int
  6642. intel_modeset_stage_output_state(struct drm_device *dev,
  6643. struct drm_mode_set *set,
  6644. struct intel_set_config *config)
  6645. {
  6646. struct drm_crtc *new_crtc;
  6647. struct intel_connector *connector;
  6648. struct intel_encoder *encoder;
  6649. int count, ro;
  6650. /* The upper layers ensure that we either disable a crtc or have a list
  6651. * of connectors. For paranoia, double-check this. */
  6652. WARN_ON(!set->fb && (set->num_connectors != 0));
  6653. WARN_ON(set->fb && (set->num_connectors == 0));
  6654. count = 0;
  6655. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6656. base.head) {
  6657. /* Otherwise traverse passed in connector list and get encoders
  6658. * for them. */
  6659. for (ro = 0; ro < set->num_connectors; ro++) {
  6660. if (set->connectors[ro] == &connector->base) {
  6661. connector->new_encoder = connector->encoder;
  6662. break;
  6663. }
  6664. }
  6665. /* If we disable the crtc, disable all its connectors. Also, if
  6666. * the connector is on the changing crtc but not on the new
  6667. * connector list, disable it. */
  6668. if ((!set->fb || ro == set->num_connectors) &&
  6669. connector->base.encoder &&
  6670. connector->base.encoder->crtc == set->crtc) {
  6671. connector->new_encoder = NULL;
  6672. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  6673. connector->base.base.id,
  6674. drm_get_connector_name(&connector->base));
  6675. }
  6676. if (&connector->new_encoder->base != connector->base.encoder) {
  6677. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  6678. config->mode_changed = true;
  6679. }
  6680. }
  6681. /* connector->new_encoder is now updated for all connectors. */
  6682. /* Update crtc of enabled connectors. */
  6683. count = 0;
  6684. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6685. base.head) {
  6686. if (!connector->new_encoder)
  6687. continue;
  6688. new_crtc = connector->new_encoder->base.crtc;
  6689. for (ro = 0; ro < set->num_connectors; ro++) {
  6690. if (set->connectors[ro] == &connector->base)
  6691. new_crtc = set->crtc;
  6692. }
  6693. /* Make sure the new CRTC will work with the encoder */
  6694. if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
  6695. new_crtc)) {
  6696. return -EINVAL;
  6697. }
  6698. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  6699. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  6700. connector->base.base.id,
  6701. drm_get_connector_name(&connector->base),
  6702. new_crtc->base.id);
  6703. }
  6704. /* Check for any encoders that needs to be disabled. */
  6705. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6706. base.head) {
  6707. list_for_each_entry(connector,
  6708. &dev->mode_config.connector_list,
  6709. base.head) {
  6710. if (connector->new_encoder == encoder) {
  6711. WARN_ON(!connector->new_encoder->new_crtc);
  6712. goto next_encoder;
  6713. }
  6714. }
  6715. encoder->new_crtc = NULL;
  6716. next_encoder:
  6717. /* Only now check for crtc changes so we don't miss encoders
  6718. * that will be disabled. */
  6719. if (&encoder->new_crtc->base != encoder->base.crtc) {
  6720. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  6721. config->mode_changed = true;
  6722. }
  6723. }
  6724. /* Now we've also updated encoder->new_crtc for all encoders. */
  6725. return 0;
  6726. }
  6727. static int intel_crtc_set_config(struct drm_mode_set *set)
  6728. {
  6729. struct drm_device *dev;
  6730. struct drm_mode_set save_set;
  6731. struct intel_set_config *config;
  6732. int ret;
  6733. BUG_ON(!set);
  6734. BUG_ON(!set->crtc);
  6735. BUG_ON(!set->crtc->helper_private);
  6736. if (!set->mode)
  6737. set->fb = NULL;
  6738. /* The fb helper likes to play gross jokes with ->mode_set_config.
  6739. * Unfortunately the crtc helper doesn't do much at all for this case,
  6740. * so we have to cope with this madness until the fb helper is fixed up. */
  6741. if (set->fb && set->num_connectors == 0)
  6742. return 0;
  6743. if (set->fb) {
  6744. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  6745. set->crtc->base.id, set->fb->base.id,
  6746. (int)set->num_connectors, set->x, set->y);
  6747. } else {
  6748. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  6749. }
  6750. dev = set->crtc->dev;
  6751. ret = -ENOMEM;
  6752. config = kzalloc(sizeof(*config), GFP_KERNEL);
  6753. if (!config)
  6754. goto out_config;
  6755. ret = intel_set_config_save_state(dev, config);
  6756. if (ret)
  6757. goto out_config;
  6758. save_set.crtc = set->crtc;
  6759. save_set.mode = &set->crtc->mode;
  6760. save_set.x = set->crtc->x;
  6761. save_set.y = set->crtc->y;
  6762. save_set.fb = set->crtc->fb;
  6763. /* Compute whether we need a full modeset, only an fb base update or no
  6764. * change at all. In the future we might also check whether only the
  6765. * mode changed, e.g. for LVDS where we only change the panel fitter in
  6766. * such cases. */
  6767. intel_set_config_compute_mode_changes(set, config);
  6768. ret = intel_modeset_stage_output_state(dev, set, config);
  6769. if (ret)
  6770. goto fail;
  6771. if (config->mode_changed) {
  6772. if (set->mode) {
  6773. DRM_DEBUG_KMS("attempting to set mode from"
  6774. " userspace\n");
  6775. drm_mode_debug_printmodeline(set->mode);
  6776. }
  6777. ret = intel_set_mode(set->crtc, set->mode,
  6778. set->x, set->y, set->fb);
  6779. if (ret) {
  6780. DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
  6781. set->crtc->base.id, ret);
  6782. goto fail;
  6783. }
  6784. } else if (config->fb_changed) {
  6785. ret = intel_pipe_set_base(set->crtc,
  6786. set->x, set->y, set->fb);
  6787. }
  6788. intel_set_config_free(config);
  6789. return 0;
  6790. fail:
  6791. intel_set_config_restore_state(dev, config);
  6792. /* Try to restore the config */
  6793. if (config->mode_changed &&
  6794. intel_set_mode(save_set.crtc, save_set.mode,
  6795. save_set.x, save_set.y, save_set.fb))
  6796. DRM_ERROR("failed to restore config after modeset failure\n");
  6797. out_config:
  6798. intel_set_config_free(config);
  6799. return ret;
  6800. }
  6801. static const struct drm_crtc_funcs intel_crtc_funcs = {
  6802. .cursor_set = intel_crtc_cursor_set,
  6803. .cursor_move = intel_crtc_cursor_move,
  6804. .gamma_set = intel_crtc_gamma_set,
  6805. .set_config = intel_crtc_set_config,
  6806. .destroy = intel_crtc_destroy,
  6807. .page_flip = intel_crtc_page_flip,
  6808. };
  6809. static void intel_cpu_pll_init(struct drm_device *dev)
  6810. {
  6811. if (HAS_DDI(dev))
  6812. intel_ddi_pll_init(dev);
  6813. }
  6814. static void intel_pch_pll_init(struct drm_device *dev)
  6815. {
  6816. drm_i915_private_t *dev_priv = dev->dev_private;
  6817. int i;
  6818. if (dev_priv->num_pch_pll == 0) {
  6819. DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
  6820. return;
  6821. }
  6822. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  6823. dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
  6824. dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
  6825. dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
  6826. }
  6827. }
  6828. static void intel_crtc_init(struct drm_device *dev, int pipe)
  6829. {
  6830. drm_i915_private_t *dev_priv = dev->dev_private;
  6831. struct intel_crtc *intel_crtc;
  6832. int i;
  6833. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  6834. if (intel_crtc == NULL)
  6835. return;
  6836. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  6837. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  6838. for (i = 0; i < 256; i++) {
  6839. intel_crtc->lut_r[i] = i;
  6840. intel_crtc->lut_g[i] = i;
  6841. intel_crtc->lut_b[i] = i;
  6842. }
  6843. /* Swap pipes & planes for FBC on pre-965 */
  6844. intel_crtc->pipe = pipe;
  6845. intel_crtc->plane = pipe;
  6846. intel_crtc->cpu_transcoder = pipe;
  6847. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  6848. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  6849. intel_crtc->plane = !pipe;
  6850. }
  6851. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  6852. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  6853. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  6854. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  6855. intel_crtc->bpp = 24; /* default for pre-Ironlake */
  6856. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  6857. }
  6858. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  6859. struct drm_file *file)
  6860. {
  6861. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  6862. struct drm_mode_object *drmmode_obj;
  6863. struct intel_crtc *crtc;
  6864. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  6865. return -ENODEV;
  6866. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  6867. DRM_MODE_OBJECT_CRTC);
  6868. if (!drmmode_obj) {
  6869. DRM_ERROR("no such CRTC id\n");
  6870. return -EINVAL;
  6871. }
  6872. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  6873. pipe_from_crtc_id->pipe = crtc->pipe;
  6874. return 0;
  6875. }
  6876. static int intel_encoder_clones(struct intel_encoder *encoder)
  6877. {
  6878. struct drm_device *dev = encoder->base.dev;
  6879. struct intel_encoder *source_encoder;
  6880. int index_mask = 0;
  6881. int entry = 0;
  6882. list_for_each_entry(source_encoder,
  6883. &dev->mode_config.encoder_list, base.head) {
  6884. if (encoder == source_encoder)
  6885. index_mask |= (1 << entry);
  6886. /* Intel hw has only one MUX where enocoders could be cloned. */
  6887. if (encoder->cloneable && source_encoder->cloneable)
  6888. index_mask |= (1 << entry);
  6889. entry++;
  6890. }
  6891. return index_mask;
  6892. }
  6893. static bool has_edp_a(struct drm_device *dev)
  6894. {
  6895. struct drm_i915_private *dev_priv = dev->dev_private;
  6896. if (!IS_MOBILE(dev))
  6897. return false;
  6898. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  6899. return false;
  6900. if (IS_GEN5(dev) &&
  6901. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  6902. return false;
  6903. return true;
  6904. }
  6905. static void intel_setup_outputs(struct drm_device *dev)
  6906. {
  6907. struct drm_i915_private *dev_priv = dev->dev_private;
  6908. struct intel_encoder *encoder;
  6909. bool dpd_is_edp = false;
  6910. bool has_lvds;
  6911. has_lvds = intel_lvds_init(dev);
  6912. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  6913. /* disable the panel fitter on everything but LVDS */
  6914. I915_WRITE(PFIT_CONTROL, 0);
  6915. }
  6916. if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
  6917. intel_crt_init(dev);
  6918. if (HAS_DDI(dev)) {
  6919. int found;
  6920. /* Haswell uses DDI functions to detect digital outputs */
  6921. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  6922. /* DDI A only supports eDP */
  6923. if (found)
  6924. intel_ddi_init(dev, PORT_A);
  6925. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  6926. * register */
  6927. found = I915_READ(SFUSE_STRAP);
  6928. if (found & SFUSE_STRAP_DDIB_DETECTED)
  6929. intel_ddi_init(dev, PORT_B);
  6930. if (found & SFUSE_STRAP_DDIC_DETECTED)
  6931. intel_ddi_init(dev, PORT_C);
  6932. if (found & SFUSE_STRAP_DDID_DETECTED)
  6933. intel_ddi_init(dev, PORT_D);
  6934. } else if (HAS_PCH_SPLIT(dev)) {
  6935. int found;
  6936. dpd_is_edp = intel_dpd_is_edp(dev);
  6937. if (has_edp_a(dev))
  6938. intel_dp_init(dev, DP_A, PORT_A);
  6939. if (I915_READ(HDMIB) & PORT_DETECTED) {
  6940. /* PCH SDVOB multiplex with HDMIB */
  6941. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  6942. if (!found)
  6943. intel_hdmi_init(dev, HDMIB, PORT_B);
  6944. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  6945. intel_dp_init(dev, PCH_DP_B, PORT_B);
  6946. }
  6947. if (I915_READ(HDMIC) & PORT_DETECTED)
  6948. intel_hdmi_init(dev, HDMIC, PORT_C);
  6949. if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
  6950. intel_hdmi_init(dev, HDMID, PORT_D);
  6951. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  6952. intel_dp_init(dev, PCH_DP_C, PORT_C);
  6953. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  6954. intel_dp_init(dev, PCH_DP_D, PORT_D);
  6955. } else if (IS_VALLEYVIEW(dev)) {
  6956. /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
  6957. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  6958. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  6959. if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
  6960. intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
  6961. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  6962. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  6963. }
  6964. if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
  6965. intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
  6966. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  6967. bool found = false;
  6968. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  6969. DRM_DEBUG_KMS("probing SDVOB\n");
  6970. found = intel_sdvo_init(dev, SDVOB, true);
  6971. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  6972. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  6973. intel_hdmi_init(dev, SDVOB, PORT_B);
  6974. }
  6975. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  6976. DRM_DEBUG_KMS("probing DP_B\n");
  6977. intel_dp_init(dev, DP_B, PORT_B);
  6978. }
  6979. }
  6980. /* Before G4X SDVOC doesn't have its own detect register */
  6981. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  6982. DRM_DEBUG_KMS("probing SDVOC\n");
  6983. found = intel_sdvo_init(dev, SDVOC, false);
  6984. }
  6985. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  6986. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  6987. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  6988. intel_hdmi_init(dev, SDVOC, PORT_C);
  6989. }
  6990. if (SUPPORTS_INTEGRATED_DP(dev)) {
  6991. DRM_DEBUG_KMS("probing DP_C\n");
  6992. intel_dp_init(dev, DP_C, PORT_C);
  6993. }
  6994. }
  6995. if (SUPPORTS_INTEGRATED_DP(dev) &&
  6996. (I915_READ(DP_D) & DP_DETECTED)) {
  6997. DRM_DEBUG_KMS("probing DP_D\n");
  6998. intel_dp_init(dev, DP_D, PORT_D);
  6999. }
  7000. } else if (IS_GEN2(dev))
  7001. intel_dvo_init(dev);
  7002. if (SUPPORTS_TV(dev))
  7003. intel_tv_init(dev);
  7004. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  7005. encoder->base.possible_crtcs = encoder->crtc_mask;
  7006. encoder->base.possible_clones =
  7007. intel_encoder_clones(encoder);
  7008. }
  7009. intel_init_pch_refclk(dev);
  7010. drm_helper_move_panel_connectors_to_head(dev);
  7011. }
  7012. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  7013. {
  7014. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  7015. drm_framebuffer_cleanup(fb);
  7016. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  7017. kfree(intel_fb);
  7018. }
  7019. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  7020. struct drm_file *file,
  7021. unsigned int *handle)
  7022. {
  7023. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  7024. struct drm_i915_gem_object *obj = intel_fb->obj;
  7025. return drm_gem_handle_create(file, &obj->base, handle);
  7026. }
  7027. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  7028. .destroy = intel_user_framebuffer_destroy,
  7029. .create_handle = intel_user_framebuffer_create_handle,
  7030. };
  7031. int intel_framebuffer_init(struct drm_device *dev,
  7032. struct intel_framebuffer *intel_fb,
  7033. struct drm_mode_fb_cmd2 *mode_cmd,
  7034. struct drm_i915_gem_object *obj)
  7035. {
  7036. int ret;
  7037. if (obj->tiling_mode == I915_TILING_Y) {
  7038. DRM_DEBUG("hardware does not support tiling Y\n");
  7039. return -EINVAL;
  7040. }
  7041. if (mode_cmd->pitches[0] & 63) {
  7042. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  7043. mode_cmd->pitches[0]);
  7044. return -EINVAL;
  7045. }
  7046. /* FIXME <= Gen4 stride limits are bit unclear */
  7047. if (mode_cmd->pitches[0] > 32768) {
  7048. DRM_DEBUG("pitch (%d) must be at less than 32768\n",
  7049. mode_cmd->pitches[0]);
  7050. return -EINVAL;
  7051. }
  7052. if (obj->tiling_mode != I915_TILING_NONE &&
  7053. mode_cmd->pitches[0] != obj->stride) {
  7054. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  7055. mode_cmd->pitches[0], obj->stride);
  7056. return -EINVAL;
  7057. }
  7058. /* Reject formats not supported by any plane early. */
  7059. switch (mode_cmd->pixel_format) {
  7060. case DRM_FORMAT_C8:
  7061. case DRM_FORMAT_RGB565:
  7062. case DRM_FORMAT_XRGB8888:
  7063. case DRM_FORMAT_ARGB8888:
  7064. break;
  7065. case DRM_FORMAT_XRGB1555:
  7066. case DRM_FORMAT_ARGB1555:
  7067. if (INTEL_INFO(dev)->gen > 3) {
  7068. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7069. return -EINVAL;
  7070. }
  7071. break;
  7072. case DRM_FORMAT_XBGR8888:
  7073. case DRM_FORMAT_ABGR8888:
  7074. case DRM_FORMAT_XRGB2101010:
  7075. case DRM_FORMAT_ARGB2101010:
  7076. case DRM_FORMAT_XBGR2101010:
  7077. case DRM_FORMAT_ABGR2101010:
  7078. if (INTEL_INFO(dev)->gen < 4) {
  7079. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7080. return -EINVAL;
  7081. }
  7082. break;
  7083. case DRM_FORMAT_YUYV:
  7084. case DRM_FORMAT_UYVY:
  7085. case DRM_FORMAT_YVYU:
  7086. case DRM_FORMAT_VYUY:
  7087. if (INTEL_INFO(dev)->gen < 5) {
  7088. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7089. return -EINVAL;
  7090. }
  7091. break;
  7092. default:
  7093. DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
  7094. return -EINVAL;
  7095. }
  7096. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  7097. if (mode_cmd->offsets[0] != 0)
  7098. return -EINVAL;
  7099. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  7100. intel_fb->obj = obj;
  7101. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  7102. if (ret) {
  7103. DRM_ERROR("framebuffer init failed %d\n", ret);
  7104. return ret;
  7105. }
  7106. return 0;
  7107. }
  7108. static struct drm_framebuffer *
  7109. intel_user_framebuffer_create(struct drm_device *dev,
  7110. struct drm_file *filp,
  7111. struct drm_mode_fb_cmd2 *mode_cmd)
  7112. {
  7113. struct drm_i915_gem_object *obj;
  7114. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  7115. mode_cmd->handles[0]));
  7116. if (&obj->base == NULL)
  7117. return ERR_PTR(-ENOENT);
  7118. return intel_framebuffer_create(dev, mode_cmd, obj);
  7119. }
  7120. static const struct drm_mode_config_funcs intel_mode_funcs = {
  7121. .fb_create = intel_user_framebuffer_create,
  7122. .output_poll_changed = intel_fb_output_poll_changed,
  7123. };
  7124. /* Set up chip specific display functions */
  7125. static void intel_init_display(struct drm_device *dev)
  7126. {
  7127. struct drm_i915_private *dev_priv = dev->dev_private;
  7128. /* We always want a DPMS function */
  7129. if (HAS_DDI(dev)) {
  7130. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  7131. dev_priv->display.crtc_enable = haswell_crtc_enable;
  7132. dev_priv->display.crtc_disable = haswell_crtc_disable;
  7133. dev_priv->display.off = haswell_crtc_off;
  7134. dev_priv->display.update_plane = ironlake_update_plane;
  7135. } else if (HAS_PCH_SPLIT(dev)) {
  7136. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  7137. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  7138. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  7139. dev_priv->display.off = ironlake_crtc_off;
  7140. dev_priv->display.update_plane = ironlake_update_plane;
  7141. } else {
  7142. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  7143. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  7144. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  7145. dev_priv->display.off = i9xx_crtc_off;
  7146. dev_priv->display.update_plane = i9xx_update_plane;
  7147. }
  7148. /* Returns the core display clock speed */
  7149. if (IS_VALLEYVIEW(dev))
  7150. dev_priv->display.get_display_clock_speed =
  7151. valleyview_get_display_clock_speed;
  7152. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  7153. dev_priv->display.get_display_clock_speed =
  7154. i945_get_display_clock_speed;
  7155. else if (IS_I915G(dev))
  7156. dev_priv->display.get_display_clock_speed =
  7157. i915_get_display_clock_speed;
  7158. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  7159. dev_priv->display.get_display_clock_speed =
  7160. i9xx_misc_get_display_clock_speed;
  7161. else if (IS_I915GM(dev))
  7162. dev_priv->display.get_display_clock_speed =
  7163. i915gm_get_display_clock_speed;
  7164. else if (IS_I865G(dev))
  7165. dev_priv->display.get_display_clock_speed =
  7166. i865_get_display_clock_speed;
  7167. else if (IS_I85X(dev))
  7168. dev_priv->display.get_display_clock_speed =
  7169. i855_get_display_clock_speed;
  7170. else /* 852, 830 */
  7171. dev_priv->display.get_display_clock_speed =
  7172. i830_get_display_clock_speed;
  7173. if (HAS_PCH_SPLIT(dev)) {
  7174. if (IS_GEN5(dev)) {
  7175. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  7176. dev_priv->display.write_eld = ironlake_write_eld;
  7177. } else if (IS_GEN6(dev)) {
  7178. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  7179. dev_priv->display.write_eld = ironlake_write_eld;
  7180. } else if (IS_IVYBRIDGE(dev)) {
  7181. /* FIXME: detect B0+ stepping and use auto training */
  7182. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  7183. dev_priv->display.write_eld = ironlake_write_eld;
  7184. dev_priv->display.modeset_global_resources =
  7185. ivb_modeset_global_resources;
  7186. } else if (IS_HASWELL(dev)) {
  7187. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  7188. dev_priv->display.write_eld = haswell_write_eld;
  7189. dev_priv->display.modeset_global_resources =
  7190. haswell_modeset_global_resources;
  7191. }
  7192. } else if (IS_G4X(dev)) {
  7193. dev_priv->display.write_eld = g4x_write_eld;
  7194. }
  7195. /* Default just returns -ENODEV to indicate unsupported */
  7196. dev_priv->display.queue_flip = intel_default_queue_flip;
  7197. switch (INTEL_INFO(dev)->gen) {
  7198. case 2:
  7199. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  7200. break;
  7201. case 3:
  7202. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  7203. break;
  7204. case 4:
  7205. case 5:
  7206. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  7207. break;
  7208. case 6:
  7209. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  7210. break;
  7211. case 7:
  7212. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  7213. break;
  7214. }
  7215. }
  7216. /*
  7217. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  7218. * resume, or other times. This quirk makes sure that's the case for
  7219. * affected systems.
  7220. */
  7221. static void quirk_pipea_force(struct drm_device *dev)
  7222. {
  7223. struct drm_i915_private *dev_priv = dev->dev_private;
  7224. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  7225. DRM_INFO("applying pipe a force quirk\n");
  7226. }
  7227. /*
  7228. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  7229. */
  7230. static void quirk_ssc_force_disable(struct drm_device *dev)
  7231. {
  7232. struct drm_i915_private *dev_priv = dev->dev_private;
  7233. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  7234. DRM_INFO("applying lvds SSC disable quirk\n");
  7235. }
  7236. /*
  7237. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  7238. * brightness value
  7239. */
  7240. static void quirk_invert_brightness(struct drm_device *dev)
  7241. {
  7242. struct drm_i915_private *dev_priv = dev->dev_private;
  7243. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  7244. DRM_INFO("applying inverted panel brightness quirk\n");
  7245. }
  7246. struct intel_quirk {
  7247. int device;
  7248. int subsystem_vendor;
  7249. int subsystem_device;
  7250. void (*hook)(struct drm_device *dev);
  7251. };
  7252. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  7253. struct intel_dmi_quirk {
  7254. void (*hook)(struct drm_device *dev);
  7255. const struct dmi_system_id (*dmi_id_list)[];
  7256. };
  7257. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  7258. {
  7259. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  7260. return 1;
  7261. }
  7262. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  7263. {
  7264. .dmi_id_list = &(const struct dmi_system_id[]) {
  7265. {
  7266. .callback = intel_dmi_reverse_brightness,
  7267. .ident = "NCR Corporation",
  7268. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  7269. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  7270. },
  7271. },
  7272. { } /* terminating entry */
  7273. },
  7274. .hook = quirk_invert_brightness,
  7275. },
  7276. };
  7277. static struct intel_quirk intel_quirks[] = {
  7278. /* HP Mini needs pipe A force quirk (LP: #322104) */
  7279. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  7280. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  7281. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  7282. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  7283. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  7284. /* 830/845 need to leave pipe A & dpll A up */
  7285. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7286. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7287. /* Lenovo U160 cannot use SSC on LVDS */
  7288. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  7289. /* Sony Vaio Y cannot use SSC on LVDS */
  7290. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  7291. /* Acer Aspire 5734Z must invert backlight brightness */
  7292. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  7293. /* Acer/eMachines G725 */
  7294. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  7295. /* Acer/eMachines e725 */
  7296. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  7297. /* Acer/Packard Bell NCL20 */
  7298. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  7299. };
  7300. static void intel_init_quirks(struct drm_device *dev)
  7301. {
  7302. struct pci_dev *d = dev->pdev;
  7303. int i;
  7304. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  7305. struct intel_quirk *q = &intel_quirks[i];
  7306. if (d->device == q->device &&
  7307. (d->subsystem_vendor == q->subsystem_vendor ||
  7308. q->subsystem_vendor == PCI_ANY_ID) &&
  7309. (d->subsystem_device == q->subsystem_device ||
  7310. q->subsystem_device == PCI_ANY_ID))
  7311. q->hook(dev);
  7312. }
  7313. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  7314. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  7315. intel_dmi_quirks[i].hook(dev);
  7316. }
  7317. }
  7318. /* Disable the VGA plane that we never use */
  7319. static void i915_disable_vga(struct drm_device *dev)
  7320. {
  7321. struct drm_i915_private *dev_priv = dev->dev_private;
  7322. u8 sr1;
  7323. u32 vga_reg = i915_vgacntrl_reg(dev);
  7324. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  7325. outb(SR01, VGA_SR_INDEX);
  7326. sr1 = inb(VGA_SR_DATA);
  7327. outb(sr1 | 1<<5, VGA_SR_DATA);
  7328. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  7329. udelay(300);
  7330. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  7331. POSTING_READ(vga_reg);
  7332. }
  7333. void intel_modeset_init_hw(struct drm_device *dev)
  7334. {
  7335. intel_init_power_well(dev);
  7336. intel_prepare_ddi(dev);
  7337. intel_init_clock_gating(dev);
  7338. mutex_lock(&dev->struct_mutex);
  7339. intel_enable_gt_powersave(dev);
  7340. mutex_unlock(&dev->struct_mutex);
  7341. }
  7342. void intel_modeset_init(struct drm_device *dev)
  7343. {
  7344. struct drm_i915_private *dev_priv = dev->dev_private;
  7345. int i, ret;
  7346. drm_mode_config_init(dev);
  7347. dev->mode_config.min_width = 0;
  7348. dev->mode_config.min_height = 0;
  7349. dev->mode_config.preferred_depth = 24;
  7350. dev->mode_config.prefer_shadow = 1;
  7351. dev->mode_config.funcs = &intel_mode_funcs;
  7352. intel_init_quirks(dev);
  7353. intel_init_pm(dev);
  7354. intel_init_display(dev);
  7355. if (IS_GEN2(dev)) {
  7356. dev->mode_config.max_width = 2048;
  7357. dev->mode_config.max_height = 2048;
  7358. } else if (IS_GEN3(dev)) {
  7359. dev->mode_config.max_width = 4096;
  7360. dev->mode_config.max_height = 4096;
  7361. } else {
  7362. dev->mode_config.max_width = 8192;
  7363. dev->mode_config.max_height = 8192;
  7364. }
  7365. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  7366. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  7367. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  7368. for (i = 0; i < dev_priv->num_pipe; i++) {
  7369. intel_crtc_init(dev, i);
  7370. ret = intel_plane_init(dev, i);
  7371. if (ret)
  7372. DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
  7373. }
  7374. intel_cpu_pll_init(dev);
  7375. intel_pch_pll_init(dev);
  7376. /* Just disable it once at startup */
  7377. i915_disable_vga(dev);
  7378. intel_setup_outputs(dev);
  7379. /* Just in case the BIOS is doing something questionable. */
  7380. intel_disable_fbc(dev);
  7381. }
  7382. static void
  7383. intel_connector_break_all_links(struct intel_connector *connector)
  7384. {
  7385. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7386. connector->base.encoder = NULL;
  7387. connector->encoder->connectors_active = false;
  7388. connector->encoder->base.crtc = NULL;
  7389. }
  7390. static void intel_enable_pipe_a(struct drm_device *dev)
  7391. {
  7392. struct intel_connector *connector;
  7393. struct drm_connector *crt = NULL;
  7394. struct intel_load_detect_pipe load_detect_temp;
  7395. /* We can't just switch on the pipe A, we need to set things up with a
  7396. * proper mode and output configuration. As a gross hack, enable pipe A
  7397. * by enabling the load detect pipe once. */
  7398. list_for_each_entry(connector,
  7399. &dev->mode_config.connector_list,
  7400. base.head) {
  7401. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  7402. crt = &connector->base;
  7403. break;
  7404. }
  7405. }
  7406. if (!crt)
  7407. return;
  7408. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
  7409. intel_release_load_detect_pipe(crt, &load_detect_temp);
  7410. }
  7411. static bool
  7412. intel_check_plane_mapping(struct intel_crtc *crtc)
  7413. {
  7414. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  7415. u32 reg, val;
  7416. if (dev_priv->num_pipe == 1)
  7417. return true;
  7418. reg = DSPCNTR(!crtc->plane);
  7419. val = I915_READ(reg);
  7420. if ((val & DISPLAY_PLANE_ENABLE) &&
  7421. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  7422. return false;
  7423. return true;
  7424. }
  7425. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  7426. {
  7427. struct drm_device *dev = crtc->base.dev;
  7428. struct drm_i915_private *dev_priv = dev->dev_private;
  7429. u32 reg;
  7430. /* Clear any frame start delays used for debugging left by the BIOS */
  7431. reg = PIPECONF(crtc->cpu_transcoder);
  7432. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  7433. /* We need to sanitize the plane -> pipe mapping first because this will
  7434. * disable the crtc (and hence change the state) if it is wrong. Note
  7435. * that gen4+ has a fixed plane -> pipe mapping. */
  7436. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  7437. struct intel_connector *connector;
  7438. bool plane;
  7439. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  7440. crtc->base.base.id);
  7441. /* Pipe has the wrong plane attached and the plane is active.
  7442. * Temporarily change the plane mapping and disable everything
  7443. * ... */
  7444. plane = crtc->plane;
  7445. crtc->plane = !plane;
  7446. dev_priv->display.crtc_disable(&crtc->base);
  7447. crtc->plane = plane;
  7448. /* ... and break all links. */
  7449. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7450. base.head) {
  7451. if (connector->encoder->base.crtc != &crtc->base)
  7452. continue;
  7453. intel_connector_break_all_links(connector);
  7454. }
  7455. WARN_ON(crtc->active);
  7456. crtc->base.enabled = false;
  7457. }
  7458. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  7459. crtc->pipe == PIPE_A && !crtc->active) {
  7460. /* BIOS forgot to enable pipe A, this mostly happens after
  7461. * resume. Force-enable the pipe to fix this, the update_dpms
  7462. * call below we restore the pipe to the right state, but leave
  7463. * the required bits on. */
  7464. intel_enable_pipe_a(dev);
  7465. }
  7466. /* Adjust the state of the output pipe according to whether we
  7467. * have active connectors/encoders. */
  7468. intel_crtc_update_dpms(&crtc->base);
  7469. if (crtc->active != crtc->base.enabled) {
  7470. struct intel_encoder *encoder;
  7471. /* This can happen either due to bugs in the get_hw_state
  7472. * functions or because the pipe is force-enabled due to the
  7473. * pipe A quirk. */
  7474. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  7475. crtc->base.base.id,
  7476. crtc->base.enabled ? "enabled" : "disabled",
  7477. crtc->active ? "enabled" : "disabled");
  7478. crtc->base.enabled = crtc->active;
  7479. /* Because we only establish the connector -> encoder ->
  7480. * crtc links if something is active, this means the
  7481. * crtc is now deactivated. Break the links. connector
  7482. * -> encoder links are only establish when things are
  7483. * actually up, hence no need to break them. */
  7484. WARN_ON(crtc->active);
  7485. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  7486. WARN_ON(encoder->connectors_active);
  7487. encoder->base.crtc = NULL;
  7488. }
  7489. }
  7490. }
  7491. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  7492. {
  7493. struct intel_connector *connector;
  7494. struct drm_device *dev = encoder->base.dev;
  7495. /* We need to check both for a crtc link (meaning that the
  7496. * encoder is active and trying to read from a pipe) and the
  7497. * pipe itself being active. */
  7498. bool has_active_crtc = encoder->base.crtc &&
  7499. to_intel_crtc(encoder->base.crtc)->active;
  7500. if (encoder->connectors_active && !has_active_crtc) {
  7501. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  7502. encoder->base.base.id,
  7503. drm_get_encoder_name(&encoder->base));
  7504. /* Connector is active, but has no active pipe. This is
  7505. * fallout from our resume register restoring. Disable
  7506. * the encoder manually again. */
  7507. if (encoder->base.crtc) {
  7508. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  7509. encoder->base.base.id,
  7510. drm_get_encoder_name(&encoder->base));
  7511. encoder->disable(encoder);
  7512. }
  7513. /* Inconsistent output/port/pipe state happens presumably due to
  7514. * a bug in one of the get_hw_state functions. Or someplace else
  7515. * in our code, like the register restore mess on resume. Clamp
  7516. * things to off as a safer default. */
  7517. list_for_each_entry(connector,
  7518. &dev->mode_config.connector_list,
  7519. base.head) {
  7520. if (connector->encoder != encoder)
  7521. continue;
  7522. intel_connector_break_all_links(connector);
  7523. }
  7524. }
  7525. /* Enabled encoders without active connectors will be fixed in
  7526. * the crtc fixup. */
  7527. }
  7528. void i915_redisable_vga(struct drm_device *dev)
  7529. {
  7530. struct drm_i915_private *dev_priv = dev->dev_private;
  7531. u32 vga_reg = i915_vgacntrl_reg(dev);
  7532. if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
  7533. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  7534. i915_disable_vga(dev);
  7535. }
  7536. }
  7537. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  7538. * and i915 state tracking structures. */
  7539. void intel_modeset_setup_hw_state(struct drm_device *dev,
  7540. bool force_restore)
  7541. {
  7542. struct drm_i915_private *dev_priv = dev->dev_private;
  7543. enum pipe pipe;
  7544. u32 tmp;
  7545. struct intel_crtc *crtc;
  7546. struct intel_encoder *encoder;
  7547. struct intel_connector *connector;
  7548. if (HAS_DDI(dev)) {
  7549. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  7550. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  7551. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  7552. case TRANS_DDI_EDP_INPUT_A_ON:
  7553. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  7554. pipe = PIPE_A;
  7555. break;
  7556. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  7557. pipe = PIPE_B;
  7558. break;
  7559. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  7560. pipe = PIPE_C;
  7561. break;
  7562. }
  7563. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7564. crtc->cpu_transcoder = TRANSCODER_EDP;
  7565. DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
  7566. pipe_name(pipe));
  7567. }
  7568. }
  7569. for_each_pipe(pipe) {
  7570. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7571. tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
  7572. if (tmp & PIPECONF_ENABLE)
  7573. crtc->active = true;
  7574. else
  7575. crtc->active = false;
  7576. crtc->base.enabled = crtc->active;
  7577. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  7578. crtc->base.base.id,
  7579. crtc->active ? "enabled" : "disabled");
  7580. }
  7581. if (HAS_DDI(dev))
  7582. intel_ddi_setup_hw_pll_state(dev);
  7583. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7584. base.head) {
  7585. pipe = 0;
  7586. if (encoder->get_hw_state(encoder, &pipe)) {
  7587. encoder->base.crtc =
  7588. dev_priv->pipe_to_crtc_mapping[pipe];
  7589. } else {
  7590. encoder->base.crtc = NULL;
  7591. }
  7592. encoder->connectors_active = false;
  7593. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
  7594. encoder->base.base.id,
  7595. drm_get_encoder_name(&encoder->base),
  7596. encoder->base.crtc ? "enabled" : "disabled",
  7597. pipe);
  7598. }
  7599. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7600. base.head) {
  7601. if (connector->get_hw_state(connector)) {
  7602. connector->base.dpms = DRM_MODE_DPMS_ON;
  7603. connector->encoder->connectors_active = true;
  7604. connector->base.encoder = &connector->encoder->base;
  7605. } else {
  7606. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7607. connector->base.encoder = NULL;
  7608. }
  7609. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  7610. connector->base.base.id,
  7611. drm_get_connector_name(&connector->base),
  7612. connector->base.encoder ? "enabled" : "disabled");
  7613. }
  7614. /* HW state is read out, now we need to sanitize this mess. */
  7615. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7616. base.head) {
  7617. intel_sanitize_encoder(encoder);
  7618. }
  7619. for_each_pipe(pipe) {
  7620. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7621. intel_sanitize_crtc(crtc);
  7622. }
  7623. if (force_restore) {
  7624. for_each_pipe(pipe) {
  7625. intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
  7626. }
  7627. i915_redisable_vga(dev);
  7628. } else {
  7629. intel_modeset_update_staged_output_state(dev);
  7630. }
  7631. intel_modeset_check_state(dev);
  7632. drm_mode_config_reset(dev);
  7633. }
  7634. void intel_modeset_gem_init(struct drm_device *dev)
  7635. {
  7636. intel_modeset_init_hw(dev);
  7637. intel_setup_overlay(dev);
  7638. intel_modeset_setup_hw_state(dev, false);
  7639. }
  7640. void intel_modeset_cleanup(struct drm_device *dev)
  7641. {
  7642. struct drm_i915_private *dev_priv = dev->dev_private;
  7643. struct drm_crtc *crtc;
  7644. struct intel_crtc *intel_crtc;
  7645. drm_kms_helper_poll_fini(dev);
  7646. mutex_lock(&dev->struct_mutex);
  7647. intel_unregister_dsm_handler();
  7648. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  7649. /* Skip inactive CRTCs */
  7650. if (!crtc->fb)
  7651. continue;
  7652. intel_crtc = to_intel_crtc(crtc);
  7653. intel_increase_pllclock(crtc);
  7654. }
  7655. intel_disable_fbc(dev);
  7656. intel_disable_gt_powersave(dev);
  7657. ironlake_teardown_rc6(dev);
  7658. if (IS_VALLEYVIEW(dev))
  7659. vlv_init_dpio(dev);
  7660. mutex_unlock(&dev->struct_mutex);
  7661. /* Disable the irq before mode object teardown, for the irq might
  7662. * enqueue unpin/hotplug work. */
  7663. drm_irq_uninstall(dev);
  7664. cancel_work_sync(&dev_priv->hotplug_work);
  7665. cancel_work_sync(&dev_priv->rps.work);
  7666. /* flush any delayed tasks or pending work */
  7667. flush_scheduled_work();
  7668. drm_mode_config_cleanup(dev);
  7669. intel_cleanup_overlay(dev);
  7670. }
  7671. /*
  7672. * Return which encoder is currently attached for connector.
  7673. */
  7674. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  7675. {
  7676. return &intel_attached_encoder(connector)->base;
  7677. }
  7678. void intel_connector_attach_encoder(struct intel_connector *connector,
  7679. struct intel_encoder *encoder)
  7680. {
  7681. connector->encoder = encoder;
  7682. drm_mode_connector_attach_encoder(&connector->base,
  7683. &encoder->base);
  7684. }
  7685. /*
  7686. * set vga decode state - true == enable VGA decode
  7687. */
  7688. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  7689. {
  7690. struct drm_i915_private *dev_priv = dev->dev_private;
  7691. u16 gmch_ctrl;
  7692. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  7693. if (state)
  7694. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  7695. else
  7696. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  7697. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  7698. return 0;
  7699. }
  7700. #ifdef CONFIG_DEBUG_FS
  7701. #include <linux/seq_file.h>
  7702. struct intel_display_error_state {
  7703. struct intel_cursor_error_state {
  7704. u32 control;
  7705. u32 position;
  7706. u32 base;
  7707. u32 size;
  7708. } cursor[I915_MAX_PIPES];
  7709. struct intel_pipe_error_state {
  7710. u32 conf;
  7711. u32 source;
  7712. u32 htotal;
  7713. u32 hblank;
  7714. u32 hsync;
  7715. u32 vtotal;
  7716. u32 vblank;
  7717. u32 vsync;
  7718. } pipe[I915_MAX_PIPES];
  7719. struct intel_plane_error_state {
  7720. u32 control;
  7721. u32 stride;
  7722. u32 size;
  7723. u32 pos;
  7724. u32 addr;
  7725. u32 surface;
  7726. u32 tile_offset;
  7727. } plane[I915_MAX_PIPES];
  7728. };
  7729. struct intel_display_error_state *
  7730. intel_display_capture_error_state(struct drm_device *dev)
  7731. {
  7732. drm_i915_private_t *dev_priv = dev->dev_private;
  7733. struct intel_display_error_state *error;
  7734. enum transcoder cpu_transcoder;
  7735. int i;
  7736. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  7737. if (error == NULL)
  7738. return NULL;
  7739. for_each_pipe(i) {
  7740. cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
  7741. error->cursor[i].control = I915_READ(CURCNTR(i));
  7742. error->cursor[i].position = I915_READ(CURPOS(i));
  7743. error->cursor[i].base = I915_READ(CURBASE(i));
  7744. error->plane[i].control = I915_READ(DSPCNTR(i));
  7745. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  7746. error->plane[i].size = I915_READ(DSPSIZE(i));
  7747. error->plane[i].pos = I915_READ(DSPPOS(i));
  7748. error->plane[i].addr = I915_READ(DSPADDR(i));
  7749. if (INTEL_INFO(dev)->gen >= 4) {
  7750. error->plane[i].surface = I915_READ(DSPSURF(i));
  7751. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  7752. }
  7753. error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  7754. error->pipe[i].source = I915_READ(PIPESRC(i));
  7755. error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  7756. error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  7757. error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  7758. error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  7759. error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  7760. error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  7761. }
  7762. return error;
  7763. }
  7764. void
  7765. intel_display_print_error_state(struct seq_file *m,
  7766. struct drm_device *dev,
  7767. struct intel_display_error_state *error)
  7768. {
  7769. drm_i915_private_t *dev_priv = dev->dev_private;
  7770. int i;
  7771. seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
  7772. for_each_pipe(i) {
  7773. seq_printf(m, "Pipe [%d]:\n", i);
  7774. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  7775. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  7776. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  7777. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  7778. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  7779. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  7780. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  7781. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  7782. seq_printf(m, "Plane [%d]:\n", i);
  7783. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  7784. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  7785. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  7786. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  7787. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  7788. if (INTEL_INFO(dev)->gen >= 4) {
  7789. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  7790. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  7791. }
  7792. seq_printf(m, "Cursor [%d]:\n", i);
  7793. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  7794. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  7795. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  7796. }
  7797. }
  7798. #endif