intel_display.c 251 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367
  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 = 8, .max = 18 },
  141. .m2 = { .min = 3, .max = 7 },
  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 = 8, .max = 18 },
  154. .m2 = { .min = 3, .max = 7 },
  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_page_offset(int *x, int *y,
  1762. unsigned int tiling_mode,
  1763. unsigned int cpp,
  1764. unsigned int pitch)
  1765. {
  1766. if (tiling_mode != I915_TILING_NONE) {
  1767. unsigned int tile_rows, tiles;
  1768. tile_rows = *y / 8;
  1769. *y %= 8;
  1770. tiles = *x / (512/cpp);
  1771. *x %= 512/cpp;
  1772. return tile_rows * pitch * 8 + tiles * 4096;
  1773. } else {
  1774. unsigned int offset;
  1775. offset = *y * pitch + *x * cpp;
  1776. *y = 0;
  1777. *x = (offset & 4095) / cpp;
  1778. return offset & -4096;
  1779. }
  1780. }
  1781. static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1782. int x, int y)
  1783. {
  1784. struct drm_device *dev = crtc->dev;
  1785. struct drm_i915_private *dev_priv = dev->dev_private;
  1786. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1787. struct intel_framebuffer *intel_fb;
  1788. struct drm_i915_gem_object *obj;
  1789. int plane = intel_crtc->plane;
  1790. unsigned long linear_offset;
  1791. u32 dspcntr;
  1792. u32 reg;
  1793. switch (plane) {
  1794. case 0:
  1795. case 1:
  1796. break;
  1797. default:
  1798. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1799. return -EINVAL;
  1800. }
  1801. intel_fb = to_intel_framebuffer(fb);
  1802. obj = intel_fb->obj;
  1803. reg = DSPCNTR(plane);
  1804. dspcntr = I915_READ(reg);
  1805. /* Mask out pixel format bits in case we change it */
  1806. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1807. switch (fb->pixel_format) {
  1808. case DRM_FORMAT_C8:
  1809. dspcntr |= DISPPLANE_8BPP;
  1810. break;
  1811. case DRM_FORMAT_XRGB1555:
  1812. case DRM_FORMAT_ARGB1555:
  1813. dspcntr |= DISPPLANE_BGRX555;
  1814. break;
  1815. case DRM_FORMAT_RGB565:
  1816. dspcntr |= DISPPLANE_BGRX565;
  1817. break;
  1818. case DRM_FORMAT_XRGB8888:
  1819. case DRM_FORMAT_ARGB8888:
  1820. dspcntr |= DISPPLANE_BGRX888;
  1821. break;
  1822. case DRM_FORMAT_XBGR8888:
  1823. case DRM_FORMAT_ABGR8888:
  1824. dspcntr |= DISPPLANE_RGBX888;
  1825. break;
  1826. case DRM_FORMAT_XRGB2101010:
  1827. case DRM_FORMAT_ARGB2101010:
  1828. dspcntr |= DISPPLANE_BGRX101010;
  1829. break;
  1830. case DRM_FORMAT_XBGR2101010:
  1831. case DRM_FORMAT_ABGR2101010:
  1832. dspcntr |= DISPPLANE_RGBX101010;
  1833. break;
  1834. default:
  1835. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1836. return -EINVAL;
  1837. }
  1838. if (INTEL_INFO(dev)->gen >= 4) {
  1839. if (obj->tiling_mode != I915_TILING_NONE)
  1840. dspcntr |= DISPPLANE_TILED;
  1841. else
  1842. dspcntr &= ~DISPPLANE_TILED;
  1843. }
  1844. I915_WRITE(reg, dspcntr);
  1845. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1846. if (INTEL_INFO(dev)->gen >= 4) {
  1847. intel_crtc->dspaddr_offset =
  1848. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  1849. fb->bits_per_pixel / 8,
  1850. fb->pitches[0]);
  1851. linear_offset -= intel_crtc->dspaddr_offset;
  1852. } else {
  1853. intel_crtc->dspaddr_offset = linear_offset;
  1854. }
  1855. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1856. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1857. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1858. if (INTEL_INFO(dev)->gen >= 4) {
  1859. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1860. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1861. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1862. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1863. } else
  1864. I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset);
  1865. POSTING_READ(reg);
  1866. return 0;
  1867. }
  1868. static int ironlake_update_plane(struct drm_crtc *crtc,
  1869. struct drm_framebuffer *fb, int x, int y)
  1870. {
  1871. struct drm_device *dev = crtc->dev;
  1872. struct drm_i915_private *dev_priv = dev->dev_private;
  1873. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1874. struct intel_framebuffer *intel_fb;
  1875. struct drm_i915_gem_object *obj;
  1876. int plane = intel_crtc->plane;
  1877. unsigned long linear_offset;
  1878. u32 dspcntr;
  1879. u32 reg;
  1880. switch (plane) {
  1881. case 0:
  1882. case 1:
  1883. case 2:
  1884. break;
  1885. default:
  1886. DRM_ERROR("Can't update plane %d in SAREA\n", plane);
  1887. return -EINVAL;
  1888. }
  1889. intel_fb = to_intel_framebuffer(fb);
  1890. obj = intel_fb->obj;
  1891. reg = DSPCNTR(plane);
  1892. dspcntr = I915_READ(reg);
  1893. /* Mask out pixel format bits in case we change it */
  1894. dspcntr &= ~DISPPLANE_PIXFORMAT_MASK;
  1895. switch (fb->pixel_format) {
  1896. case DRM_FORMAT_C8:
  1897. dspcntr |= DISPPLANE_8BPP;
  1898. break;
  1899. case DRM_FORMAT_RGB565:
  1900. dspcntr |= DISPPLANE_BGRX565;
  1901. break;
  1902. case DRM_FORMAT_XRGB8888:
  1903. case DRM_FORMAT_ARGB8888:
  1904. dspcntr |= DISPPLANE_BGRX888;
  1905. break;
  1906. case DRM_FORMAT_XBGR8888:
  1907. case DRM_FORMAT_ABGR8888:
  1908. dspcntr |= DISPPLANE_RGBX888;
  1909. break;
  1910. case DRM_FORMAT_XRGB2101010:
  1911. case DRM_FORMAT_ARGB2101010:
  1912. dspcntr |= DISPPLANE_BGRX101010;
  1913. break;
  1914. case DRM_FORMAT_XBGR2101010:
  1915. case DRM_FORMAT_ABGR2101010:
  1916. dspcntr |= DISPPLANE_RGBX101010;
  1917. break;
  1918. default:
  1919. DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format);
  1920. return -EINVAL;
  1921. }
  1922. if (obj->tiling_mode != I915_TILING_NONE)
  1923. dspcntr |= DISPPLANE_TILED;
  1924. else
  1925. dspcntr &= ~DISPPLANE_TILED;
  1926. /* must disable */
  1927. dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE;
  1928. I915_WRITE(reg, dspcntr);
  1929. linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8);
  1930. intel_crtc->dspaddr_offset =
  1931. intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode,
  1932. fb->bits_per_pixel / 8,
  1933. fb->pitches[0]);
  1934. linear_offset -= intel_crtc->dspaddr_offset;
  1935. DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n",
  1936. obj->gtt_offset, linear_offset, x, y, fb->pitches[0]);
  1937. I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]);
  1938. I915_MODIFY_DISPBASE(DSPSURF(plane),
  1939. obj->gtt_offset + intel_crtc->dspaddr_offset);
  1940. if (IS_HASWELL(dev)) {
  1941. I915_WRITE(DSPOFFSET(plane), (y << 16) | x);
  1942. } else {
  1943. I915_WRITE(DSPTILEOFF(plane), (y << 16) | x);
  1944. I915_WRITE(DSPLINOFF(plane), linear_offset);
  1945. }
  1946. POSTING_READ(reg);
  1947. return 0;
  1948. }
  1949. /* Assume fb object is pinned & idle & fenced and just update base pointers */
  1950. static int
  1951. intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb,
  1952. int x, int y, enum mode_set_atomic state)
  1953. {
  1954. struct drm_device *dev = crtc->dev;
  1955. struct drm_i915_private *dev_priv = dev->dev_private;
  1956. if (dev_priv->display.disable_fbc)
  1957. dev_priv->display.disable_fbc(dev);
  1958. intel_increase_pllclock(crtc);
  1959. return dev_priv->display.update_plane(crtc, fb, x, y);
  1960. }
  1961. static int
  1962. intel_finish_fb(struct drm_framebuffer *old_fb)
  1963. {
  1964. struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj;
  1965. struct drm_i915_private *dev_priv = obj->base.dev->dev_private;
  1966. bool was_interruptible = dev_priv->mm.interruptible;
  1967. int ret;
  1968. /* Big Hammer, we also need to ensure that any pending
  1969. * MI_WAIT_FOR_EVENT inside a user batch buffer on the
  1970. * current scanout is retired before unpinning the old
  1971. * framebuffer.
  1972. *
  1973. * This should only fail upon a hung GPU, in which case we
  1974. * can safely continue.
  1975. */
  1976. dev_priv->mm.interruptible = false;
  1977. ret = i915_gem_object_finish_gpu(obj);
  1978. dev_priv->mm.interruptible = was_interruptible;
  1979. return ret;
  1980. }
  1981. static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y)
  1982. {
  1983. struct drm_device *dev = crtc->dev;
  1984. struct drm_i915_master_private *master_priv;
  1985. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  1986. if (!dev->primary->master)
  1987. return;
  1988. master_priv = dev->primary->master->driver_priv;
  1989. if (!master_priv->sarea_priv)
  1990. return;
  1991. switch (intel_crtc->pipe) {
  1992. case 0:
  1993. master_priv->sarea_priv->pipeA_x = x;
  1994. master_priv->sarea_priv->pipeA_y = y;
  1995. break;
  1996. case 1:
  1997. master_priv->sarea_priv->pipeB_x = x;
  1998. master_priv->sarea_priv->pipeB_y = y;
  1999. break;
  2000. default:
  2001. break;
  2002. }
  2003. }
  2004. static int
  2005. intel_pipe_set_base(struct drm_crtc *crtc, int x, int y,
  2006. struct drm_framebuffer *fb)
  2007. {
  2008. struct drm_device *dev = crtc->dev;
  2009. struct drm_i915_private *dev_priv = dev->dev_private;
  2010. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2011. struct drm_framebuffer *old_fb;
  2012. int ret;
  2013. /* no fb bound */
  2014. if (!fb) {
  2015. DRM_ERROR("No FB bound\n");
  2016. return 0;
  2017. }
  2018. if(intel_crtc->plane > dev_priv->num_pipe) {
  2019. DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n",
  2020. intel_crtc->plane,
  2021. dev_priv->num_pipe);
  2022. return -EINVAL;
  2023. }
  2024. mutex_lock(&dev->struct_mutex);
  2025. ret = intel_pin_and_fence_fb_obj(dev,
  2026. to_intel_framebuffer(fb)->obj,
  2027. NULL);
  2028. if (ret != 0) {
  2029. mutex_unlock(&dev->struct_mutex);
  2030. DRM_ERROR("pin & fence failed\n");
  2031. return ret;
  2032. }
  2033. if (crtc->fb)
  2034. intel_finish_fb(crtc->fb);
  2035. ret = dev_priv->display.update_plane(crtc, fb, x, y);
  2036. if (ret) {
  2037. intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj);
  2038. mutex_unlock(&dev->struct_mutex);
  2039. DRM_ERROR("failed to update base address\n");
  2040. return ret;
  2041. }
  2042. old_fb = crtc->fb;
  2043. crtc->fb = fb;
  2044. crtc->x = x;
  2045. crtc->y = y;
  2046. if (old_fb) {
  2047. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2048. intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj);
  2049. }
  2050. intel_update_fbc(dev);
  2051. mutex_unlock(&dev->struct_mutex);
  2052. intel_crtc_update_sarea_pos(crtc, x, y);
  2053. return 0;
  2054. }
  2055. static void intel_fdi_normal_train(struct drm_crtc *crtc)
  2056. {
  2057. struct drm_device *dev = crtc->dev;
  2058. struct drm_i915_private *dev_priv = dev->dev_private;
  2059. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2060. int pipe = intel_crtc->pipe;
  2061. u32 reg, temp;
  2062. /* enable normal train */
  2063. reg = FDI_TX_CTL(pipe);
  2064. temp = I915_READ(reg);
  2065. if (IS_IVYBRIDGE(dev)) {
  2066. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2067. temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE;
  2068. } else {
  2069. temp &= ~FDI_LINK_TRAIN_NONE;
  2070. temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE;
  2071. }
  2072. I915_WRITE(reg, temp);
  2073. reg = FDI_RX_CTL(pipe);
  2074. temp = I915_READ(reg);
  2075. if (HAS_PCH_CPT(dev)) {
  2076. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2077. temp |= FDI_LINK_TRAIN_NORMAL_CPT;
  2078. } else {
  2079. temp &= ~FDI_LINK_TRAIN_NONE;
  2080. temp |= FDI_LINK_TRAIN_NONE;
  2081. }
  2082. I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE);
  2083. /* wait one idle pattern time */
  2084. POSTING_READ(reg);
  2085. udelay(1000);
  2086. /* IVB wants error correction enabled */
  2087. if (IS_IVYBRIDGE(dev))
  2088. I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE |
  2089. FDI_FE_ERRC_ENABLE);
  2090. }
  2091. static void ivb_modeset_global_resources(struct drm_device *dev)
  2092. {
  2093. struct drm_i915_private *dev_priv = dev->dev_private;
  2094. struct intel_crtc *pipe_B_crtc =
  2095. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  2096. struct intel_crtc *pipe_C_crtc =
  2097. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]);
  2098. uint32_t temp;
  2099. /* When everything is off disable fdi C so that we could enable fdi B
  2100. * with all lanes. XXX: This misses the case where a pipe is not using
  2101. * any pch resources and so doesn't need any fdi lanes. */
  2102. if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) {
  2103. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  2104. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  2105. temp = I915_READ(SOUTH_CHICKEN1);
  2106. temp &= ~FDI_BC_BIFURCATION_SELECT;
  2107. DRM_DEBUG_KMS("disabling fdi C rx\n");
  2108. I915_WRITE(SOUTH_CHICKEN1, temp);
  2109. }
  2110. }
  2111. /* The FDI link training functions for ILK/Ibexpeak. */
  2112. static void ironlake_fdi_link_train(struct drm_crtc *crtc)
  2113. {
  2114. struct drm_device *dev = crtc->dev;
  2115. struct drm_i915_private *dev_priv = dev->dev_private;
  2116. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2117. int pipe = intel_crtc->pipe;
  2118. int plane = intel_crtc->plane;
  2119. u32 reg, temp, tries;
  2120. /* FDI needs bits from pipe & plane first */
  2121. assert_pipe_enabled(dev_priv, pipe);
  2122. assert_plane_enabled(dev_priv, plane);
  2123. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2124. for train result */
  2125. reg = FDI_RX_IMR(pipe);
  2126. temp = I915_READ(reg);
  2127. temp &= ~FDI_RX_SYMBOL_LOCK;
  2128. temp &= ~FDI_RX_BIT_LOCK;
  2129. I915_WRITE(reg, temp);
  2130. I915_READ(reg);
  2131. udelay(150);
  2132. /* enable CPU FDI TX and PCH FDI RX */
  2133. reg = FDI_TX_CTL(pipe);
  2134. temp = I915_READ(reg);
  2135. temp &= ~(7 << 19);
  2136. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2137. temp &= ~FDI_LINK_TRAIN_NONE;
  2138. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2139. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2140. reg = FDI_RX_CTL(pipe);
  2141. temp = I915_READ(reg);
  2142. temp &= ~FDI_LINK_TRAIN_NONE;
  2143. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2144. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2145. POSTING_READ(reg);
  2146. udelay(150);
  2147. /* Ironlake workaround, enable clock pointer after FDI enable*/
  2148. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2149. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR |
  2150. FDI_RX_PHASE_SYNC_POINTER_EN);
  2151. reg = FDI_RX_IIR(pipe);
  2152. for (tries = 0; tries < 5; tries++) {
  2153. temp = I915_READ(reg);
  2154. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2155. if ((temp & FDI_RX_BIT_LOCK)) {
  2156. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2157. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2158. break;
  2159. }
  2160. }
  2161. if (tries == 5)
  2162. DRM_ERROR("FDI train 1 fail!\n");
  2163. /* Train 2 */
  2164. reg = FDI_TX_CTL(pipe);
  2165. temp = I915_READ(reg);
  2166. temp &= ~FDI_LINK_TRAIN_NONE;
  2167. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2168. I915_WRITE(reg, temp);
  2169. reg = FDI_RX_CTL(pipe);
  2170. temp = I915_READ(reg);
  2171. temp &= ~FDI_LINK_TRAIN_NONE;
  2172. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2173. I915_WRITE(reg, temp);
  2174. POSTING_READ(reg);
  2175. udelay(150);
  2176. reg = FDI_RX_IIR(pipe);
  2177. for (tries = 0; tries < 5; tries++) {
  2178. temp = I915_READ(reg);
  2179. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2180. if (temp & FDI_RX_SYMBOL_LOCK) {
  2181. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2182. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2183. break;
  2184. }
  2185. }
  2186. if (tries == 5)
  2187. DRM_ERROR("FDI train 2 fail!\n");
  2188. DRM_DEBUG_KMS("FDI train done\n");
  2189. }
  2190. static const int snb_b_fdi_train_param[] = {
  2191. FDI_LINK_TRAIN_400MV_0DB_SNB_B,
  2192. FDI_LINK_TRAIN_400MV_6DB_SNB_B,
  2193. FDI_LINK_TRAIN_600MV_3_5DB_SNB_B,
  2194. FDI_LINK_TRAIN_800MV_0DB_SNB_B,
  2195. };
  2196. /* The FDI link training functions for SNB/Cougarpoint. */
  2197. static void gen6_fdi_link_train(struct drm_crtc *crtc)
  2198. {
  2199. struct drm_device *dev = crtc->dev;
  2200. struct drm_i915_private *dev_priv = dev->dev_private;
  2201. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2202. int pipe = intel_crtc->pipe;
  2203. u32 reg, temp, i, retry;
  2204. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2205. for train result */
  2206. reg = FDI_RX_IMR(pipe);
  2207. temp = I915_READ(reg);
  2208. temp &= ~FDI_RX_SYMBOL_LOCK;
  2209. temp &= ~FDI_RX_BIT_LOCK;
  2210. I915_WRITE(reg, temp);
  2211. POSTING_READ(reg);
  2212. udelay(150);
  2213. /* enable CPU FDI TX and PCH FDI RX */
  2214. reg = FDI_TX_CTL(pipe);
  2215. temp = I915_READ(reg);
  2216. temp &= ~(7 << 19);
  2217. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2218. temp &= ~FDI_LINK_TRAIN_NONE;
  2219. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2220. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2221. /* SNB-B */
  2222. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2223. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2224. I915_WRITE(FDI_RX_MISC(pipe),
  2225. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2226. reg = FDI_RX_CTL(pipe);
  2227. temp = I915_READ(reg);
  2228. if (HAS_PCH_CPT(dev)) {
  2229. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2230. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2231. } else {
  2232. temp &= ~FDI_LINK_TRAIN_NONE;
  2233. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2234. }
  2235. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2236. POSTING_READ(reg);
  2237. udelay(150);
  2238. for (i = 0; i < 4; i++) {
  2239. reg = FDI_TX_CTL(pipe);
  2240. temp = I915_READ(reg);
  2241. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2242. temp |= snb_b_fdi_train_param[i];
  2243. I915_WRITE(reg, temp);
  2244. POSTING_READ(reg);
  2245. udelay(500);
  2246. for (retry = 0; retry < 5; retry++) {
  2247. reg = FDI_RX_IIR(pipe);
  2248. temp = I915_READ(reg);
  2249. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2250. if (temp & FDI_RX_BIT_LOCK) {
  2251. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2252. DRM_DEBUG_KMS("FDI train 1 done.\n");
  2253. break;
  2254. }
  2255. udelay(50);
  2256. }
  2257. if (retry < 5)
  2258. break;
  2259. }
  2260. if (i == 4)
  2261. DRM_ERROR("FDI train 1 fail!\n");
  2262. /* Train 2 */
  2263. reg = FDI_TX_CTL(pipe);
  2264. temp = I915_READ(reg);
  2265. temp &= ~FDI_LINK_TRAIN_NONE;
  2266. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2267. if (IS_GEN6(dev)) {
  2268. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2269. /* SNB-B */
  2270. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2271. }
  2272. I915_WRITE(reg, temp);
  2273. reg = FDI_RX_CTL(pipe);
  2274. temp = I915_READ(reg);
  2275. if (HAS_PCH_CPT(dev)) {
  2276. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2277. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2278. } else {
  2279. temp &= ~FDI_LINK_TRAIN_NONE;
  2280. temp |= FDI_LINK_TRAIN_PATTERN_2;
  2281. }
  2282. I915_WRITE(reg, temp);
  2283. POSTING_READ(reg);
  2284. udelay(150);
  2285. for (i = 0; i < 4; i++) {
  2286. reg = FDI_TX_CTL(pipe);
  2287. temp = I915_READ(reg);
  2288. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2289. temp |= snb_b_fdi_train_param[i];
  2290. I915_WRITE(reg, temp);
  2291. POSTING_READ(reg);
  2292. udelay(500);
  2293. for (retry = 0; retry < 5; retry++) {
  2294. reg = FDI_RX_IIR(pipe);
  2295. temp = I915_READ(reg);
  2296. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2297. if (temp & FDI_RX_SYMBOL_LOCK) {
  2298. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2299. DRM_DEBUG_KMS("FDI train 2 done.\n");
  2300. break;
  2301. }
  2302. udelay(50);
  2303. }
  2304. if (retry < 5)
  2305. break;
  2306. }
  2307. if (i == 4)
  2308. DRM_ERROR("FDI train 2 fail!\n");
  2309. DRM_DEBUG_KMS("FDI train done.\n");
  2310. }
  2311. /* Manual link training for Ivy Bridge A0 parts */
  2312. static void ivb_manual_fdi_link_train(struct drm_crtc *crtc)
  2313. {
  2314. struct drm_device *dev = crtc->dev;
  2315. struct drm_i915_private *dev_priv = dev->dev_private;
  2316. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2317. int pipe = intel_crtc->pipe;
  2318. u32 reg, temp, i;
  2319. /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit
  2320. for train result */
  2321. reg = FDI_RX_IMR(pipe);
  2322. temp = I915_READ(reg);
  2323. temp &= ~FDI_RX_SYMBOL_LOCK;
  2324. temp &= ~FDI_RX_BIT_LOCK;
  2325. I915_WRITE(reg, temp);
  2326. POSTING_READ(reg);
  2327. udelay(150);
  2328. DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n",
  2329. I915_READ(FDI_RX_IIR(pipe)));
  2330. /* enable CPU FDI TX and PCH FDI RX */
  2331. reg = FDI_TX_CTL(pipe);
  2332. temp = I915_READ(reg);
  2333. temp &= ~(7 << 19);
  2334. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2335. temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB);
  2336. temp |= FDI_LINK_TRAIN_PATTERN_1_IVB;
  2337. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2338. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2339. temp |= FDI_COMPOSITE_SYNC;
  2340. I915_WRITE(reg, temp | FDI_TX_ENABLE);
  2341. I915_WRITE(FDI_RX_MISC(pipe),
  2342. FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90);
  2343. reg = FDI_RX_CTL(pipe);
  2344. temp = I915_READ(reg);
  2345. temp &= ~FDI_LINK_TRAIN_AUTO;
  2346. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2347. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2348. temp |= FDI_COMPOSITE_SYNC;
  2349. I915_WRITE(reg, temp | FDI_RX_ENABLE);
  2350. POSTING_READ(reg);
  2351. udelay(150);
  2352. for (i = 0; i < 4; i++) {
  2353. reg = FDI_TX_CTL(pipe);
  2354. temp = I915_READ(reg);
  2355. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2356. temp |= snb_b_fdi_train_param[i];
  2357. I915_WRITE(reg, temp);
  2358. POSTING_READ(reg);
  2359. udelay(500);
  2360. reg = FDI_RX_IIR(pipe);
  2361. temp = I915_READ(reg);
  2362. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2363. if (temp & FDI_RX_BIT_LOCK ||
  2364. (I915_READ(reg) & FDI_RX_BIT_LOCK)) {
  2365. I915_WRITE(reg, temp | FDI_RX_BIT_LOCK);
  2366. DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i);
  2367. break;
  2368. }
  2369. }
  2370. if (i == 4)
  2371. DRM_ERROR("FDI train 1 fail!\n");
  2372. /* Train 2 */
  2373. reg = FDI_TX_CTL(pipe);
  2374. temp = I915_READ(reg);
  2375. temp &= ~FDI_LINK_TRAIN_NONE_IVB;
  2376. temp |= FDI_LINK_TRAIN_PATTERN_2_IVB;
  2377. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2378. temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B;
  2379. I915_WRITE(reg, temp);
  2380. reg = FDI_RX_CTL(pipe);
  2381. temp = I915_READ(reg);
  2382. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2383. temp |= FDI_LINK_TRAIN_PATTERN_2_CPT;
  2384. I915_WRITE(reg, temp);
  2385. POSTING_READ(reg);
  2386. udelay(150);
  2387. for (i = 0; i < 4; i++) {
  2388. reg = FDI_TX_CTL(pipe);
  2389. temp = I915_READ(reg);
  2390. temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK;
  2391. temp |= snb_b_fdi_train_param[i];
  2392. I915_WRITE(reg, temp);
  2393. POSTING_READ(reg);
  2394. udelay(500);
  2395. reg = FDI_RX_IIR(pipe);
  2396. temp = I915_READ(reg);
  2397. DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp);
  2398. if (temp & FDI_RX_SYMBOL_LOCK) {
  2399. I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK);
  2400. DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i);
  2401. break;
  2402. }
  2403. }
  2404. if (i == 4)
  2405. DRM_ERROR("FDI train 2 fail!\n");
  2406. DRM_DEBUG_KMS("FDI train done.\n");
  2407. }
  2408. static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc)
  2409. {
  2410. struct drm_device *dev = intel_crtc->base.dev;
  2411. struct drm_i915_private *dev_priv = dev->dev_private;
  2412. int pipe = intel_crtc->pipe;
  2413. u32 reg, temp;
  2414. /* enable PCH FDI RX PLL, wait warmup plus DMI latency */
  2415. reg = FDI_RX_CTL(pipe);
  2416. temp = I915_READ(reg);
  2417. temp &= ~((0x7 << 19) | (0x7 << 16));
  2418. temp |= (intel_crtc->fdi_lanes - 1) << 19;
  2419. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2420. I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE);
  2421. POSTING_READ(reg);
  2422. udelay(200);
  2423. /* Switch from Rawclk to PCDclk */
  2424. temp = I915_READ(reg);
  2425. I915_WRITE(reg, temp | FDI_PCDCLK);
  2426. POSTING_READ(reg);
  2427. udelay(200);
  2428. /* Enable CPU FDI TX PLL, always on for Ironlake */
  2429. reg = FDI_TX_CTL(pipe);
  2430. temp = I915_READ(reg);
  2431. if ((temp & FDI_TX_PLL_ENABLE) == 0) {
  2432. I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE);
  2433. POSTING_READ(reg);
  2434. udelay(100);
  2435. }
  2436. }
  2437. static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc)
  2438. {
  2439. struct drm_device *dev = intel_crtc->base.dev;
  2440. struct drm_i915_private *dev_priv = dev->dev_private;
  2441. int pipe = intel_crtc->pipe;
  2442. u32 reg, temp;
  2443. /* Switch from PCDclk to Rawclk */
  2444. reg = FDI_RX_CTL(pipe);
  2445. temp = I915_READ(reg);
  2446. I915_WRITE(reg, temp & ~FDI_PCDCLK);
  2447. /* Disable CPU FDI TX PLL */
  2448. reg = FDI_TX_CTL(pipe);
  2449. temp = I915_READ(reg);
  2450. I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE);
  2451. POSTING_READ(reg);
  2452. udelay(100);
  2453. reg = FDI_RX_CTL(pipe);
  2454. temp = I915_READ(reg);
  2455. I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE);
  2456. /* Wait for the clocks to turn off. */
  2457. POSTING_READ(reg);
  2458. udelay(100);
  2459. }
  2460. static void ironlake_fdi_disable(struct drm_crtc *crtc)
  2461. {
  2462. struct drm_device *dev = crtc->dev;
  2463. struct drm_i915_private *dev_priv = dev->dev_private;
  2464. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2465. int pipe = intel_crtc->pipe;
  2466. u32 reg, temp;
  2467. /* disable CPU FDI tx and PCH FDI rx */
  2468. reg = FDI_TX_CTL(pipe);
  2469. temp = I915_READ(reg);
  2470. I915_WRITE(reg, temp & ~FDI_TX_ENABLE);
  2471. POSTING_READ(reg);
  2472. reg = FDI_RX_CTL(pipe);
  2473. temp = I915_READ(reg);
  2474. temp &= ~(0x7 << 16);
  2475. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2476. I915_WRITE(reg, temp & ~FDI_RX_ENABLE);
  2477. POSTING_READ(reg);
  2478. udelay(100);
  2479. /* Ironlake workaround, disable clock pointer after downing FDI */
  2480. if (HAS_PCH_IBX(dev)) {
  2481. I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR);
  2482. }
  2483. /* still set train pattern 1 */
  2484. reg = FDI_TX_CTL(pipe);
  2485. temp = I915_READ(reg);
  2486. temp &= ~FDI_LINK_TRAIN_NONE;
  2487. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2488. I915_WRITE(reg, temp);
  2489. reg = FDI_RX_CTL(pipe);
  2490. temp = I915_READ(reg);
  2491. if (HAS_PCH_CPT(dev)) {
  2492. temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT;
  2493. temp |= FDI_LINK_TRAIN_PATTERN_1_CPT;
  2494. } else {
  2495. temp &= ~FDI_LINK_TRAIN_NONE;
  2496. temp |= FDI_LINK_TRAIN_PATTERN_1;
  2497. }
  2498. /* BPC in FDI rx is consistent with that in PIPECONF */
  2499. temp &= ~(0x07 << 16);
  2500. temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11;
  2501. I915_WRITE(reg, temp);
  2502. POSTING_READ(reg);
  2503. udelay(100);
  2504. }
  2505. static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc)
  2506. {
  2507. struct drm_device *dev = crtc->dev;
  2508. struct drm_i915_private *dev_priv = dev->dev_private;
  2509. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2510. unsigned long flags;
  2511. bool pending;
  2512. if (i915_reset_in_progress(&dev_priv->gpu_error) ||
  2513. intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter))
  2514. return false;
  2515. spin_lock_irqsave(&dev->event_lock, flags);
  2516. pending = to_intel_crtc(crtc)->unpin_work != NULL;
  2517. spin_unlock_irqrestore(&dev->event_lock, flags);
  2518. return pending;
  2519. }
  2520. static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc)
  2521. {
  2522. struct drm_device *dev = crtc->dev;
  2523. struct drm_i915_private *dev_priv = dev->dev_private;
  2524. if (crtc->fb == NULL)
  2525. return;
  2526. WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue));
  2527. wait_event(dev_priv->pending_flip_queue,
  2528. !intel_crtc_has_pending_flip(crtc));
  2529. mutex_lock(&dev->struct_mutex);
  2530. intel_finish_fb(crtc->fb);
  2531. mutex_unlock(&dev->struct_mutex);
  2532. }
  2533. static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc)
  2534. {
  2535. struct drm_device *dev = crtc->dev;
  2536. struct intel_encoder *intel_encoder;
  2537. /*
  2538. * If there's a non-PCH eDP on this crtc, it must be DP_A, and that
  2539. * must be driven by its own crtc; no sharing is possible.
  2540. */
  2541. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  2542. switch (intel_encoder->type) {
  2543. case INTEL_OUTPUT_EDP:
  2544. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  2545. return false;
  2546. continue;
  2547. }
  2548. }
  2549. return true;
  2550. }
  2551. static bool haswell_crtc_driving_pch(struct drm_crtc *crtc)
  2552. {
  2553. return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG);
  2554. }
  2555. /* Program iCLKIP clock to the desired frequency */
  2556. static void lpt_program_iclkip(struct drm_crtc *crtc)
  2557. {
  2558. struct drm_device *dev = crtc->dev;
  2559. struct drm_i915_private *dev_priv = dev->dev_private;
  2560. u32 divsel, phaseinc, auxdiv, phasedir = 0;
  2561. u32 temp;
  2562. mutex_lock(&dev_priv->dpio_lock);
  2563. /* It is necessary to ungate the pixclk gate prior to programming
  2564. * the divisors, and gate it back when it is done.
  2565. */
  2566. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE);
  2567. /* Disable SSCCTL */
  2568. intel_sbi_write(dev_priv, SBI_SSCCTL6,
  2569. intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) |
  2570. SBI_SSCCTL_DISABLE,
  2571. SBI_ICLK);
  2572. /* 20MHz is a corner case which is out of range for the 7-bit divisor */
  2573. if (crtc->mode.clock == 20000) {
  2574. auxdiv = 1;
  2575. divsel = 0x41;
  2576. phaseinc = 0x20;
  2577. } else {
  2578. /* The iCLK virtual clock root frequency is in MHz,
  2579. * but the crtc->mode.clock in in KHz. To get the divisors,
  2580. * it is necessary to divide one by another, so we
  2581. * convert the virtual clock precision to KHz here for higher
  2582. * precision.
  2583. */
  2584. u32 iclk_virtual_root_freq = 172800 * 1000;
  2585. u32 iclk_pi_range = 64;
  2586. u32 desired_divisor, msb_divisor_value, pi_value;
  2587. desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock);
  2588. msb_divisor_value = desired_divisor / iclk_pi_range;
  2589. pi_value = desired_divisor % iclk_pi_range;
  2590. auxdiv = 0;
  2591. divsel = msb_divisor_value - 2;
  2592. phaseinc = pi_value;
  2593. }
  2594. /* This should not happen with any sane values */
  2595. WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) &
  2596. ~SBI_SSCDIVINTPHASE_DIVSEL_MASK);
  2597. WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) &
  2598. ~SBI_SSCDIVINTPHASE_INCVAL_MASK);
  2599. DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n",
  2600. crtc->mode.clock,
  2601. auxdiv,
  2602. divsel,
  2603. phasedir,
  2604. phaseinc);
  2605. /* Program SSCDIVINTPHASE6 */
  2606. temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK);
  2607. temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK;
  2608. temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel);
  2609. temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK;
  2610. temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc);
  2611. temp |= SBI_SSCDIVINTPHASE_DIR(phasedir);
  2612. temp |= SBI_SSCDIVINTPHASE_PROPAGATE;
  2613. intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK);
  2614. /* Program SSCAUXDIV */
  2615. temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK);
  2616. temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1);
  2617. temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv);
  2618. intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK);
  2619. /* Enable modulator and associated divider */
  2620. temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK);
  2621. temp &= ~SBI_SSCCTL_DISABLE;
  2622. intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK);
  2623. /* Wait for initialization time */
  2624. udelay(24);
  2625. I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE);
  2626. mutex_unlock(&dev_priv->dpio_lock);
  2627. }
  2628. /*
  2629. * Enable PCH resources required for PCH ports:
  2630. * - PCH PLLs
  2631. * - FDI training & RX/TX
  2632. * - update transcoder timings
  2633. * - DP transcoding bits
  2634. * - transcoder
  2635. */
  2636. static void ironlake_pch_enable(struct drm_crtc *crtc)
  2637. {
  2638. struct drm_device *dev = crtc->dev;
  2639. struct drm_i915_private *dev_priv = dev->dev_private;
  2640. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2641. int pipe = intel_crtc->pipe;
  2642. u32 reg, temp;
  2643. assert_transcoder_disabled(dev_priv, pipe);
  2644. /* Write the TU size bits before fdi link training, so that error
  2645. * detection works. */
  2646. I915_WRITE(FDI_RX_TUSIZE1(pipe),
  2647. I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK);
  2648. /* For PCH output, training FDI link */
  2649. dev_priv->display.fdi_link_train(crtc);
  2650. /* XXX: pch pll's can be enabled any time before we enable the PCH
  2651. * transcoder, and we actually should do this to not upset any PCH
  2652. * transcoder that already use the clock when we share it.
  2653. *
  2654. * Note that enable_pch_pll tries to do the right thing, but get_pch_pll
  2655. * unconditionally resets the pll - we need that to have the right LVDS
  2656. * enable sequence. */
  2657. ironlake_enable_pch_pll(intel_crtc);
  2658. if (HAS_PCH_CPT(dev)) {
  2659. u32 sel;
  2660. temp = I915_READ(PCH_DPLL_SEL);
  2661. switch (pipe) {
  2662. default:
  2663. case 0:
  2664. temp |= TRANSA_DPLL_ENABLE;
  2665. sel = TRANSA_DPLLB_SEL;
  2666. break;
  2667. case 1:
  2668. temp |= TRANSB_DPLL_ENABLE;
  2669. sel = TRANSB_DPLLB_SEL;
  2670. break;
  2671. case 2:
  2672. temp |= TRANSC_DPLL_ENABLE;
  2673. sel = TRANSC_DPLLB_SEL;
  2674. break;
  2675. }
  2676. if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B)
  2677. temp |= sel;
  2678. else
  2679. temp &= ~sel;
  2680. I915_WRITE(PCH_DPLL_SEL, temp);
  2681. }
  2682. /* set transcoder timing, panel must allow it */
  2683. assert_panel_unlocked(dev_priv, pipe);
  2684. I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe)));
  2685. I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe)));
  2686. I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe)));
  2687. I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe)));
  2688. I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe)));
  2689. I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe)));
  2690. I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe)));
  2691. intel_fdi_normal_train(crtc);
  2692. /* For PCH DP, enable TRANS_DP_CTL */
  2693. if (HAS_PCH_CPT(dev) &&
  2694. (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) ||
  2695. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2696. u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5;
  2697. reg = TRANS_DP_CTL(pipe);
  2698. temp = I915_READ(reg);
  2699. temp &= ~(TRANS_DP_PORT_SEL_MASK |
  2700. TRANS_DP_SYNC_MASK |
  2701. TRANS_DP_BPC_MASK);
  2702. temp |= (TRANS_DP_OUTPUT_ENABLE |
  2703. TRANS_DP_ENH_FRAMING);
  2704. temp |= bpc << 9; /* same format but at 11:9 */
  2705. if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC)
  2706. temp |= TRANS_DP_HSYNC_ACTIVE_HIGH;
  2707. if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC)
  2708. temp |= TRANS_DP_VSYNC_ACTIVE_HIGH;
  2709. switch (intel_trans_dp_port_sel(crtc)) {
  2710. case PCH_DP_B:
  2711. temp |= TRANS_DP_PORT_SEL_B;
  2712. break;
  2713. case PCH_DP_C:
  2714. temp |= TRANS_DP_PORT_SEL_C;
  2715. break;
  2716. case PCH_DP_D:
  2717. temp |= TRANS_DP_PORT_SEL_D;
  2718. break;
  2719. default:
  2720. BUG();
  2721. }
  2722. I915_WRITE(reg, temp);
  2723. }
  2724. ironlake_enable_pch_transcoder(dev_priv, pipe);
  2725. }
  2726. static void lpt_pch_enable(struct drm_crtc *crtc)
  2727. {
  2728. struct drm_device *dev = crtc->dev;
  2729. struct drm_i915_private *dev_priv = dev->dev_private;
  2730. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2731. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  2732. assert_transcoder_disabled(dev_priv, TRANSCODER_A);
  2733. lpt_program_iclkip(crtc);
  2734. /* Set transcoder timing. */
  2735. I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder)));
  2736. I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder)));
  2737. I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder)));
  2738. I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder)));
  2739. I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder)));
  2740. I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder)));
  2741. I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder)));
  2742. lpt_enable_pch_transcoder(dev_priv, cpu_transcoder);
  2743. }
  2744. static void intel_put_pch_pll(struct intel_crtc *intel_crtc)
  2745. {
  2746. struct intel_pch_pll *pll = intel_crtc->pch_pll;
  2747. if (pll == NULL)
  2748. return;
  2749. if (pll->refcount == 0) {
  2750. WARN(1, "bad PCH PLL refcount\n");
  2751. return;
  2752. }
  2753. --pll->refcount;
  2754. intel_crtc->pch_pll = NULL;
  2755. }
  2756. static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp)
  2757. {
  2758. struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private;
  2759. struct intel_pch_pll *pll;
  2760. int i;
  2761. pll = intel_crtc->pch_pll;
  2762. if (pll) {
  2763. DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n",
  2764. intel_crtc->base.base.id, pll->pll_reg);
  2765. goto prepare;
  2766. }
  2767. if (HAS_PCH_IBX(dev_priv->dev)) {
  2768. /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */
  2769. i = intel_crtc->pipe;
  2770. pll = &dev_priv->pch_plls[i];
  2771. DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n",
  2772. intel_crtc->base.base.id, pll->pll_reg);
  2773. goto found;
  2774. }
  2775. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2776. pll = &dev_priv->pch_plls[i];
  2777. /* Only want to check enabled timings first */
  2778. if (pll->refcount == 0)
  2779. continue;
  2780. if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) &&
  2781. fp == I915_READ(pll->fp0_reg)) {
  2782. DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n",
  2783. intel_crtc->base.base.id,
  2784. pll->pll_reg, pll->refcount, pll->active);
  2785. goto found;
  2786. }
  2787. }
  2788. /* Ok no matching timings, maybe there's a free one? */
  2789. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  2790. pll = &dev_priv->pch_plls[i];
  2791. if (pll->refcount == 0) {
  2792. DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n",
  2793. intel_crtc->base.base.id, pll->pll_reg);
  2794. goto found;
  2795. }
  2796. }
  2797. return NULL;
  2798. found:
  2799. intel_crtc->pch_pll = pll;
  2800. pll->refcount++;
  2801. DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe);
  2802. prepare: /* separate function? */
  2803. DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg);
  2804. /* Wait for the clocks to stabilize before rewriting the regs */
  2805. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2806. POSTING_READ(pll->pll_reg);
  2807. udelay(150);
  2808. I915_WRITE(pll->fp0_reg, fp);
  2809. I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE);
  2810. pll->on = false;
  2811. return pll;
  2812. }
  2813. void intel_cpt_verify_modeset(struct drm_device *dev, int pipe)
  2814. {
  2815. struct drm_i915_private *dev_priv = dev->dev_private;
  2816. int dslreg = PIPEDSL(pipe);
  2817. u32 temp;
  2818. temp = I915_READ(dslreg);
  2819. udelay(500);
  2820. if (wait_for(I915_READ(dslreg) != temp, 5)) {
  2821. if (wait_for(I915_READ(dslreg) != temp, 5))
  2822. DRM_ERROR("mode set failed: pipe %d stuck\n", pipe);
  2823. }
  2824. }
  2825. static void ironlake_crtc_enable(struct drm_crtc *crtc)
  2826. {
  2827. struct drm_device *dev = crtc->dev;
  2828. struct drm_i915_private *dev_priv = dev->dev_private;
  2829. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2830. struct intel_encoder *encoder;
  2831. int pipe = intel_crtc->pipe;
  2832. int plane = intel_crtc->plane;
  2833. u32 temp;
  2834. bool is_pch_port;
  2835. WARN_ON(!crtc->enabled);
  2836. if (intel_crtc->active)
  2837. return;
  2838. intel_crtc->active = true;
  2839. intel_update_watermarks(dev);
  2840. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  2841. temp = I915_READ(PCH_LVDS);
  2842. if ((temp & LVDS_PORT_EN) == 0)
  2843. I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN);
  2844. }
  2845. is_pch_port = ironlake_crtc_driving_pch(crtc);
  2846. if (is_pch_port) {
  2847. /* Note: FDI PLL enabling _must_ be done before we enable the
  2848. * cpu pipes, hence this is separate from all the other fdi/pch
  2849. * enabling. */
  2850. ironlake_fdi_pll_enable(intel_crtc);
  2851. } else {
  2852. assert_fdi_tx_disabled(dev_priv, pipe);
  2853. assert_fdi_rx_disabled(dev_priv, pipe);
  2854. }
  2855. for_each_encoder_on_crtc(dev, crtc, encoder)
  2856. if (encoder->pre_enable)
  2857. encoder->pre_enable(encoder);
  2858. /* Enable panel fitting for LVDS */
  2859. if (dev_priv->pch_pf_size &&
  2860. (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) ||
  2861. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) {
  2862. /* Force use of hard-coded filter coefficients
  2863. * as some pre-programmed values are broken,
  2864. * e.g. x201.
  2865. */
  2866. if (IS_IVYBRIDGE(dev))
  2867. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2868. PF_PIPE_SEL_IVB(pipe));
  2869. else
  2870. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3);
  2871. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2872. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2873. }
  2874. /*
  2875. * On ILK+ LUT must be loaded before the pipe is running but with
  2876. * clocks enabled
  2877. */
  2878. intel_crtc_load_lut(crtc);
  2879. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2880. intel_enable_plane(dev_priv, plane, pipe);
  2881. if (is_pch_port)
  2882. ironlake_pch_enable(crtc);
  2883. mutex_lock(&dev->struct_mutex);
  2884. intel_update_fbc(dev);
  2885. mutex_unlock(&dev->struct_mutex);
  2886. intel_crtc_update_cursor(crtc, true);
  2887. for_each_encoder_on_crtc(dev, crtc, encoder)
  2888. encoder->enable(encoder);
  2889. if (HAS_PCH_CPT(dev))
  2890. intel_cpt_verify_modeset(dev, intel_crtc->pipe);
  2891. /*
  2892. * There seems to be a race in PCH platform hw (at least on some
  2893. * outputs) where an enabled pipe still completes any pageflip right
  2894. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2895. * as the first vblank happend, everything works as expected. Hence just
  2896. * wait for one vblank before returning to avoid strange things
  2897. * happening.
  2898. */
  2899. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2900. }
  2901. static void haswell_crtc_enable(struct drm_crtc *crtc)
  2902. {
  2903. struct drm_device *dev = crtc->dev;
  2904. struct drm_i915_private *dev_priv = dev->dev_private;
  2905. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2906. struct intel_encoder *encoder;
  2907. int pipe = intel_crtc->pipe;
  2908. int plane = intel_crtc->plane;
  2909. bool is_pch_port;
  2910. WARN_ON(!crtc->enabled);
  2911. if (intel_crtc->active)
  2912. return;
  2913. intel_crtc->active = true;
  2914. intel_update_watermarks(dev);
  2915. is_pch_port = haswell_crtc_driving_pch(crtc);
  2916. if (is_pch_port)
  2917. dev_priv->display.fdi_link_train(crtc);
  2918. for_each_encoder_on_crtc(dev, crtc, encoder)
  2919. if (encoder->pre_enable)
  2920. encoder->pre_enable(encoder);
  2921. intel_ddi_enable_pipe_clock(intel_crtc);
  2922. /* Enable panel fitting for eDP */
  2923. if (dev_priv->pch_pf_size &&
  2924. intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  2925. /* Force use of hard-coded filter coefficients
  2926. * as some pre-programmed values are broken,
  2927. * e.g. x201.
  2928. */
  2929. I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 |
  2930. PF_PIPE_SEL_IVB(pipe));
  2931. I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos);
  2932. I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size);
  2933. }
  2934. /*
  2935. * On ILK+ LUT must be loaded before the pipe is running but with
  2936. * clocks enabled
  2937. */
  2938. intel_crtc_load_lut(crtc);
  2939. intel_ddi_set_pipe_settings(crtc);
  2940. intel_ddi_enable_pipe_func(crtc);
  2941. intel_enable_pipe(dev_priv, pipe, is_pch_port);
  2942. intel_enable_plane(dev_priv, plane, pipe);
  2943. if (is_pch_port)
  2944. lpt_pch_enable(crtc);
  2945. mutex_lock(&dev->struct_mutex);
  2946. intel_update_fbc(dev);
  2947. mutex_unlock(&dev->struct_mutex);
  2948. intel_crtc_update_cursor(crtc, true);
  2949. for_each_encoder_on_crtc(dev, crtc, encoder)
  2950. encoder->enable(encoder);
  2951. /*
  2952. * There seems to be a race in PCH platform hw (at least on some
  2953. * outputs) where an enabled pipe still completes any pageflip right
  2954. * away (as if the pipe is off) instead of waiting for vblank. As soon
  2955. * as the first vblank happend, everything works as expected. Hence just
  2956. * wait for one vblank before returning to avoid strange things
  2957. * happening.
  2958. */
  2959. intel_wait_for_vblank(dev, intel_crtc->pipe);
  2960. }
  2961. static void ironlake_crtc_disable(struct drm_crtc *crtc)
  2962. {
  2963. struct drm_device *dev = crtc->dev;
  2964. struct drm_i915_private *dev_priv = dev->dev_private;
  2965. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  2966. struct intel_encoder *encoder;
  2967. int pipe = intel_crtc->pipe;
  2968. int plane = intel_crtc->plane;
  2969. u32 reg, temp;
  2970. if (!intel_crtc->active)
  2971. return;
  2972. for_each_encoder_on_crtc(dev, crtc, encoder)
  2973. encoder->disable(encoder);
  2974. intel_crtc_wait_for_pending_flips(crtc);
  2975. drm_vblank_off(dev, pipe);
  2976. intel_crtc_update_cursor(crtc, false);
  2977. intel_disable_plane(dev_priv, plane, pipe);
  2978. if (dev_priv->cfb_plane == plane)
  2979. intel_disable_fbc(dev);
  2980. intel_disable_pipe(dev_priv, pipe);
  2981. /* Disable PF */
  2982. I915_WRITE(PF_CTL(pipe), 0);
  2983. I915_WRITE(PF_WIN_SZ(pipe), 0);
  2984. for_each_encoder_on_crtc(dev, crtc, encoder)
  2985. if (encoder->post_disable)
  2986. encoder->post_disable(encoder);
  2987. ironlake_fdi_disable(crtc);
  2988. ironlake_disable_pch_transcoder(dev_priv, pipe);
  2989. if (HAS_PCH_CPT(dev)) {
  2990. /* disable TRANS_DP_CTL */
  2991. reg = TRANS_DP_CTL(pipe);
  2992. temp = I915_READ(reg);
  2993. temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK);
  2994. temp |= TRANS_DP_PORT_SEL_NONE;
  2995. I915_WRITE(reg, temp);
  2996. /* disable DPLL_SEL */
  2997. temp = I915_READ(PCH_DPLL_SEL);
  2998. switch (pipe) {
  2999. case 0:
  3000. temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL);
  3001. break;
  3002. case 1:
  3003. temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL);
  3004. break;
  3005. case 2:
  3006. /* C shares PLL A or B */
  3007. temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL);
  3008. break;
  3009. default:
  3010. BUG(); /* wtf */
  3011. }
  3012. I915_WRITE(PCH_DPLL_SEL, temp);
  3013. }
  3014. /* disable PCH DPLL */
  3015. intel_disable_pch_pll(intel_crtc);
  3016. ironlake_fdi_pll_disable(intel_crtc);
  3017. intel_crtc->active = false;
  3018. intel_update_watermarks(dev);
  3019. mutex_lock(&dev->struct_mutex);
  3020. intel_update_fbc(dev);
  3021. mutex_unlock(&dev->struct_mutex);
  3022. }
  3023. static void haswell_crtc_disable(struct drm_crtc *crtc)
  3024. {
  3025. struct drm_device *dev = crtc->dev;
  3026. struct drm_i915_private *dev_priv = dev->dev_private;
  3027. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3028. struct intel_encoder *encoder;
  3029. int pipe = intel_crtc->pipe;
  3030. int plane = intel_crtc->plane;
  3031. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3032. bool is_pch_port;
  3033. if (!intel_crtc->active)
  3034. return;
  3035. is_pch_port = haswell_crtc_driving_pch(crtc);
  3036. for_each_encoder_on_crtc(dev, crtc, encoder)
  3037. encoder->disable(encoder);
  3038. intel_crtc_wait_for_pending_flips(crtc);
  3039. drm_vblank_off(dev, pipe);
  3040. intel_crtc_update_cursor(crtc, false);
  3041. intel_disable_plane(dev_priv, plane, pipe);
  3042. if (dev_priv->cfb_plane == plane)
  3043. intel_disable_fbc(dev);
  3044. intel_disable_pipe(dev_priv, pipe);
  3045. intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder);
  3046. /* Disable PF */
  3047. I915_WRITE(PF_CTL(pipe), 0);
  3048. I915_WRITE(PF_WIN_SZ(pipe), 0);
  3049. intel_ddi_disable_pipe_clock(intel_crtc);
  3050. for_each_encoder_on_crtc(dev, crtc, encoder)
  3051. if (encoder->post_disable)
  3052. encoder->post_disable(encoder);
  3053. if (is_pch_port) {
  3054. lpt_disable_pch_transcoder(dev_priv);
  3055. intel_ddi_fdi_disable(crtc);
  3056. }
  3057. intel_crtc->active = false;
  3058. intel_update_watermarks(dev);
  3059. mutex_lock(&dev->struct_mutex);
  3060. intel_update_fbc(dev);
  3061. mutex_unlock(&dev->struct_mutex);
  3062. }
  3063. static void ironlake_crtc_off(struct drm_crtc *crtc)
  3064. {
  3065. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3066. intel_put_pch_pll(intel_crtc);
  3067. }
  3068. static void haswell_crtc_off(struct drm_crtc *crtc)
  3069. {
  3070. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3071. /* Stop saying we're using TRANSCODER_EDP because some other CRTC might
  3072. * start using it. */
  3073. intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe;
  3074. intel_ddi_put_crtc_pll(crtc);
  3075. }
  3076. static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable)
  3077. {
  3078. if (!enable && intel_crtc->overlay) {
  3079. struct drm_device *dev = intel_crtc->base.dev;
  3080. struct drm_i915_private *dev_priv = dev->dev_private;
  3081. mutex_lock(&dev->struct_mutex);
  3082. dev_priv->mm.interruptible = false;
  3083. (void) intel_overlay_switch_off(intel_crtc->overlay);
  3084. dev_priv->mm.interruptible = true;
  3085. mutex_unlock(&dev->struct_mutex);
  3086. }
  3087. /* Let userspace switch the overlay on again. In most cases userspace
  3088. * has to recompute where to put it anyway.
  3089. */
  3090. }
  3091. static void i9xx_crtc_enable(struct drm_crtc *crtc)
  3092. {
  3093. struct drm_device *dev = crtc->dev;
  3094. struct drm_i915_private *dev_priv = dev->dev_private;
  3095. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3096. struct intel_encoder *encoder;
  3097. int pipe = intel_crtc->pipe;
  3098. int plane = intel_crtc->plane;
  3099. WARN_ON(!crtc->enabled);
  3100. if (intel_crtc->active)
  3101. return;
  3102. intel_crtc->active = true;
  3103. intel_update_watermarks(dev);
  3104. intel_enable_pll(dev_priv, pipe);
  3105. for_each_encoder_on_crtc(dev, crtc, encoder)
  3106. if (encoder->pre_enable)
  3107. encoder->pre_enable(encoder);
  3108. intel_enable_pipe(dev_priv, pipe, false);
  3109. intel_enable_plane(dev_priv, plane, pipe);
  3110. intel_crtc_load_lut(crtc);
  3111. intel_update_fbc(dev);
  3112. /* Give the overlay scaler a chance to enable if it's on this pipe */
  3113. intel_crtc_dpms_overlay(intel_crtc, true);
  3114. intel_crtc_update_cursor(crtc, true);
  3115. for_each_encoder_on_crtc(dev, crtc, encoder)
  3116. encoder->enable(encoder);
  3117. }
  3118. static void i9xx_crtc_disable(struct drm_crtc *crtc)
  3119. {
  3120. struct drm_device *dev = crtc->dev;
  3121. struct drm_i915_private *dev_priv = dev->dev_private;
  3122. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3123. struct intel_encoder *encoder;
  3124. int pipe = intel_crtc->pipe;
  3125. int plane = intel_crtc->plane;
  3126. u32 pctl;
  3127. if (!intel_crtc->active)
  3128. return;
  3129. for_each_encoder_on_crtc(dev, crtc, encoder)
  3130. encoder->disable(encoder);
  3131. /* Give the overlay scaler a chance to disable if it's on this pipe */
  3132. intel_crtc_wait_for_pending_flips(crtc);
  3133. drm_vblank_off(dev, pipe);
  3134. intel_crtc_dpms_overlay(intel_crtc, false);
  3135. intel_crtc_update_cursor(crtc, false);
  3136. if (dev_priv->cfb_plane == plane)
  3137. intel_disable_fbc(dev);
  3138. intel_disable_plane(dev_priv, plane, pipe);
  3139. intel_disable_pipe(dev_priv, pipe);
  3140. /* Disable pannel fitter if it is on this pipe. */
  3141. pctl = I915_READ(PFIT_CONTROL);
  3142. if ((pctl & PFIT_ENABLE) &&
  3143. ((pctl & PFIT_PIPE_MASK) >> PFIT_PIPE_SHIFT) == pipe)
  3144. I915_WRITE(PFIT_CONTROL, 0);
  3145. intel_disable_pll(dev_priv, pipe);
  3146. intel_crtc->active = false;
  3147. intel_update_fbc(dev);
  3148. intel_update_watermarks(dev);
  3149. }
  3150. static void i9xx_crtc_off(struct drm_crtc *crtc)
  3151. {
  3152. }
  3153. static void intel_crtc_update_sarea(struct drm_crtc *crtc,
  3154. bool enabled)
  3155. {
  3156. struct drm_device *dev = crtc->dev;
  3157. struct drm_i915_master_private *master_priv;
  3158. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3159. int pipe = intel_crtc->pipe;
  3160. if (!dev->primary->master)
  3161. return;
  3162. master_priv = dev->primary->master->driver_priv;
  3163. if (!master_priv->sarea_priv)
  3164. return;
  3165. switch (pipe) {
  3166. case 0:
  3167. master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0;
  3168. master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0;
  3169. break;
  3170. case 1:
  3171. master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0;
  3172. master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0;
  3173. break;
  3174. default:
  3175. DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe));
  3176. break;
  3177. }
  3178. }
  3179. /**
  3180. * Sets the power management mode of the pipe and plane.
  3181. */
  3182. void intel_crtc_update_dpms(struct drm_crtc *crtc)
  3183. {
  3184. struct drm_device *dev = crtc->dev;
  3185. struct drm_i915_private *dev_priv = dev->dev_private;
  3186. struct intel_encoder *intel_encoder;
  3187. bool enable = false;
  3188. for_each_encoder_on_crtc(dev, crtc, intel_encoder)
  3189. enable |= intel_encoder->connectors_active;
  3190. if (enable)
  3191. dev_priv->display.crtc_enable(crtc);
  3192. else
  3193. dev_priv->display.crtc_disable(crtc);
  3194. intel_crtc_update_sarea(crtc, enable);
  3195. }
  3196. static void intel_crtc_disable(struct drm_crtc *crtc)
  3197. {
  3198. struct drm_device *dev = crtc->dev;
  3199. struct drm_connector *connector;
  3200. struct drm_i915_private *dev_priv = dev->dev_private;
  3201. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3202. /* crtc should still be enabled when we disable it. */
  3203. WARN_ON(!crtc->enabled);
  3204. intel_crtc->eld_vld = false;
  3205. dev_priv->display.crtc_disable(crtc);
  3206. intel_crtc_update_sarea(crtc, false);
  3207. dev_priv->display.off(crtc);
  3208. assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane);
  3209. assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe);
  3210. if (crtc->fb) {
  3211. mutex_lock(&dev->struct_mutex);
  3212. intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj);
  3213. mutex_unlock(&dev->struct_mutex);
  3214. crtc->fb = NULL;
  3215. }
  3216. /* Update computed state. */
  3217. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  3218. if (!connector->encoder || !connector->encoder->crtc)
  3219. continue;
  3220. if (connector->encoder->crtc != crtc)
  3221. continue;
  3222. connector->dpms = DRM_MODE_DPMS_OFF;
  3223. to_intel_encoder(connector->encoder)->connectors_active = false;
  3224. }
  3225. }
  3226. void intel_modeset_disable(struct drm_device *dev)
  3227. {
  3228. struct drm_crtc *crtc;
  3229. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  3230. if (crtc->enabled)
  3231. intel_crtc_disable(crtc);
  3232. }
  3233. }
  3234. void intel_encoder_destroy(struct drm_encoder *encoder)
  3235. {
  3236. struct intel_encoder *intel_encoder = to_intel_encoder(encoder);
  3237. drm_encoder_cleanup(encoder);
  3238. kfree(intel_encoder);
  3239. }
  3240. /* Simple dpms helper for encodres with just one connector, no cloning and only
  3241. * one kind of off state. It clamps all !ON modes to fully OFF and changes the
  3242. * state of the entire output pipe. */
  3243. void intel_encoder_dpms(struct intel_encoder *encoder, int mode)
  3244. {
  3245. if (mode == DRM_MODE_DPMS_ON) {
  3246. encoder->connectors_active = true;
  3247. intel_crtc_update_dpms(encoder->base.crtc);
  3248. } else {
  3249. encoder->connectors_active = false;
  3250. intel_crtc_update_dpms(encoder->base.crtc);
  3251. }
  3252. }
  3253. /* Cross check the actual hw state with our own modeset state tracking (and it's
  3254. * internal consistency). */
  3255. static void intel_connector_check_state(struct intel_connector *connector)
  3256. {
  3257. if (connector->get_hw_state(connector)) {
  3258. struct intel_encoder *encoder = connector->encoder;
  3259. struct drm_crtc *crtc;
  3260. bool encoder_enabled;
  3261. enum pipe pipe;
  3262. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  3263. connector->base.base.id,
  3264. drm_get_connector_name(&connector->base));
  3265. WARN(connector->base.dpms == DRM_MODE_DPMS_OFF,
  3266. "wrong connector dpms state\n");
  3267. WARN(connector->base.encoder != &encoder->base,
  3268. "active connector not linked to encoder\n");
  3269. WARN(!encoder->connectors_active,
  3270. "encoder->connectors_active not set\n");
  3271. encoder_enabled = encoder->get_hw_state(encoder, &pipe);
  3272. WARN(!encoder_enabled, "encoder not enabled\n");
  3273. if (WARN_ON(!encoder->base.crtc))
  3274. return;
  3275. crtc = encoder->base.crtc;
  3276. WARN(!crtc->enabled, "crtc not enabled\n");
  3277. WARN(!to_intel_crtc(crtc)->active, "crtc not active\n");
  3278. WARN(pipe != to_intel_crtc(crtc)->pipe,
  3279. "encoder active on the wrong pipe\n");
  3280. }
  3281. }
  3282. /* Even simpler default implementation, if there's really no special case to
  3283. * consider. */
  3284. void intel_connector_dpms(struct drm_connector *connector, int mode)
  3285. {
  3286. struct intel_encoder *encoder = intel_attached_encoder(connector);
  3287. /* All the simple cases only support two dpms states. */
  3288. if (mode != DRM_MODE_DPMS_ON)
  3289. mode = DRM_MODE_DPMS_OFF;
  3290. if (mode == connector->dpms)
  3291. return;
  3292. connector->dpms = mode;
  3293. /* Only need to change hw state when actually enabled */
  3294. if (encoder->base.crtc)
  3295. intel_encoder_dpms(encoder, mode);
  3296. else
  3297. WARN_ON(encoder->connectors_active != false);
  3298. intel_modeset_check_state(connector->dev);
  3299. }
  3300. /* Simple connector->get_hw_state implementation for encoders that support only
  3301. * one connector and no cloning and hence the encoder state determines the state
  3302. * of the connector. */
  3303. bool intel_connector_get_hw_state(struct intel_connector *connector)
  3304. {
  3305. enum pipe pipe = 0;
  3306. struct intel_encoder *encoder = connector->encoder;
  3307. return encoder->get_hw_state(encoder, &pipe);
  3308. }
  3309. static bool intel_crtc_mode_fixup(struct drm_crtc *crtc,
  3310. const struct drm_display_mode *mode,
  3311. struct drm_display_mode *adjusted_mode)
  3312. {
  3313. struct drm_device *dev = crtc->dev;
  3314. if (HAS_PCH_SPLIT(dev)) {
  3315. /* FDI link clock is fixed at 2.7G */
  3316. if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4)
  3317. return false;
  3318. }
  3319. /* All interlaced capable intel hw wants timings in frames. Note though
  3320. * that intel_lvds_mode_fixup does some funny tricks with the crtc
  3321. * timings, so we need to be careful not to clobber these.*/
  3322. if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET))
  3323. drm_mode_set_crtcinfo(adjusted_mode, 0);
  3324. /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes
  3325. * with a hsync front porch of 0.
  3326. */
  3327. if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) &&
  3328. adjusted_mode->hsync_start == adjusted_mode->hdisplay)
  3329. return false;
  3330. return true;
  3331. }
  3332. static int valleyview_get_display_clock_speed(struct drm_device *dev)
  3333. {
  3334. return 400000; /* FIXME */
  3335. }
  3336. static int i945_get_display_clock_speed(struct drm_device *dev)
  3337. {
  3338. return 400000;
  3339. }
  3340. static int i915_get_display_clock_speed(struct drm_device *dev)
  3341. {
  3342. return 333000;
  3343. }
  3344. static int i9xx_misc_get_display_clock_speed(struct drm_device *dev)
  3345. {
  3346. return 200000;
  3347. }
  3348. static int i915gm_get_display_clock_speed(struct drm_device *dev)
  3349. {
  3350. u16 gcfgc = 0;
  3351. pci_read_config_word(dev->pdev, GCFGC, &gcfgc);
  3352. if (gcfgc & GC_LOW_FREQUENCY_ENABLE)
  3353. return 133000;
  3354. else {
  3355. switch (gcfgc & GC_DISPLAY_CLOCK_MASK) {
  3356. case GC_DISPLAY_CLOCK_333_MHZ:
  3357. return 333000;
  3358. default:
  3359. case GC_DISPLAY_CLOCK_190_200_MHZ:
  3360. return 190000;
  3361. }
  3362. }
  3363. }
  3364. static int i865_get_display_clock_speed(struct drm_device *dev)
  3365. {
  3366. return 266000;
  3367. }
  3368. static int i855_get_display_clock_speed(struct drm_device *dev)
  3369. {
  3370. u16 hpllcc = 0;
  3371. /* Assume that the hardware is in the high speed state. This
  3372. * should be the default.
  3373. */
  3374. switch (hpllcc & GC_CLOCK_CONTROL_MASK) {
  3375. case GC_CLOCK_133_200:
  3376. case GC_CLOCK_100_200:
  3377. return 200000;
  3378. case GC_CLOCK_166_250:
  3379. return 250000;
  3380. case GC_CLOCK_100_133:
  3381. return 133000;
  3382. }
  3383. /* Shouldn't happen */
  3384. return 0;
  3385. }
  3386. static int i830_get_display_clock_speed(struct drm_device *dev)
  3387. {
  3388. return 133000;
  3389. }
  3390. static void
  3391. intel_reduce_ratio(uint32_t *num, uint32_t *den)
  3392. {
  3393. while (*num > 0xffffff || *den > 0xffffff) {
  3394. *num >>= 1;
  3395. *den >>= 1;
  3396. }
  3397. }
  3398. void
  3399. intel_link_compute_m_n(int bits_per_pixel, int nlanes,
  3400. int pixel_clock, int link_clock,
  3401. struct intel_link_m_n *m_n)
  3402. {
  3403. m_n->tu = 64;
  3404. m_n->gmch_m = bits_per_pixel * pixel_clock;
  3405. m_n->gmch_n = link_clock * nlanes * 8;
  3406. intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n);
  3407. m_n->link_m = pixel_clock;
  3408. m_n->link_n = link_clock;
  3409. intel_reduce_ratio(&m_n->link_m, &m_n->link_n);
  3410. }
  3411. static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv)
  3412. {
  3413. if (i915_panel_use_ssc >= 0)
  3414. return i915_panel_use_ssc != 0;
  3415. return dev_priv->lvds_use_ssc
  3416. && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE);
  3417. }
  3418. /**
  3419. * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send
  3420. * @crtc: CRTC structure
  3421. * @mode: requested mode
  3422. *
  3423. * A pipe may be connected to one or more outputs. Based on the depth of the
  3424. * attached framebuffer, choose a good color depth to use on the pipe.
  3425. *
  3426. * If possible, match the pipe depth to the fb depth. In some cases, this
  3427. * isn't ideal, because the connected output supports a lesser or restricted
  3428. * set of depths. Resolve that here:
  3429. * LVDS typically supports only 6bpc, so clamp down in that case
  3430. * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc
  3431. * Displays may support a restricted set as well, check EDID and clamp as
  3432. * appropriate.
  3433. * DP may want to dither down to 6bpc to fit larger modes
  3434. *
  3435. * RETURNS:
  3436. * Dithering requirement (i.e. false if display bpc and pipe bpc match,
  3437. * true if they don't match).
  3438. */
  3439. static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc,
  3440. struct drm_framebuffer *fb,
  3441. unsigned int *pipe_bpp,
  3442. struct drm_display_mode *mode)
  3443. {
  3444. struct drm_device *dev = crtc->dev;
  3445. struct drm_i915_private *dev_priv = dev->dev_private;
  3446. struct drm_connector *connector;
  3447. struct intel_encoder *intel_encoder;
  3448. unsigned int display_bpc = UINT_MAX, bpc;
  3449. /* Walk the encoders & connectors on this crtc, get min bpc */
  3450. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  3451. if (intel_encoder->type == INTEL_OUTPUT_LVDS) {
  3452. unsigned int lvds_bpc;
  3453. if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) ==
  3454. LVDS_A3_POWER_UP)
  3455. lvds_bpc = 8;
  3456. else
  3457. lvds_bpc = 6;
  3458. if (lvds_bpc < display_bpc) {
  3459. DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc);
  3460. display_bpc = lvds_bpc;
  3461. }
  3462. continue;
  3463. }
  3464. /* Not one of the known troublemakers, check the EDID */
  3465. list_for_each_entry(connector, &dev->mode_config.connector_list,
  3466. head) {
  3467. if (connector->encoder != &intel_encoder->base)
  3468. continue;
  3469. /* Don't use an invalid EDID bpc value */
  3470. if (connector->display_info.bpc &&
  3471. connector->display_info.bpc < display_bpc) {
  3472. DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc);
  3473. display_bpc = connector->display_info.bpc;
  3474. }
  3475. }
  3476. if (intel_encoder->type == INTEL_OUTPUT_EDP) {
  3477. /* Use VBT settings if we have an eDP panel */
  3478. unsigned int edp_bpc = dev_priv->edp.bpp / 3;
  3479. if (edp_bpc && edp_bpc < display_bpc) {
  3480. DRM_DEBUG_KMS("clamping display bpc (was %d) to eDP (%d)\n", display_bpc, edp_bpc);
  3481. display_bpc = edp_bpc;
  3482. }
  3483. continue;
  3484. }
  3485. /*
  3486. * HDMI is either 12 or 8, so if the display lets 10bpc sneak
  3487. * through, clamp it down. (Note: >12bpc will be caught below.)
  3488. */
  3489. if (intel_encoder->type == INTEL_OUTPUT_HDMI) {
  3490. if (display_bpc > 8 && display_bpc < 12) {
  3491. DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n");
  3492. display_bpc = 12;
  3493. } else {
  3494. DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n");
  3495. display_bpc = 8;
  3496. }
  3497. }
  3498. }
  3499. if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  3500. DRM_DEBUG_KMS("Dithering DP to 6bpc\n");
  3501. display_bpc = 6;
  3502. }
  3503. /*
  3504. * We could just drive the pipe at the highest bpc all the time and
  3505. * enable dithering as needed, but that costs bandwidth. So choose
  3506. * the minimum value that expresses the full color range of the fb but
  3507. * also stays within the max display bpc discovered above.
  3508. */
  3509. switch (fb->depth) {
  3510. case 8:
  3511. bpc = 8; /* since we go through a colormap */
  3512. break;
  3513. case 15:
  3514. case 16:
  3515. bpc = 6; /* min is 18bpp */
  3516. break;
  3517. case 24:
  3518. bpc = 8;
  3519. break;
  3520. case 30:
  3521. bpc = 10;
  3522. break;
  3523. case 48:
  3524. bpc = 12;
  3525. break;
  3526. default:
  3527. DRM_DEBUG("unsupported depth, assuming 24 bits\n");
  3528. bpc = min((unsigned int)8, display_bpc);
  3529. break;
  3530. }
  3531. display_bpc = min(display_bpc, bpc);
  3532. DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n",
  3533. bpc, display_bpc);
  3534. *pipe_bpp = display_bpc * 3;
  3535. return display_bpc != bpc;
  3536. }
  3537. static int vlv_get_refclk(struct drm_crtc *crtc)
  3538. {
  3539. struct drm_device *dev = crtc->dev;
  3540. struct drm_i915_private *dev_priv = dev->dev_private;
  3541. int refclk = 27000; /* for DP & HDMI */
  3542. return 100000; /* only one validated so far */
  3543. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) {
  3544. refclk = 96000;
  3545. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3546. if (intel_panel_use_ssc(dev_priv))
  3547. refclk = 100000;
  3548. else
  3549. refclk = 96000;
  3550. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  3551. refclk = 100000;
  3552. }
  3553. return refclk;
  3554. }
  3555. static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors)
  3556. {
  3557. struct drm_device *dev = crtc->dev;
  3558. struct drm_i915_private *dev_priv = dev->dev_private;
  3559. int refclk;
  3560. if (IS_VALLEYVIEW(dev)) {
  3561. refclk = vlv_get_refclk(crtc);
  3562. } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3563. intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  3564. refclk = dev_priv->lvds_ssc_freq * 1000;
  3565. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  3566. refclk / 1000);
  3567. } else if (!IS_GEN2(dev)) {
  3568. refclk = 96000;
  3569. } else {
  3570. refclk = 48000;
  3571. }
  3572. return refclk;
  3573. }
  3574. static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode,
  3575. intel_clock_t *clock)
  3576. {
  3577. /* SDVO TV has fixed PLL values depend on its clock range,
  3578. this mirrors vbios setting. */
  3579. if (adjusted_mode->clock >= 100000
  3580. && adjusted_mode->clock < 140500) {
  3581. clock->p1 = 2;
  3582. clock->p2 = 10;
  3583. clock->n = 3;
  3584. clock->m1 = 16;
  3585. clock->m2 = 8;
  3586. } else if (adjusted_mode->clock >= 140500
  3587. && adjusted_mode->clock <= 200000) {
  3588. clock->p1 = 1;
  3589. clock->p2 = 10;
  3590. clock->n = 6;
  3591. clock->m1 = 12;
  3592. clock->m2 = 8;
  3593. }
  3594. }
  3595. static void i9xx_update_pll_dividers(struct drm_crtc *crtc,
  3596. intel_clock_t *clock,
  3597. intel_clock_t *reduced_clock)
  3598. {
  3599. struct drm_device *dev = crtc->dev;
  3600. struct drm_i915_private *dev_priv = dev->dev_private;
  3601. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3602. int pipe = intel_crtc->pipe;
  3603. u32 fp, fp2 = 0;
  3604. if (IS_PINEVIEW(dev)) {
  3605. fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2;
  3606. if (reduced_clock)
  3607. fp2 = (1 << reduced_clock->n) << 16 |
  3608. reduced_clock->m1 << 8 | reduced_clock->m2;
  3609. } else {
  3610. fp = clock->n << 16 | clock->m1 << 8 | clock->m2;
  3611. if (reduced_clock)
  3612. fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 |
  3613. reduced_clock->m2;
  3614. }
  3615. I915_WRITE(FP0(pipe), fp);
  3616. intel_crtc->lowfreq_avail = false;
  3617. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3618. reduced_clock && i915_powersave) {
  3619. I915_WRITE(FP1(pipe), fp2);
  3620. intel_crtc->lowfreq_avail = true;
  3621. } else {
  3622. I915_WRITE(FP1(pipe), fp);
  3623. }
  3624. }
  3625. static void vlv_update_pll(struct drm_crtc *crtc,
  3626. struct drm_display_mode *mode,
  3627. struct drm_display_mode *adjusted_mode,
  3628. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3629. int num_connectors)
  3630. {
  3631. struct drm_device *dev = crtc->dev;
  3632. struct drm_i915_private *dev_priv = dev->dev_private;
  3633. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3634. int pipe = intel_crtc->pipe;
  3635. u32 dpll, mdiv, pdiv;
  3636. u32 bestn, bestm1, bestm2, bestp1, bestp2;
  3637. bool is_sdvo;
  3638. u32 temp;
  3639. mutex_lock(&dev_priv->dpio_lock);
  3640. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3641. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3642. dpll = DPLL_VGA_MODE_DIS;
  3643. dpll |= DPLL_EXT_BUFFER_ENABLE_VLV;
  3644. dpll |= DPLL_REFA_CLK_ENABLE_VLV;
  3645. dpll |= DPLL_INTEGRATED_CLOCK_VLV;
  3646. I915_WRITE(DPLL(pipe), dpll);
  3647. POSTING_READ(DPLL(pipe));
  3648. bestn = clock->n;
  3649. bestm1 = clock->m1;
  3650. bestm2 = clock->m2;
  3651. bestp1 = clock->p1;
  3652. bestp2 = clock->p2;
  3653. /*
  3654. * In Valleyview PLL and program lane counter registers are exposed
  3655. * through DPIO interface
  3656. */
  3657. mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK));
  3658. mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT));
  3659. mdiv |= ((bestn << DPIO_N_SHIFT));
  3660. mdiv |= (1 << DPIO_POST_DIV_SHIFT);
  3661. mdiv |= (1 << DPIO_K_SHIFT);
  3662. mdiv |= DPIO_ENABLE_CALIBRATION;
  3663. intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv);
  3664. intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000);
  3665. pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) |
  3666. (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) |
  3667. (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) |
  3668. (5 << DPIO_CLK_BIAS_CTL_SHIFT);
  3669. intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv);
  3670. intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b);
  3671. dpll |= DPLL_VCO_ENABLE;
  3672. I915_WRITE(DPLL(pipe), dpll);
  3673. POSTING_READ(DPLL(pipe));
  3674. if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1))
  3675. DRM_ERROR("DPLL %d failed to lock\n", pipe);
  3676. intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620);
  3677. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3678. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3679. I915_WRITE(DPLL(pipe), dpll);
  3680. /* Wait for the clocks to stabilize. */
  3681. POSTING_READ(DPLL(pipe));
  3682. udelay(150);
  3683. temp = 0;
  3684. if (is_sdvo) {
  3685. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3686. if (temp > 1)
  3687. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3688. else
  3689. temp = 0;
  3690. }
  3691. I915_WRITE(DPLL_MD(pipe), temp);
  3692. POSTING_READ(DPLL_MD(pipe));
  3693. /* Now program lane control registers */
  3694. if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)
  3695. || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI))
  3696. {
  3697. temp = 0x1000C4;
  3698. if(pipe == 1)
  3699. temp |= (1 << 21);
  3700. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp);
  3701. }
  3702. if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP))
  3703. {
  3704. temp = 0x1000C4;
  3705. if(pipe == 1)
  3706. temp |= (1 << 21);
  3707. intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp);
  3708. }
  3709. mutex_unlock(&dev_priv->dpio_lock);
  3710. }
  3711. static void i9xx_update_pll(struct drm_crtc *crtc,
  3712. struct drm_display_mode *mode,
  3713. struct drm_display_mode *adjusted_mode,
  3714. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3715. int num_connectors)
  3716. {
  3717. struct drm_device *dev = crtc->dev;
  3718. struct drm_i915_private *dev_priv = dev->dev_private;
  3719. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3720. struct intel_encoder *encoder;
  3721. int pipe = intel_crtc->pipe;
  3722. u32 dpll;
  3723. bool is_sdvo;
  3724. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3725. is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) ||
  3726. intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI);
  3727. dpll = DPLL_VGA_MODE_DIS;
  3728. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS))
  3729. dpll |= DPLLB_MODE_LVDS;
  3730. else
  3731. dpll |= DPLLB_MODE_DAC_SERIAL;
  3732. if (is_sdvo) {
  3733. int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  3734. if (pixel_multiplier > 1) {
  3735. if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev))
  3736. dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES;
  3737. }
  3738. dpll |= DPLL_DVO_HIGH_SPEED;
  3739. }
  3740. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3741. dpll |= DPLL_DVO_HIGH_SPEED;
  3742. /* compute bitmask from p1 value */
  3743. if (IS_PINEVIEW(dev))
  3744. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW;
  3745. else {
  3746. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3747. if (IS_G4X(dev) && reduced_clock)
  3748. dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  3749. }
  3750. switch (clock->p2) {
  3751. case 5:
  3752. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  3753. break;
  3754. case 7:
  3755. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  3756. break;
  3757. case 10:
  3758. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  3759. break;
  3760. case 14:
  3761. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  3762. break;
  3763. }
  3764. if (INTEL_INFO(dev)->gen >= 4)
  3765. dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT);
  3766. if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3767. dpll |= PLL_REF_INPUT_TVCLKINBC;
  3768. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3769. /* XXX: just matching BIOS for now */
  3770. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3771. dpll |= 3;
  3772. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3773. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3774. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3775. else
  3776. dpll |= PLL_REF_INPUT_DREFCLK;
  3777. dpll |= DPLL_VCO_ENABLE;
  3778. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3779. POSTING_READ(DPLL(pipe));
  3780. udelay(150);
  3781. for_each_encoder_on_crtc(dev, crtc, encoder)
  3782. if (encoder->pre_pll_enable)
  3783. encoder->pre_pll_enable(encoder);
  3784. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT))
  3785. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  3786. I915_WRITE(DPLL(pipe), dpll);
  3787. /* Wait for the clocks to stabilize. */
  3788. POSTING_READ(DPLL(pipe));
  3789. udelay(150);
  3790. if (INTEL_INFO(dev)->gen >= 4) {
  3791. u32 temp = 0;
  3792. if (is_sdvo) {
  3793. temp = intel_mode_get_pixel_multiplier(adjusted_mode);
  3794. if (temp > 1)
  3795. temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT;
  3796. else
  3797. temp = 0;
  3798. }
  3799. I915_WRITE(DPLL_MD(pipe), temp);
  3800. } else {
  3801. /* The pixel multiplier can only be updated once the
  3802. * DPLL is enabled and the clocks are stable.
  3803. *
  3804. * So write it again.
  3805. */
  3806. I915_WRITE(DPLL(pipe), dpll);
  3807. }
  3808. }
  3809. static void i8xx_update_pll(struct drm_crtc *crtc,
  3810. struct drm_display_mode *adjusted_mode,
  3811. intel_clock_t *clock, intel_clock_t *reduced_clock,
  3812. int num_connectors)
  3813. {
  3814. struct drm_device *dev = crtc->dev;
  3815. struct drm_i915_private *dev_priv = dev->dev_private;
  3816. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3817. struct intel_encoder *encoder;
  3818. int pipe = intel_crtc->pipe;
  3819. u32 dpll;
  3820. i9xx_update_pll_dividers(crtc, clock, reduced_clock);
  3821. dpll = DPLL_VGA_MODE_DIS;
  3822. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) {
  3823. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3824. } else {
  3825. if (clock->p1 == 2)
  3826. dpll |= PLL_P1_DIVIDE_BY_TWO;
  3827. else
  3828. dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  3829. if (clock->p2 == 4)
  3830. dpll |= PLL_P2_DIVIDE_BY_4;
  3831. }
  3832. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT))
  3833. /* XXX: just matching BIOS for now */
  3834. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  3835. dpll |= 3;
  3836. else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) &&
  3837. intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  3838. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  3839. else
  3840. dpll |= PLL_REF_INPUT_DREFCLK;
  3841. dpll |= DPLL_VCO_ENABLE;
  3842. I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE);
  3843. POSTING_READ(DPLL(pipe));
  3844. udelay(150);
  3845. for_each_encoder_on_crtc(dev, crtc, encoder)
  3846. if (encoder->pre_pll_enable)
  3847. encoder->pre_pll_enable(encoder);
  3848. I915_WRITE(DPLL(pipe), dpll);
  3849. /* Wait for the clocks to stabilize. */
  3850. POSTING_READ(DPLL(pipe));
  3851. udelay(150);
  3852. /* The pixel multiplier can only be updated once the
  3853. * DPLL is enabled and the clocks are stable.
  3854. *
  3855. * So write it again.
  3856. */
  3857. I915_WRITE(DPLL(pipe), dpll);
  3858. }
  3859. static void intel_set_pipe_timings(struct intel_crtc *intel_crtc,
  3860. struct drm_display_mode *mode,
  3861. struct drm_display_mode *adjusted_mode)
  3862. {
  3863. struct drm_device *dev = intel_crtc->base.dev;
  3864. struct drm_i915_private *dev_priv = dev->dev_private;
  3865. enum pipe pipe = intel_crtc->pipe;
  3866. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  3867. uint32_t vsyncshift;
  3868. if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) {
  3869. /* the chip adds 2 halflines automatically */
  3870. adjusted_mode->crtc_vtotal -= 1;
  3871. adjusted_mode->crtc_vblank_end -= 1;
  3872. vsyncshift = adjusted_mode->crtc_hsync_start
  3873. - adjusted_mode->crtc_htotal / 2;
  3874. } else {
  3875. vsyncshift = 0;
  3876. }
  3877. if (INTEL_INFO(dev)->gen > 3)
  3878. I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift);
  3879. I915_WRITE(HTOTAL(cpu_transcoder),
  3880. (adjusted_mode->crtc_hdisplay - 1) |
  3881. ((adjusted_mode->crtc_htotal - 1) << 16));
  3882. I915_WRITE(HBLANK(cpu_transcoder),
  3883. (adjusted_mode->crtc_hblank_start - 1) |
  3884. ((adjusted_mode->crtc_hblank_end - 1) << 16));
  3885. I915_WRITE(HSYNC(cpu_transcoder),
  3886. (adjusted_mode->crtc_hsync_start - 1) |
  3887. ((adjusted_mode->crtc_hsync_end - 1) << 16));
  3888. I915_WRITE(VTOTAL(cpu_transcoder),
  3889. (adjusted_mode->crtc_vdisplay - 1) |
  3890. ((adjusted_mode->crtc_vtotal - 1) << 16));
  3891. I915_WRITE(VBLANK(cpu_transcoder),
  3892. (adjusted_mode->crtc_vblank_start - 1) |
  3893. ((adjusted_mode->crtc_vblank_end - 1) << 16));
  3894. I915_WRITE(VSYNC(cpu_transcoder),
  3895. (adjusted_mode->crtc_vsync_start - 1) |
  3896. ((adjusted_mode->crtc_vsync_end - 1) << 16));
  3897. /* Workaround: when the EDP input selection is B, the VTOTAL_B must be
  3898. * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is
  3899. * documented on the DDI_FUNC_CTL register description, EDP Input Select
  3900. * bits. */
  3901. if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP &&
  3902. (pipe == PIPE_B || pipe == PIPE_C))
  3903. I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder)));
  3904. /* pipesrc controls the size that is scaled from, which should
  3905. * always be the user's requested size.
  3906. */
  3907. I915_WRITE(PIPESRC(pipe),
  3908. ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1));
  3909. }
  3910. static int i9xx_crtc_mode_set(struct drm_crtc *crtc,
  3911. struct drm_display_mode *mode,
  3912. struct drm_display_mode *adjusted_mode,
  3913. int x, int y,
  3914. struct drm_framebuffer *fb)
  3915. {
  3916. struct drm_device *dev = crtc->dev;
  3917. struct drm_i915_private *dev_priv = dev->dev_private;
  3918. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  3919. int pipe = intel_crtc->pipe;
  3920. int plane = intel_crtc->plane;
  3921. int refclk, num_connectors = 0;
  3922. intel_clock_t clock, reduced_clock;
  3923. u32 dspcntr, pipeconf;
  3924. bool ok, has_reduced_clock = false, is_sdvo = false;
  3925. bool is_lvds = false, is_tv = false, is_dp = false;
  3926. struct intel_encoder *encoder;
  3927. const intel_limit_t *limit;
  3928. int ret;
  3929. for_each_encoder_on_crtc(dev, crtc, encoder) {
  3930. switch (encoder->type) {
  3931. case INTEL_OUTPUT_LVDS:
  3932. is_lvds = true;
  3933. break;
  3934. case INTEL_OUTPUT_SDVO:
  3935. case INTEL_OUTPUT_HDMI:
  3936. is_sdvo = true;
  3937. if (encoder->needs_tv_clock)
  3938. is_tv = true;
  3939. break;
  3940. case INTEL_OUTPUT_TVOUT:
  3941. is_tv = true;
  3942. break;
  3943. case INTEL_OUTPUT_DISPLAYPORT:
  3944. is_dp = true;
  3945. break;
  3946. }
  3947. num_connectors++;
  3948. }
  3949. refclk = i9xx_get_refclk(crtc, num_connectors);
  3950. /*
  3951. * Returns a set of divisors for the desired target clock with the given
  3952. * refclk, or FALSE. The returned values represent the clock equation:
  3953. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  3954. */
  3955. limit = intel_limit(crtc, refclk);
  3956. ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  3957. &clock);
  3958. if (!ok) {
  3959. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  3960. return -EINVAL;
  3961. }
  3962. /* Ensure that the cursor is valid for the new mode before changing... */
  3963. intel_crtc_update_cursor(crtc, true);
  3964. if (is_lvds && dev_priv->lvds_downclock_avail) {
  3965. /*
  3966. * Ensure we match the reduced clock's P to the target clock.
  3967. * If the clocks don't match, we can't switch the display clock
  3968. * by using the FP0/FP1. In such case we will disable the LVDS
  3969. * downclock feature.
  3970. */
  3971. has_reduced_clock = limit->find_pll(limit, crtc,
  3972. dev_priv->lvds_downclock,
  3973. refclk,
  3974. &clock,
  3975. &reduced_clock);
  3976. }
  3977. if (is_sdvo && is_tv)
  3978. i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock);
  3979. if (IS_GEN2(dev))
  3980. i8xx_update_pll(crtc, adjusted_mode, &clock,
  3981. has_reduced_clock ? &reduced_clock : NULL,
  3982. num_connectors);
  3983. else if (IS_VALLEYVIEW(dev))
  3984. vlv_update_pll(crtc, mode, adjusted_mode, &clock,
  3985. has_reduced_clock ? &reduced_clock : NULL,
  3986. num_connectors);
  3987. else
  3988. i9xx_update_pll(crtc, mode, adjusted_mode, &clock,
  3989. has_reduced_clock ? &reduced_clock : NULL,
  3990. num_connectors);
  3991. /* setup pipeconf */
  3992. pipeconf = I915_READ(PIPECONF(pipe));
  3993. /* Set up the display plane register */
  3994. dspcntr = DISPPLANE_GAMMA_ENABLE;
  3995. if (pipe == 0)
  3996. dspcntr &= ~DISPPLANE_SEL_PIPE_MASK;
  3997. else
  3998. dspcntr |= DISPPLANE_SEL_PIPE_B;
  3999. if (pipe == 0 && INTEL_INFO(dev)->gen < 4) {
  4000. /* Enable pixel doubling when the dot clock is > 90% of the (display)
  4001. * core speed.
  4002. *
  4003. * XXX: No double-wide on 915GM pipe B. Is that the only reason for the
  4004. * pipe == 0 check?
  4005. */
  4006. if (mode->clock >
  4007. dev_priv->display.get_display_clock_speed(dev) * 9 / 10)
  4008. pipeconf |= PIPECONF_DOUBLE_WIDE;
  4009. else
  4010. pipeconf &= ~PIPECONF_DOUBLE_WIDE;
  4011. }
  4012. /* default to 8bpc */
  4013. pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN);
  4014. if (is_dp) {
  4015. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4016. pipeconf |= PIPECONF_6BPC |
  4017. PIPECONF_DITHER_EN |
  4018. PIPECONF_DITHER_TYPE_SP;
  4019. }
  4020. }
  4021. if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) {
  4022. if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) {
  4023. pipeconf |= PIPECONF_6BPC |
  4024. PIPECONF_ENABLE |
  4025. I965_PIPECONF_ACTIVE;
  4026. }
  4027. }
  4028. DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B');
  4029. drm_mode_debug_printmodeline(mode);
  4030. if (HAS_PIPE_CXSR(dev)) {
  4031. if (intel_crtc->lowfreq_avail) {
  4032. DRM_DEBUG_KMS("enabling CxSR downclocking\n");
  4033. pipeconf |= PIPECONF_CXSR_DOWNCLOCK;
  4034. } else {
  4035. DRM_DEBUG_KMS("disabling CxSR downclocking\n");
  4036. pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK;
  4037. }
  4038. }
  4039. pipeconf &= ~PIPECONF_INTERLACE_MASK;
  4040. if (!IS_GEN2(dev) &&
  4041. adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4042. pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION;
  4043. else
  4044. pipeconf |= PIPECONF_PROGRESSIVE;
  4045. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4046. /* pipesrc and dspsize control the size that is scaled from,
  4047. * which should always be the user's requested size.
  4048. */
  4049. I915_WRITE(DSPSIZE(plane),
  4050. ((mode->vdisplay - 1) << 16) |
  4051. (mode->hdisplay - 1));
  4052. I915_WRITE(DSPPOS(plane), 0);
  4053. I915_WRITE(PIPECONF(pipe), pipeconf);
  4054. POSTING_READ(PIPECONF(pipe));
  4055. intel_enable_pipe(dev_priv, pipe, false);
  4056. intel_wait_for_vblank(dev, pipe);
  4057. I915_WRITE(DSPCNTR(plane), dspcntr);
  4058. POSTING_READ(DSPCNTR(plane));
  4059. ret = intel_pipe_set_base(crtc, x, y, fb);
  4060. intel_update_watermarks(dev);
  4061. return ret;
  4062. }
  4063. static void ironlake_init_pch_refclk(struct drm_device *dev)
  4064. {
  4065. struct drm_i915_private *dev_priv = dev->dev_private;
  4066. struct drm_mode_config *mode_config = &dev->mode_config;
  4067. struct intel_encoder *encoder;
  4068. u32 temp;
  4069. bool has_lvds = false;
  4070. bool has_cpu_edp = false;
  4071. bool has_pch_edp = false;
  4072. bool has_panel = false;
  4073. bool has_ck505 = false;
  4074. bool can_ssc = false;
  4075. /* We need to take the global config into account */
  4076. list_for_each_entry(encoder, &mode_config->encoder_list,
  4077. base.head) {
  4078. switch (encoder->type) {
  4079. case INTEL_OUTPUT_LVDS:
  4080. has_panel = true;
  4081. has_lvds = true;
  4082. break;
  4083. case INTEL_OUTPUT_EDP:
  4084. has_panel = true;
  4085. if (intel_encoder_is_pch_edp(&encoder->base))
  4086. has_pch_edp = true;
  4087. else
  4088. has_cpu_edp = true;
  4089. break;
  4090. }
  4091. }
  4092. if (HAS_PCH_IBX(dev)) {
  4093. has_ck505 = dev_priv->display_clock_mode;
  4094. can_ssc = has_ck505;
  4095. } else {
  4096. has_ck505 = false;
  4097. can_ssc = true;
  4098. }
  4099. DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n",
  4100. has_panel, has_lvds, has_pch_edp, has_cpu_edp,
  4101. has_ck505);
  4102. /* Ironlake: try to setup display ref clock before DPLL
  4103. * enabling. This is only under driver's control after
  4104. * PCH B stepping, previous chipset stepping should be
  4105. * ignoring this setting.
  4106. */
  4107. temp = I915_READ(PCH_DREF_CONTROL);
  4108. /* Always enable nonspread source */
  4109. temp &= ~DREF_NONSPREAD_SOURCE_MASK;
  4110. if (has_ck505)
  4111. temp |= DREF_NONSPREAD_CK505_ENABLE;
  4112. else
  4113. temp |= DREF_NONSPREAD_SOURCE_ENABLE;
  4114. if (has_panel) {
  4115. temp &= ~DREF_SSC_SOURCE_MASK;
  4116. temp |= DREF_SSC_SOURCE_ENABLE;
  4117. /* SSC must be turned on before enabling the CPU output */
  4118. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4119. DRM_DEBUG_KMS("Using SSC on panel\n");
  4120. temp |= DREF_SSC1_ENABLE;
  4121. } else
  4122. temp &= ~DREF_SSC1_ENABLE;
  4123. /* Get SSC going before enabling the outputs */
  4124. I915_WRITE(PCH_DREF_CONTROL, temp);
  4125. POSTING_READ(PCH_DREF_CONTROL);
  4126. udelay(200);
  4127. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4128. /* Enable CPU source on CPU attached eDP */
  4129. if (has_cpu_edp) {
  4130. if (intel_panel_use_ssc(dev_priv) && can_ssc) {
  4131. DRM_DEBUG_KMS("Using SSC on eDP\n");
  4132. temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD;
  4133. }
  4134. else
  4135. temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD;
  4136. } else
  4137. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4138. I915_WRITE(PCH_DREF_CONTROL, temp);
  4139. POSTING_READ(PCH_DREF_CONTROL);
  4140. udelay(200);
  4141. } else {
  4142. DRM_DEBUG_KMS("Disabling SSC entirely\n");
  4143. temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK;
  4144. /* Turn off CPU output */
  4145. temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE;
  4146. I915_WRITE(PCH_DREF_CONTROL, temp);
  4147. POSTING_READ(PCH_DREF_CONTROL);
  4148. udelay(200);
  4149. /* Turn off the SSC source */
  4150. temp &= ~DREF_SSC_SOURCE_MASK;
  4151. temp |= DREF_SSC_SOURCE_DISABLE;
  4152. /* Turn off SSC1 */
  4153. temp &= ~ DREF_SSC1_ENABLE;
  4154. I915_WRITE(PCH_DREF_CONTROL, temp);
  4155. POSTING_READ(PCH_DREF_CONTROL);
  4156. udelay(200);
  4157. }
  4158. }
  4159. /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */
  4160. static void lpt_init_pch_refclk(struct drm_device *dev)
  4161. {
  4162. struct drm_i915_private *dev_priv = dev->dev_private;
  4163. struct drm_mode_config *mode_config = &dev->mode_config;
  4164. struct intel_encoder *encoder;
  4165. bool has_vga = false;
  4166. bool is_sdv = false;
  4167. u32 tmp;
  4168. list_for_each_entry(encoder, &mode_config->encoder_list, base.head) {
  4169. switch (encoder->type) {
  4170. case INTEL_OUTPUT_ANALOG:
  4171. has_vga = true;
  4172. break;
  4173. }
  4174. }
  4175. if (!has_vga)
  4176. return;
  4177. mutex_lock(&dev_priv->dpio_lock);
  4178. /* XXX: Rip out SDV support once Haswell ships for real. */
  4179. if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00)
  4180. is_sdv = true;
  4181. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4182. tmp &= ~SBI_SSCCTL_DISABLE;
  4183. tmp |= SBI_SSCCTL_PATHALT;
  4184. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4185. udelay(24);
  4186. tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK);
  4187. tmp &= ~SBI_SSCCTL_PATHALT;
  4188. intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK);
  4189. if (!is_sdv) {
  4190. tmp = I915_READ(SOUTH_CHICKEN2);
  4191. tmp |= FDI_MPHY_IOSFSB_RESET_CTL;
  4192. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4193. if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) &
  4194. FDI_MPHY_IOSFSB_RESET_STATUS, 100))
  4195. DRM_ERROR("FDI mPHY reset assert timeout\n");
  4196. tmp = I915_READ(SOUTH_CHICKEN2);
  4197. tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL;
  4198. I915_WRITE(SOUTH_CHICKEN2, tmp);
  4199. if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) &
  4200. FDI_MPHY_IOSFSB_RESET_STATUS) == 0,
  4201. 100))
  4202. DRM_ERROR("FDI mPHY reset de-assert timeout\n");
  4203. }
  4204. tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY);
  4205. tmp &= ~(0xFF << 24);
  4206. tmp |= (0x12 << 24);
  4207. intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY);
  4208. if (!is_sdv) {
  4209. tmp = intel_sbi_read(dev_priv, 0x808C, SBI_MPHY);
  4210. tmp &= ~(0x3 << 6);
  4211. tmp |= (1 << 6) | (1 << 0);
  4212. intel_sbi_write(dev_priv, 0x808C, tmp, SBI_MPHY);
  4213. }
  4214. if (is_sdv) {
  4215. tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY);
  4216. tmp |= 0x7FFF;
  4217. intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY);
  4218. }
  4219. tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY);
  4220. tmp |= (1 << 11);
  4221. intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY);
  4222. tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY);
  4223. tmp |= (1 << 11);
  4224. intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY);
  4225. if (is_sdv) {
  4226. tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY);
  4227. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4228. intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY);
  4229. tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY);
  4230. tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16);
  4231. intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY);
  4232. tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY);
  4233. tmp |= (0x3F << 8);
  4234. intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY);
  4235. tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY);
  4236. tmp |= (0x3F << 8);
  4237. intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY);
  4238. }
  4239. tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY);
  4240. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4241. intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY);
  4242. tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY);
  4243. tmp |= (1 << 24) | (1 << 21) | (1 << 18);
  4244. intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY);
  4245. if (!is_sdv) {
  4246. tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY);
  4247. tmp &= ~(7 << 13);
  4248. tmp |= (5 << 13);
  4249. intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY);
  4250. tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY);
  4251. tmp &= ~(7 << 13);
  4252. tmp |= (5 << 13);
  4253. intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY);
  4254. }
  4255. tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY);
  4256. tmp &= ~0xFF;
  4257. tmp |= 0x1C;
  4258. intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY);
  4259. tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY);
  4260. tmp &= ~0xFF;
  4261. tmp |= 0x1C;
  4262. intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY);
  4263. tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY);
  4264. tmp &= ~(0xFF << 16);
  4265. tmp |= (0x1C << 16);
  4266. intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY);
  4267. tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY);
  4268. tmp &= ~(0xFF << 16);
  4269. tmp |= (0x1C << 16);
  4270. intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY);
  4271. if (!is_sdv) {
  4272. tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY);
  4273. tmp |= (1 << 27);
  4274. intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY);
  4275. tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY);
  4276. tmp |= (1 << 27);
  4277. intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY);
  4278. tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY);
  4279. tmp &= ~(0xF << 28);
  4280. tmp |= (4 << 28);
  4281. intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY);
  4282. tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY);
  4283. tmp &= ~(0xF << 28);
  4284. tmp |= (4 << 28);
  4285. intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY);
  4286. }
  4287. /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */
  4288. tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK);
  4289. tmp |= SBI_DBUFF0_ENABLE;
  4290. intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK);
  4291. mutex_unlock(&dev_priv->dpio_lock);
  4292. }
  4293. /*
  4294. * Initialize reference clocks when the driver loads
  4295. */
  4296. void intel_init_pch_refclk(struct drm_device *dev)
  4297. {
  4298. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  4299. ironlake_init_pch_refclk(dev);
  4300. else if (HAS_PCH_LPT(dev))
  4301. lpt_init_pch_refclk(dev);
  4302. }
  4303. static int ironlake_get_refclk(struct drm_crtc *crtc)
  4304. {
  4305. struct drm_device *dev = crtc->dev;
  4306. struct drm_i915_private *dev_priv = dev->dev_private;
  4307. struct intel_encoder *encoder;
  4308. struct intel_encoder *edp_encoder = NULL;
  4309. int num_connectors = 0;
  4310. bool is_lvds = false;
  4311. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4312. switch (encoder->type) {
  4313. case INTEL_OUTPUT_LVDS:
  4314. is_lvds = true;
  4315. break;
  4316. case INTEL_OUTPUT_EDP:
  4317. edp_encoder = encoder;
  4318. break;
  4319. }
  4320. num_connectors++;
  4321. }
  4322. if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) {
  4323. DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n",
  4324. dev_priv->lvds_ssc_freq);
  4325. return dev_priv->lvds_ssc_freq * 1000;
  4326. }
  4327. return 120000;
  4328. }
  4329. static void ironlake_set_pipeconf(struct drm_crtc *crtc,
  4330. struct drm_display_mode *adjusted_mode,
  4331. bool dither)
  4332. {
  4333. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4334. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4335. int pipe = intel_crtc->pipe;
  4336. uint32_t val;
  4337. val = I915_READ(PIPECONF(pipe));
  4338. val &= ~PIPECONF_BPC_MASK;
  4339. switch (intel_crtc->bpp) {
  4340. case 18:
  4341. val |= PIPECONF_6BPC;
  4342. break;
  4343. case 24:
  4344. val |= PIPECONF_8BPC;
  4345. break;
  4346. case 30:
  4347. val |= PIPECONF_10BPC;
  4348. break;
  4349. case 36:
  4350. val |= PIPECONF_12BPC;
  4351. break;
  4352. default:
  4353. /* Case prevented by intel_choose_pipe_bpp_dither. */
  4354. BUG();
  4355. }
  4356. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4357. if (dither)
  4358. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4359. val &= ~PIPECONF_INTERLACE_MASK;
  4360. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4361. val |= PIPECONF_INTERLACED_ILK;
  4362. else
  4363. val |= PIPECONF_PROGRESSIVE;
  4364. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4365. val |= PIPECONF_COLOR_RANGE_SELECT;
  4366. else
  4367. val &= ~PIPECONF_COLOR_RANGE_SELECT;
  4368. I915_WRITE(PIPECONF(pipe), val);
  4369. POSTING_READ(PIPECONF(pipe));
  4370. }
  4371. /*
  4372. * Set up the pipe CSC unit.
  4373. *
  4374. * Currently only full range RGB to limited range RGB conversion
  4375. * is supported, but eventually this should handle various
  4376. * RGB<->YCbCr scenarios as well.
  4377. */
  4378. static void intel_set_pipe_csc(struct drm_crtc *crtc,
  4379. const struct drm_display_mode *adjusted_mode)
  4380. {
  4381. struct drm_device *dev = crtc->dev;
  4382. struct drm_i915_private *dev_priv = dev->dev_private;
  4383. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4384. int pipe = intel_crtc->pipe;
  4385. uint16_t coeff = 0x7800; /* 1.0 */
  4386. /*
  4387. * TODO: Check what kind of values actually come out of the pipe
  4388. * with these coeff/postoff values and adjust to get the best
  4389. * accuracy. Perhaps we even need to take the bpc value into
  4390. * consideration.
  4391. */
  4392. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4393. coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */
  4394. /*
  4395. * GY/GU and RY/RU should be the other way around according
  4396. * to BSpec, but reality doesn't agree. Just set them up in
  4397. * a way that results in the correct picture.
  4398. */
  4399. I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16);
  4400. I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0);
  4401. I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff);
  4402. I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0);
  4403. I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0);
  4404. I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16);
  4405. I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0);
  4406. I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0);
  4407. I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0);
  4408. if (INTEL_INFO(dev)->gen > 6) {
  4409. uint16_t postoff = 0;
  4410. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4411. postoff = (16 * (1 << 13) / 255) & 0x1fff;
  4412. I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff);
  4413. I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff);
  4414. I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff);
  4415. I915_WRITE(PIPE_CSC_MODE(pipe), 0);
  4416. } else {
  4417. uint32_t mode = CSC_MODE_YUV_TO_RGB;
  4418. if (adjusted_mode->private_flags & INTEL_MODE_LIMITED_COLOR_RANGE)
  4419. mode |= CSC_BLACK_SCREEN_OFFSET;
  4420. I915_WRITE(PIPE_CSC_MODE(pipe), mode);
  4421. }
  4422. }
  4423. static void haswell_set_pipeconf(struct drm_crtc *crtc,
  4424. struct drm_display_mode *adjusted_mode,
  4425. bool dither)
  4426. {
  4427. struct drm_i915_private *dev_priv = crtc->dev->dev_private;
  4428. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4429. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4430. uint32_t val;
  4431. val = I915_READ(PIPECONF(cpu_transcoder));
  4432. val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK);
  4433. if (dither)
  4434. val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP);
  4435. val &= ~PIPECONF_INTERLACE_MASK_HSW;
  4436. if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE)
  4437. val |= PIPECONF_INTERLACED_ILK;
  4438. else
  4439. val |= PIPECONF_PROGRESSIVE;
  4440. I915_WRITE(PIPECONF(cpu_transcoder), val);
  4441. POSTING_READ(PIPECONF(cpu_transcoder));
  4442. }
  4443. static bool ironlake_compute_clocks(struct drm_crtc *crtc,
  4444. struct drm_display_mode *adjusted_mode,
  4445. intel_clock_t *clock,
  4446. bool *has_reduced_clock,
  4447. intel_clock_t *reduced_clock)
  4448. {
  4449. struct drm_device *dev = crtc->dev;
  4450. struct drm_i915_private *dev_priv = dev->dev_private;
  4451. struct intel_encoder *intel_encoder;
  4452. int refclk;
  4453. const intel_limit_t *limit;
  4454. bool ret, is_sdvo = false, is_tv = false, is_lvds = false;
  4455. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4456. switch (intel_encoder->type) {
  4457. case INTEL_OUTPUT_LVDS:
  4458. is_lvds = true;
  4459. break;
  4460. case INTEL_OUTPUT_SDVO:
  4461. case INTEL_OUTPUT_HDMI:
  4462. is_sdvo = true;
  4463. if (intel_encoder->needs_tv_clock)
  4464. is_tv = true;
  4465. break;
  4466. case INTEL_OUTPUT_TVOUT:
  4467. is_tv = true;
  4468. break;
  4469. }
  4470. }
  4471. refclk = ironlake_get_refclk(crtc);
  4472. /*
  4473. * Returns a set of divisors for the desired target clock with the given
  4474. * refclk, or FALSE. The returned values represent the clock equation:
  4475. * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2.
  4476. */
  4477. limit = intel_limit(crtc, refclk);
  4478. ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL,
  4479. clock);
  4480. if (!ret)
  4481. return false;
  4482. if (is_lvds && dev_priv->lvds_downclock_avail) {
  4483. /*
  4484. * Ensure we match the reduced clock's P to the target clock.
  4485. * If the clocks don't match, we can't switch the display clock
  4486. * by using the FP0/FP1. In such case we will disable the LVDS
  4487. * downclock feature.
  4488. */
  4489. *has_reduced_clock = limit->find_pll(limit, crtc,
  4490. dev_priv->lvds_downclock,
  4491. refclk,
  4492. clock,
  4493. reduced_clock);
  4494. }
  4495. if (is_sdvo && is_tv)
  4496. i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock);
  4497. return true;
  4498. }
  4499. static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev)
  4500. {
  4501. struct drm_i915_private *dev_priv = dev->dev_private;
  4502. uint32_t temp;
  4503. temp = I915_READ(SOUTH_CHICKEN1);
  4504. if (temp & FDI_BC_BIFURCATION_SELECT)
  4505. return;
  4506. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE);
  4507. WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE);
  4508. temp |= FDI_BC_BIFURCATION_SELECT;
  4509. DRM_DEBUG_KMS("enabling fdi C rx\n");
  4510. I915_WRITE(SOUTH_CHICKEN1, temp);
  4511. POSTING_READ(SOUTH_CHICKEN1);
  4512. }
  4513. static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc)
  4514. {
  4515. struct drm_device *dev = intel_crtc->base.dev;
  4516. struct drm_i915_private *dev_priv = dev->dev_private;
  4517. struct intel_crtc *pipe_B_crtc =
  4518. to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]);
  4519. DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n",
  4520. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4521. if (intel_crtc->fdi_lanes > 4) {
  4522. DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n",
  4523. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4524. /* Clamp lanes to avoid programming the hw with bogus values. */
  4525. intel_crtc->fdi_lanes = 4;
  4526. return false;
  4527. }
  4528. if (dev_priv->num_pipe == 2)
  4529. return true;
  4530. switch (intel_crtc->pipe) {
  4531. case PIPE_A:
  4532. return true;
  4533. case PIPE_B:
  4534. if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled &&
  4535. intel_crtc->fdi_lanes > 2) {
  4536. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4537. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4538. /* Clamp lanes to avoid programming the hw with bogus values. */
  4539. intel_crtc->fdi_lanes = 2;
  4540. return false;
  4541. }
  4542. if (intel_crtc->fdi_lanes > 2)
  4543. WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT);
  4544. else
  4545. cpt_enable_fdi_bc_bifurcation(dev);
  4546. return true;
  4547. case PIPE_C:
  4548. if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) {
  4549. if (intel_crtc->fdi_lanes > 2) {
  4550. DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n",
  4551. intel_crtc->pipe, intel_crtc->fdi_lanes);
  4552. /* Clamp lanes to avoid programming the hw with bogus values. */
  4553. intel_crtc->fdi_lanes = 2;
  4554. return false;
  4555. }
  4556. } else {
  4557. DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n");
  4558. return false;
  4559. }
  4560. cpt_enable_fdi_bc_bifurcation(dev);
  4561. return true;
  4562. default:
  4563. BUG();
  4564. }
  4565. }
  4566. int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp)
  4567. {
  4568. /*
  4569. * Account for spread spectrum to avoid
  4570. * oversubscribing the link. Max center spread
  4571. * is 2.5%; use 5% for safety's sake.
  4572. */
  4573. u32 bps = target_clock * bpp * 21 / 20;
  4574. return bps / (link_bw * 8) + 1;
  4575. }
  4576. static void ironlake_set_m_n(struct drm_crtc *crtc,
  4577. struct drm_display_mode *mode,
  4578. struct drm_display_mode *adjusted_mode)
  4579. {
  4580. struct drm_device *dev = crtc->dev;
  4581. struct drm_i915_private *dev_priv = dev->dev_private;
  4582. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4583. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  4584. struct intel_encoder *intel_encoder, *edp_encoder = NULL;
  4585. struct intel_link_m_n m_n = {0};
  4586. int target_clock, pixel_multiplier, lane, link_bw;
  4587. bool is_dp = false, is_cpu_edp = false;
  4588. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4589. switch (intel_encoder->type) {
  4590. case INTEL_OUTPUT_DISPLAYPORT:
  4591. is_dp = true;
  4592. break;
  4593. case INTEL_OUTPUT_EDP:
  4594. is_dp = true;
  4595. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4596. is_cpu_edp = true;
  4597. edp_encoder = intel_encoder;
  4598. break;
  4599. }
  4600. }
  4601. /* FDI link */
  4602. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4603. lane = 0;
  4604. /* CPU eDP doesn't require FDI link, so just set DP M/N
  4605. according to current link config */
  4606. if (is_cpu_edp) {
  4607. intel_edp_link_config(edp_encoder, &lane, &link_bw);
  4608. } else {
  4609. /* FDI is a binary signal running at ~2.7GHz, encoding
  4610. * each output octet as 10 bits. The actual frequency
  4611. * is stored as a divider into a 100MHz clock, and the
  4612. * mode pixel clock is stored in units of 1KHz.
  4613. * Hence the bw of each lane in terms of the mode signal
  4614. * is:
  4615. */
  4616. link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10;
  4617. }
  4618. /* [e]DP over FDI requires target mode clock instead of link clock. */
  4619. if (edp_encoder)
  4620. target_clock = intel_edp_target_clock(edp_encoder, mode);
  4621. else if (is_dp)
  4622. target_clock = mode->clock;
  4623. else
  4624. target_clock = adjusted_mode->clock;
  4625. if (!lane)
  4626. lane = ironlake_get_lanes_required(target_clock, link_bw,
  4627. intel_crtc->bpp);
  4628. intel_crtc->fdi_lanes = lane;
  4629. if (pixel_multiplier > 1)
  4630. link_bw *= pixel_multiplier;
  4631. intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n);
  4632. I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m);
  4633. I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n);
  4634. I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m);
  4635. I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n);
  4636. }
  4637. static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc,
  4638. struct drm_display_mode *adjusted_mode,
  4639. intel_clock_t *clock, u32 fp)
  4640. {
  4641. struct drm_crtc *crtc = &intel_crtc->base;
  4642. struct drm_device *dev = crtc->dev;
  4643. struct drm_i915_private *dev_priv = dev->dev_private;
  4644. struct intel_encoder *intel_encoder;
  4645. uint32_t dpll;
  4646. int factor, pixel_multiplier, num_connectors = 0;
  4647. bool is_lvds = false, is_sdvo = false, is_tv = false;
  4648. bool is_dp = false, is_cpu_edp = false;
  4649. for_each_encoder_on_crtc(dev, crtc, intel_encoder) {
  4650. switch (intel_encoder->type) {
  4651. case INTEL_OUTPUT_LVDS:
  4652. is_lvds = true;
  4653. break;
  4654. case INTEL_OUTPUT_SDVO:
  4655. case INTEL_OUTPUT_HDMI:
  4656. is_sdvo = true;
  4657. if (intel_encoder->needs_tv_clock)
  4658. is_tv = true;
  4659. break;
  4660. case INTEL_OUTPUT_TVOUT:
  4661. is_tv = true;
  4662. break;
  4663. case INTEL_OUTPUT_DISPLAYPORT:
  4664. is_dp = true;
  4665. break;
  4666. case INTEL_OUTPUT_EDP:
  4667. is_dp = true;
  4668. if (!intel_encoder_is_pch_edp(&intel_encoder->base))
  4669. is_cpu_edp = true;
  4670. break;
  4671. }
  4672. num_connectors++;
  4673. }
  4674. /* Enable autotuning of the PLL clock (if permissible) */
  4675. factor = 21;
  4676. if (is_lvds) {
  4677. if ((intel_panel_use_ssc(dev_priv) &&
  4678. dev_priv->lvds_ssc_freq == 100) ||
  4679. intel_is_dual_link_lvds(dev))
  4680. factor = 25;
  4681. } else if (is_sdvo && is_tv)
  4682. factor = 20;
  4683. if (clock->m < factor * clock->n)
  4684. fp |= FP_CB_TUNE;
  4685. dpll = 0;
  4686. if (is_lvds)
  4687. dpll |= DPLLB_MODE_LVDS;
  4688. else
  4689. dpll |= DPLLB_MODE_DAC_SERIAL;
  4690. if (is_sdvo) {
  4691. pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode);
  4692. if (pixel_multiplier > 1) {
  4693. dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT;
  4694. }
  4695. dpll |= DPLL_DVO_HIGH_SPEED;
  4696. }
  4697. if (is_dp && !is_cpu_edp)
  4698. dpll |= DPLL_DVO_HIGH_SPEED;
  4699. /* compute bitmask from p1 value */
  4700. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT;
  4701. /* also FPA1 */
  4702. dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT;
  4703. switch (clock->p2) {
  4704. case 5:
  4705. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5;
  4706. break;
  4707. case 7:
  4708. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7;
  4709. break;
  4710. case 10:
  4711. dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10;
  4712. break;
  4713. case 14:
  4714. dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14;
  4715. break;
  4716. }
  4717. if (is_sdvo && is_tv)
  4718. dpll |= PLL_REF_INPUT_TVCLKINBC;
  4719. else if (is_tv)
  4720. /* XXX: just matching BIOS for now */
  4721. /* dpll |= PLL_REF_INPUT_TVCLKINBC; */
  4722. dpll |= 3;
  4723. else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2)
  4724. dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN;
  4725. else
  4726. dpll |= PLL_REF_INPUT_DREFCLK;
  4727. return dpll;
  4728. }
  4729. static int ironlake_crtc_mode_set(struct drm_crtc *crtc,
  4730. struct drm_display_mode *mode,
  4731. struct drm_display_mode *adjusted_mode,
  4732. int x, int y,
  4733. struct drm_framebuffer *fb)
  4734. {
  4735. struct drm_device *dev = crtc->dev;
  4736. struct drm_i915_private *dev_priv = dev->dev_private;
  4737. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4738. int pipe = intel_crtc->pipe;
  4739. int plane = intel_crtc->plane;
  4740. int num_connectors = 0;
  4741. intel_clock_t clock, reduced_clock;
  4742. u32 dpll, fp = 0, fp2 = 0;
  4743. bool ok, has_reduced_clock = false;
  4744. bool is_lvds = false, is_dp = false, is_cpu_edp = false;
  4745. struct intel_encoder *encoder;
  4746. int ret;
  4747. bool dither, fdi_config_ok;
  4748. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4749. switch (encoder->type) {
  4750. case INTEL_OUTPUT_LVDS:
  4751. is_lvds = true;
  4752. break;
  4753. case INTEL_OUTPUT_DISPLAYPORT:
  4754. is_dp = true;
  4755. break;
  4756. case INTEL_OUTPUT_EDP:
  4757. is_dp = true;
  4758. if (!intel_encoder_is_pch_edp(&encoder->base))
  4759. is_cpu_edp = true;
  4760. break;
  4761. }
  4762. num_connectors++;
  4763. }
  4764. WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)),
  4765. "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev));
  4766. ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock,
  4767. &has_reduced_clock, &reduced_clock);
  4768. if (!ok) {
  4769. DRM_ERROR("Couldn't find PLL settings for mode!\n");
  4770. return -EINVAL;
  4771. }
  4772. /* Ensure that the cursor is valid for the new mode before changing... */
  4773. intel_crtc_update_cursor(crtc, true);
  4774. /* determine panel color depth */
  4775. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4776. adjusted_mode);
  4777. if (is_lvds && dev_priv->lvds_dither)
  4778. dither = true;
  4779. fp = clock.n << 16 | clock.m1 << 8 | clock.m2;
  4780. if (has_reduced_clock)
  4781. fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 |
  4782. reduced_clock.m2;
  4783. dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp);
  4784. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4785. drm_mode_debug_printmodeline(mode);
  4786. /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */
  4787. if (!is_cpu_edp) {
  4788. struct intel_pch_pll *pll;
  4789. pll = intel_get_pch_pll(intel_crtc, dpll, fp);
  4790. if (pll == NULL) {
  4791. DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n",
  4792. pipe);
  4793. return -EINVAL;
  4794. }
  4795. } else
  4796. intel_put_pch_pll(intel_crtc);
  4797. if (is_dp && !is_cpu_edp)
  4798. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4799. for_each_encoder_on_crtc(dev, crtc, encoder)
  4800. if (encoder->pre_pll_enable)
  4801. encoder->pre_pll_enable(encoder);
  4802. if (intel_crtc->pch_pll) {
  4803. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4804. /* Wait for the clocks to stabilize. */
  4805. POSTING_READ(intel_crtc->pch_pll->pll_reg);
  4806. udelay(150);
  4807. /* The pixel multiplier can only be updated once the
  4808. * DPLL is enabled and the clocks are stable.
  4809. *
  4810. * So write it again.
  4811. */
  4812. I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll);
  4813. }
  4814. intel_crtc->lowfreq_avail = false;
  4815. if (intel_crtc->pch_pll) {
  4816. if (is_lvds && has_reduced_clock && i915_powersave) {
  4817. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2);
  4818. intel_crtc->lowfreq_avail = true;
  4819. } else {
  4820. I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp);
  4821. }
  4822. }
  4823. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4824. /* Note, this also computes intel_crtc->fdi_lanes which is used below in
  4825. * ironlake_check_fdi_lanes. */
  4826. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4827. fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc);
  4828. ironlake_set_pipeconf(crtc, adjusted_mode, dither);
  4829. intel_wait_for_vblank(dev, pipe);
  4830. /* Set up the display plane register */
  4831. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE);
  4832. POSTING_READ(DSPCNTR(plane));
  4833. ret = intel_pipe_set_base(crtc, x, y, fb);
  4834. intel_update_watermarks(dev);
  4835. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4836. return fdi_config_ok ? ret : -EINVAL;
  4837. }
  4838. static void haswell_modeset_global_resources(struct drm_device *dev)
  4839. {
  4840. struct drm_i915_private *dev_priv = dev->dev_private;
  4841. bool enable = false;
  4842. struct intel_crtc *crtc;
  4843. struct intel_encoder *encoder;
  4844. list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) {
  4845. if (crtc->pipe != PIPE_A && crtc->base.enabled)
  4846. enable = true;
  4847. /* XXX: Should check for edp transcoder here, but thanks to init
  4848. * sequence that's not yet available. Just in case desktop eDP
  4849. * on PORT D is possible on haswell, too. */
  4850. }
  4851. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  4852. base.head) {
  4853. if (encoder->type != INTEL_OUTPUT_EDP &&
  4854. encoder->connectors_active)
  4855. enable = true;
  4856. }
  4857. /* Even the eDP panel fitter is outside the always-on well. */
  4858. if (dev_priv->pch_pf_size)
  4859. enable = true;
  4860. intel_set_power_well(dev, enable);
  4861. }
  4862. static int haswell_crtc_mode_set(struct drm_crtc *crtc,
  4863. struct drm_display_mode *mode,
  4864. struct drm_display_mode *adjusted_mode,
  4865. int x, int y,
  4866. struct drm_framebuffer *fb)
  4867. {
  4868. struct drm_device *dev = crtc->dev;
  4869. struct drm_i915_private *dev_priv = dev->dev_private;
  4870. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4871. int pipe = intel_crtc->pipe;
  4872. int plane = intel_crtc->plane;
  4873. int num_connectors = 0;
  4874. bool is_dp = false, is_cpu_edp = false;
  4875. struct intel_encoder *encoder;
  4876. int ret;
  4877. bool dither;
  4878. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4879. switch (encoder->type) {
  4880. case INTEL_OUTPUT_DISPLAYPORT:
  4881. is_dp = true;
  4882. break;
  4883. case INTEL_OUTPUT_EDP:
  4884. is_dp = true;
  4885. if (!intel_encoder_is_pch_edp(&encoder->base))
  4886. is_cpu_edp = true;
  4887. break;
  4888. }
  4889. num_connectors++;
  4890. }
  4891. /* We are not sure yet this won't happen. */
  4892. WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n",
  4893. INTEL_PCH_TYPE(dev));
  4894. WARN(num_connectors != 1, "%d connectors attached to pipe %c\n",
  4895. num_connectors, pipe_name(pipe));
  4896. WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) &
  4897. (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE));
  4898. WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE);
  4899. if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock))
  4900. return -EINVAL;
  4901. /* Ensure that the cursor is valid for the new mode before changing... */
  4902. intel_crtc_update_cursor(crtc, true);
  4903. /* determine panel color depth */
  4904. dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp,
  4905. adjusted_mode);
  4906. DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe);
  4907. drm_mode_debug_printmodeline(mode);
  4908. if (is_dp && !is_cpu_edp)
  4909. intel_dp_set_m_n(crtc, mode, adjusted_mode);
  4910. intel_crtc->lowfreq_avail = false;
  4911. intel_set_pipe_timings(intel_crtc, mode, adjusted_mode);
  4912. if (!is_dp || is_cpu_edp)
  4913. ironlake_set_m_n(crtc, mode, adjusted_mode);
  4914. haswell_set_pipeconf(crtc, adjusted_mode, dither);
  4915. intel_set_pipe_csc(crtc, adjusted_mode);
  4916. /* Set up the display plane register */
  4917. I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE);
  4918. POSTING_READ(DSPCNTR(plane));
  4919. ret = intel_pipe_set_base(crtc, x, y, fb);
  4920. intel_update_watermarks(dev);
  4921. intel_update_linetime_watermarks(dev, pipe, adjusted_mode);
  4922. return ret;
  4923. }
  4924. static int intel_crtc_mode_set(struct drm_crtc *crtc,
  4925. struct drm_display_mode *mode,
  4926. struct drm_display_mode *adjusted_mode,
  4927. int x, int y,
  4928. struct drm_framebuffer *fb)
  4929. {
  4930. struct drm_device *dev = crtc->dev;
  4931. struct drm_i915_private *dev_priv = dev->dev_private;
  4932. struct drm_encoder_helper_funcs *encoder_funcs;
  4933. struct intel_encoder *encoder;
  4934. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  4935. int pipe = intel_crtc->pipe;
  4936. int ret;
  4937. if (IS_HASWELL(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))
  4938. intel_crtc->cpu_transcoder = TRANSCODER_EDP;
  4939. else
  4940. intel_crtc->cpu_transcoder = pipe;
  4941. drm_vblank_pre_modeset(dev, pipe);
  4942. ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode,
  4943. x, y, fb);
  4944. drm_vblank_post_modeset(dev, pipe);
  4945. if (ret != 0)
  4946. return ret;
  4947. for_each_encoder_on_crtc(dev, crtc, encoder) {
  4948. DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n",
  4949. encoder->base.base.id,
  4950. drm_get_encoder_name(&encoder->base),
  4951. mode->base.id, mode->name);
  4952. encoder_funcs = encoder->base.helper_private;
  4953. encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode);
  4954. }
  4955. return 0;
  4956. }
  4957. static bool intel_eld_uptodate(struct drm_connector *connector,
  4958. int reg_eldv, uint32_t bits_eldv,
  4959. int reg_elda, uint32_t bits_elda,
  4960. int reg_edid)
  4961. {
  4962. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4963. uint8_t *eld = connector->eld;
  4964. uint32_t i;
  4965. i = I915_READ(reg_eldv);
  4966. i &= bits_eldv;
  4967. if (!eld[0])
  4968. return !i;
  4969. if (!i)
  4970. return false;
  4971. i = I915_READ(reg_elda);
  4972. i &= ~bits_elda;
  4973. I915_WRITE(reg_elda, i);
  4974. for (i = 0; i < eld[2]; i++)
  4975. if (I915_READ(reg_edid) != *((uint32_t *)eld + i))
  4976. return false;
  4977. return true;
  4978. }
  4979. static void g4x_write_eld(struct drm_connector *connector,
  4980. struct drm_crtc *crtc)
  4981. {
  4982. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  4983. uint8_t *eld = connector->eld;
  4984. uint32_t eldv;
  4985. uint32_t len;
  4986. uint32_t i;
  4987. i = I915_READ(G4X_AUD_VID_DID);
  4988. if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL)
  4989. eldv = G4X_ELDV_DEVCL_DEVBLC;
  4990. else
  4991. eldv = G4X_ELDV_DEVCTG;
  4992. if (intel_eld_uptodate(connector,
  4993. G4X_AUD_CNTL_ST, eldv,
  4994. G4X_AUD_CNTL_ST, G4X_ELD_ADDR,
  4995. G4X_HDMIW_HDMIEDID))
  4996. return;
  4997. i = I915_READ(G4X_AUD_CNTL_ST);
  4998. i &= ~(eldv | G4X_ELD_ADDR);
  4999. len = (i >> 9) & 0x1f; /* ELD buffer size */
  5000. I915_WRITE(G4X_AUD_CNTL_ST, i);
  5001. if (!eld[0])
  5002. return;
  5003. len = min_t(uint8_t, eld[2], len);
  5004. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5005. for (i = 0; i < len; i++)
  5006. I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i));
  5007. i = I915_READ(G4X_AUD_CNTL_ST);
  5008. i |= eldv;
  5009. I915_WRITE(G4X_AUD_CNTL_ST, i);
  5010. }
  5011. static void haswell_write_eld(struct drm_connector *connector,
  5012. struct drm_crtc *crtc)
  5013. {
  5014. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  5015. uint8_t *eld = connector->eld;
  5016. struct drm_device *dev = crtc->dev;
  5017. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5018. uint32_t eldv;
  5019. uint32_t i;
  5020. int len;
  5021. int pipe = to_intel_crtc(crtc)->pipe;
  5022. int tmp;
  5023. int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe);
  5024. int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe);
  5025. int aud_config = HSW_AUD_CFG(pipe);
  5026. int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD;
  5027. DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n");
  5028. /* Audio output enable */
  5029. DRM_DEBUG_DRIVER("HDMI audio: enable codec\n");
  5030. tmp = I915_READ(aud_cntrl_st2);
  5031. tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4));
  5032. I915_WRITE(aud_cntrl_st2, tmp);
  5033. /* Wait for 1 vertical blank */
  5034. intel_wait_for_vblank(dev, pipe);
  5035. /* Set ELD valid state */
  5036. tmp = I915_READ(aud_cntrl_st2);
  5037. DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp);
  5038. tmp |= (AUDIO_ELD_VALID_A << (pipe * 4));
  5039. I915_WRITE(aud_cntrl_st2, tmp);
  5040. tmp = I915_READ(aud_cntrl_st2);
  5041. DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp);
  5042. /* Enable HDMI mode */
  5043. tmp = I915_READ(aud_config);
  5044. DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp);
  5045. /* clear N_programing_enable and N_value_index */
  5046. tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE);
  5047. I915_WRITE(aud_config, tmp);
  5048. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  5049. eldv = AUDIO_ELD_VALID_A << (pipe * 4);
  5050. intel_crtc->eld_vld = true;
  5051. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  5052. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  5053. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  5054. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  5055. } else
  5056. I915_WRITE(aud_config, 0);
  5057. if (intel_eld_uptodate(connector,
  5058. aud_cntrl_st2, eldv,
  5059. aud_cntl_st, IBX_ELD_ADDRESS,
  5060. hdmiw_hdmiedid))
  5061. return;
  5062. i = I915_READ(aud_cntrl_st2);
  5063. i &= ~eldv;
  5064. I915_WRITE(aud_cntrl_st2, i);
  5065. if (!eld[0])
  5066. return;
  5067. i = I915_READ(aud_cntl_st);
  5068. i &= ~IBX_ELD_ADDRESS;
  5069. I915_WRITE(aud_cntl_st, i);
  5070. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5071. DRM_DEBUG_DRIVER("port num:%d\n", i);
  5072. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5073. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5074. for (i = 0; i < len; i++)
  5075. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5076. i = I915_READ(aud_cntrl_st2);
  5077. i |= eldv;
  5078. I915_WRITE(aud_cntrl_st2, i);
  5079. }
  5080. static void ironlake_write_eld(struct drm_connector *connector,
  5081. struct drm_crtc *crtc)
  5082. {
  5083. struct drm_i915_private *dev_priv = connector->dev->dev_private;
  5084. uint8_t *eld = connector->eld;
  5085. uint32_t eldv;
  5086. uint32_t i;
  5087. int len;
  5088. int hdmiw_hdmiedid;
  5089. int aud_config;
  5090. int aud_cntl_st;
  5091. int aud_cntrl_st2;
  5092. int pipe = to_intel_crtc(crtc)->pipe;
  5093. if (HAS_PCH_IBX(connector->dev)) {
  5094. hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe);
  5095. aud_config = IBX_AUD_CFG(pipe);
  5096. aud_cntl_st = IBX_AUD_CNTL_ST(pipe);
  5097. aud_cntrl_st2 = IBX_AUD_CNTL_ST2;
  5098. } else {
  5099. hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe);
  5100. aud_config = CPT_AUD_CFG(pipe);
  5101. aud_cntl_st = CPT_AUD_CNTL_ST(pipe);
  5102. aud_cntrl_st2 = CPT_AUD_CNTRL_ST2;
  5103. }
  5104. DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe));
  5105. i = I915_READ(aud_cntl_st);
  5106. i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */
  5107. if (!i) {
  5108. DRM_DEBUG_DRIVER("Audio directed to unknown port\n");
  5109. /* operate blindly on all ports */
  5110. eldv = IBX_ELD_VALIDB;
  5111. eldv |= IBX_ELD_VALIDB << 4;
  5112. eldv |= IBX_ELD_VALIDB << 8;
  5113. } else {
  5114. DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i);
  5115. eldv = IBX_ELD_VALIDB << ((i - 1) * 4);
  5116. }
  5117. if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) {
  5118. DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n");
  5119. eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */
  5120. I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */
  5121. } else
  5122. I915_WRITE(aud_config, 0);
  5123. if (intel_eld_uptodate(connector,
  5124. aud_cntrl_st2, eldv,
  5125. aud_cntl_st, IBX_ELD_ADDRESS,
  5126. hdmiw_hdmiedid))
  5127. return;
  5128. i = I915_READ(aud_cntrl_st2);
  5129. i &= ~eldv;
  5130. I915_WRITE(aud_cntrl_st2, i);
  5131. if (!eld[0])
  5132. return;
  5133. i = I915_READ(aud_cntl_st);
  5134. i &= ~IBX_ELD_ADDRESS;
  5135. I915_WRITE(aud_cntl_st, i);
  5136. len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */
  5137. DRM_DEBUG_DRIVER("ELD size %d\n", len);
  5138. for (i = 0; i < len; i++)
  5139. I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i));
  5140. i = I915_READ(aud_cntrl_st2);
  5141. i |= eldv;
  5142. I915_WRITE(aud_cntrl_st2, i);
  5143. }
  5144. void intel_write_eld(struct drm_encoder *encoder,
  5145. struct drm_display_mode *mode)
  5146. {
  5147. struct drm_crtc *crtc = encoder->crtc;
  5148. struct drm_connector *connector;
  5149. struct drm_device *dev = encoder->dev;
  5150. struct drm_i915_private *dev_priv = dev->dev_private;
  5151. connector = drm_select_eld(encoder, mode);
  5152. if (!connector)
  5153. return;
  5154. DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5155. connector->base.id,
  5156. drm_get_connector_name(connector),
  5157. connector->encoder->base.id,
  5158. drm_get_encoder_name(connector->encoder));
  5159. connector->eld[6] = drm_av_sync_delay(connector, mode) / 2;
  5160. if (dev_priv->display.write_eld)
  5161. dev_priv->display.write_eld(connector, crtc);
  5162. }
  5163. /** Loads the palette/gamma unit for the CRTC with the prepared values */
  5164. void intel_crtc_load_lut(struct drm_crtc *crtc)
  5165. {
  5166. struct drm_device *dev = crtc->dev;
  5167. struct drm_i915_private *dev_priv = dev->dev_private;
  5168. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5169. int palreg = PALETTE(intel_crtc->pipe);
  5170. int i;
  5171. /* The clocks have to be on to load the palette. */
  5172. if (!crtc->enabled || !intel_crtc->active)
  5173. return;
  5174. /* use legacy palette for Ironlake */
  5175. if (HAS_PCH_SPLIT(dev))
  5176. palreg = LGC_PALETTE(intel_crtc->pipe);
  5177. for (i = 0; i < 256; i++) {
  5178. I915_WRITE(palreg + 4 * i,
  5179. (intel_crtc->lut_r[i] << 16) |
  5180. (intel_crtc->lut_g[i] << 8) |
  5181. intel_crtc->lut_b[i]);
  5182. }
  5183. }
  5184. static void i845_update_cursor(struct drm_crtc *crtc, u32 base)
  5185. {
  5186. struct drm_device *dev = crtc->dev;
  5187. struct drm_i915_private *dev_priv = dev->dev_private;
  5188. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5189. bool visible = base != 0;
  5190. u32 cntl;
  5191. if (intel_crtc->cursor_visible == visible)
  5192. return;
  5193. cntl = I915_READ(_CURACNTR);
  5194. if (visible) {
  5195. /* On these chipsets we can only modify the base whilst
  5196. * the cursor is disabled.
  5197. */
  5198. I915_WRITE(_CURABASE, base);
  5199. cntl &= ~(CURSOR_FORMAT_MASK);
  5200. /* XXX width must be 64, stride 256 => 0x00 << 28 */
  5201. cntl |= CURSOR_ENABLE |
  5202. CURSOR_GAMMA_ENABLE |
  5203. CURSOR_FORMAT_ARGB;
  5204. } else
  5205. cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE);
  5206. I915_WRITE(_CURACNTR, cntl);
  5207. intel_crtc->cursor_visible = visible;
  5208. }
  5209. static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base)
  5210. {
  5211. struct drm_device *dev = crtc->dev;
  5212. struct drm_i915_private *dev_priv = dev->dev_private;
  5213. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5214. int pipe = intel_crtc->pipe;
  5215. bool visible = base != 0;
  5216. if (intel_crtc->cursor_visible != visible) {
  5217. uint32_t cntl = I915_READ(CURCNTR(pipe));
  5218. if (base) {
  5219. cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT);
  5220. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5221. cntl |= pipe << 28; /* Connect to correct pipe */
  5222. } else {
  5223. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5224. cntl |= CURSOR_MODE_DISABLE;
  5225. }
  5226. I915_WRITE(CURCNTR(pipe), cntl);
  5227. intel_crtc->cursor_visible = visible;
  5228. }
  5229. /* and commit changes on next vblank */
  5230. I915_WRITE(CURBASE(pipe), base);
  5231. }
  5232. static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
  5233. {
  5234. struct drm_device *dev = crtc->dev;
  5235. struct drm_i915_private *dev_priv = dev->dev_private;
  5236. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5237. int pipe = intel_crtc->pipe;
  5238. bool visible = base != 0;
  5239. if (intel_crtc->cursor_visible != visible) {
  5240. uint32_t cntl = I915_READ(CURCNTR_IVB(pipe));
  5241. if (base) {
  5242. cntl &= ~CURSOR_MODE;
  5243. cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE;
  5244. } else {
  5245. cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE);
  5246. cntl |= CURSOR_MODE_DISABLE;
  5247. }
  5248. if (IS_HASWELL(dev))
  5249. cntl |= CURSOR_PIPE_CSC_ENABLE;
  5250. I915_WRITE(CURCNTR_IVB(pipe), cntl);
  5251. intel_crtc->cursor_visible = visible;
  5252. }
  5253. /* and commit changes on next vblank */
  5254. I915_WRITE(CURBASE_IVB(pipe), base);
  5255. }
  5256. /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
  5257. static void intel_crtc_update_cursor(struct drm_crtc *crtc,
  5258. bool on)
  5259. {
  5260. struct drm_device *dev = crtc->dev;
  5261. struct drm_i915_private *dev_priv = dev->dev_private;
  5262. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5263. int pipe = intel_crtc->pipe;
  5264. int x = intel_crtc->cursor_x;
  5265. int y = intel_crtc->cursor_y;
  5266. u32 base, pos;
  5267. bool visible;
  5268. pos = 0;
  5269. if (on && crtc->enabled && crtc->fb) {
  5270. base = intel_crtc->cursor_addr;
  5271. if (x > (int) crtc->fb->width)
  5272. base = 0;
  5273. if (y > (int) crtc->fb->height)
  5274. base = 0;
  5275. } else
  5276. base = 0;
  5277. if (x < 0) {
  5278. if (x + intel_crtc->cursor_width < 0)
  5279. base = 0;
  5280. pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
  5281. x = -x;
  5282. }
  5283. pos |= x << CURSOR_X_SHIFT;
  5284. if (y < 0) {
  5285. if (y + intel_crtc->cursor_height < 0)
  5286. base = 0;
  5287. pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
  5288. y = -y;
  5289. }
  5290. pos |= y << CURSOR_Y_SHIFT;
  5291. visible = base != 0;
  5292. if (!visible && !intel_crtc->cursor_visible)
  5293. return;
  5294. if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
  5295. I915_WRITE(CURPOS_IVB(pipe), pos);
  5296. ivb_update_cursor(crtc, base);
  5297. } else {
  5298. I915_WRITE(CURPOS(pipe), pos);
  5299. if (IS_845G(dev) || IS_I865G(dev))
  5300. i845_update_cursor(crtc, base);
  5301. else
  5302. i9xx_update_cursor(crtc, base);
  5303. }
  5304. }
  5305. static int intel_crtc_cursor_set(struct drm_crtc *crtc,
  5306. struct drm_file *file,
  5307. uint32_t handle,
  5308. uint32_t width, uint32_t height)
  5309. {
  5310. struct drm_device *dev = crtc->dev;
  5311. struct drm_i915_private *dev_priv = dev->dev_private;
  5312. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5313. struct drm_i915_gem_object *obj;
  5314. uint32_t addr;
  5315. int ret;
  5316. /* if we want to turn off the cursor ignore width and height */
  5317. if (!handle) {
  5318. DRM_DEBUG_KMS("cursor off\n");
  5319. addr = 0;
  5320. obj = NULL;
  5321. mutex_lock(&dev->struct_mutex);
  5322. goto finish;
  5323. }
  5324. /* Currently we only support 64x64 cursors */
  5325. if (width != 64 || height != 64) {
  5326. DRM_ERROR("we currently only support 64x64 cursors\n");
  5327. return -EINVAL;
  5328. }
  5329. obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
  5330. if (&obj->base == NULL)
  5331. return -ENOENT;
  5332. if (obj->base.size < width * height * 4) {
  5333. DRM_ERROR("buffer is to small\n");
  5334. ret = -ENOMEM;
  5335. goto fail;
  5336. }
  5337. /* we only need to pin inside GTT if cursor is non-phy */
  5338. mutex_lock(&dev->struct_mutex);
  5339. if (!dev_priv->info->cursor_needs_physical) {
  5340. if (obj->tiling_mode) {
  5341. DRM_ERROR("cursor cannot be tiled\n");
  5342. ret = -EINVAL;
  5343. goto fail_locked;
  5344. }
  5345. ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL);
  5346. if (ret) {
  5347. DRM_ERROR("failed to move cursor bo into the GTT\n");
  5348. goto fail_locked;
  5349. }
  5350. ret = i915_gem_object_put_fence(obj);
  5351. if (ret) {
  5352. DRM_ERROR("failed to release fence for cursor");
  5353. goto fail_unpin;
  5354. }
  5355. addr = obj->gtt_offset;
  5356. } else {
  5357. int align = IS_I830(dev) ? 16 * 1024 : 256;
  5358. ret = i915_gem_attach_phys_object(dev, obj,
  5359. (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1,
  5360. align);
  5361. if (ret) {
  5362. DRM_ERROR("failed to attach phys object\n");
  5363. goto fail_locked;
  5364. }
  5365. addr = obj->phys_obj->handle->busaddr;
  5366. }
  5367. if (IS_GEN2(dev))
  5368. I915_WRITE(CURSIZE, (height << 12) | width);
  5369. finish:
  5370. if (intel_crtc->cursor_bo) {
  5371. if (dev_priv->info->cursor_needs_physical) {
  5372. if (intel_crtc->cursor_bo != obj)
  5373. i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
  5374. } else
  5375. i915_gem_object_unpin(intel_crtc->cursor_bo);
  5376. drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
  5377. }
  5378. mutex_unlock(&dev->struct_mutex);
  5379. intel_crtc->cursor_addr = addr;
  5380. intel_crtc->cursor_bo = obj;
  5381. intel_crtc->cursor_width = width;
  5382. intel_crtc->cursor_height = height;
  5383. intel_crtc_update_cursor(crtc, true);
  5384. return 0;
  5385. fail_unpin:
  5386. i915_gem_object_unpin(obj);
  5387. fail_locked:
  5388. mutex_unlock(&dev->struct_mutex);
  5389. fail:
  5390. drm_gem_object_unreference_unlocked(&obj->base);
  5391. return ret;
  5392. }
  5393. static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
  5394. {
  5395. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5396. intel_crtc->cursor_x = x;
  5397. intel_crtc->cursor_y = y;
  5398. intel_crtc_update_cursor(crtc, true);
  5399. return 0;
  5400. }
  5401. /** Sets the color ramps on behalf of RandR */
  5402. void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green,
  5403. u16 blue, int regno)
  5404. {
  5405. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5406. intel_crtc->lut_r[regno] = red >> 8;
  5407. intel_crtc->lut_g[regno] = green >> 8;
  5408. intel_crtc->lut_b[regno] = blue >> 8;
  5409. }
  5410. void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green,
  5411. u16 *blue, int regno)
  5412. {
  5413. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5414. *red = intel_crtc->lut_r[regno] << 8;
  5415. *green = intel_crtc->lut_g[regno] << 8;
  5416. *blue = intel_crtc->lut_b[regno] << 8;
  5417. }
  5418. static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green,
  5419. u16 *blue, uint32_t start, uint32_t size)
  5420. {
  5421. int end = (start + size > 256) ? 256 : start + size, i;
  5422. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5423. for (i = start; i < end; i++) {
  5424. intel_crtc->lut_r[i] = red[i] >> 8;
  5425. intel_crtc->lut_g[i] = green[i] >> 8;
  5426. intel_crtc->lut_b[i] = blue[i] >> 8;
  5427. }
  5428. intel_crtc_load_lut(crtc);
  5429. }
  5430. /**
  5431. * Get a pipe with a simple mode set on it for doing load-based monitor
  5432. * detection.
  5433. *
  5434. * It will be up to the load-detect code to adjust the pipe as appropriate for
  5435. * its requirements. The pipe will be connected to no other encoders.
  5436. *
  5437. * Currently this code will only succeed if there is a pipe with no encoders
  5438. * configured for it. In the future, it could choose to temporarily disable
  5439. * some outputs to free up a pipe for its use.
  5440. *
  5441. * \return crtc, or NULL if no pipes are available.
  5442. */
  5443. /* VESA 640x480x72Hz mode to set on the pipe */
  5444. static struct drm_display_mode load_detect_mode = {
  5445. DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664,
  5446. 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC),
  5447. };
  5448. static struct drm_framebuffer *
  5449. intel_framebuffer_create(struct drm_device *dev,
  5450. struct drm_mode_fb_cmd2 *mode_cmd,
  5451. struct drm_i915_gem_object *obj)
  5452. {
  5453. struct intel_framebuffer *intel_fb;
  5454. int ret;
  5455. intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL);
  5456. if (!intel_fb) {
  5457. drm_gem_object_unreference_unlocked(&obj->base);
  5458. return ERR_PTR(-ENOMEM);
  5459. }
  5460. ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj);
  5461. if (ret) {
  5462. drm_gem_object_unreference_unlocked(&obj->base);
  5463. kfree(intel_fb);
  5464. return ERR_PTR(ret);
  5465. }
  5466. return &intel_fb->base;
  5467. }
  5468. static u32
  5469. intel_framebuffer_pitch_for_width(int width, int bpp)
  5470. {
  5471. u32 pitch = DIV_ROUND_UP(width * bpp, 8);
  5472. return ALIGN(pitch, 64);
  5473. }
  5474. static u32
  5475. intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp)
  5476. {
  5477. u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp);
  5478. return ALIGN(pitch * mode->vdisplay, PAGE_SIZE);
  5479. }
  5480. static struct drm_framebuffer *
  5481. intel_framebuffer_create_for_mode(struct drm_device *dev,
  5482. struct drm_display_mode *mode,
  5483. int depth, int bpp)
  5484. {
  5485. struct drm_i915_gem_object *obj;
  5486. struct drm_mode_fb_cmd2 mode_cmd = { 0 };
  5487. obj = i915_gem_alloc_object(dev,
  5488. intel_framebuffer_size_for_mode(mode, bpp));
  5489. if (obj == NULL)
  5490. return ERR_PTR(-ENOMEM);
  5491. mode_cmd.width = mode->hdisplay;
  5492. mode_cmd.height = mode->vdisplay;
  5493. mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width,
  5494. bpp);
  5495. mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth);
  5496. return intel_framebuffer_create(dev, &mode_cmd, obj);
  5497. }
  5498. static struct drm_framebuffer *
  5499. mode_fits_in_fbdev(struct drm_device *dev,
  5500. struct drm_display_mode *mode)
  5501. {
  5502. struct drm_i915_private *dev_priv = dev->dev_private;
  5503. struct drm_i915_gem_object *obj;
  5504. struct drm_framebuffer *fb;
  5505. if (dev_priv->fbdev == NULL)
  5506. return NULL;
  5507. obj = dev_priv->fbdev->ifb.obj;
  5508. if (obj == NULL)
  5509. return NULL;
  5510. fb = &dev_priv->fbdev->ifb.base;
  5511. if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay,
  5512. fb->bits_per_pixel))
  5513. return NULL;
  5514. if (obj->base.size < mode->vdisplay * fb->pitches[0])
  5515. return NULL;
  5516. return fb;
  5517. }
  5518. bool intel_get_load_detect_pipe(struct drm_connector *connector,
  5519. struct drm_display_mode *mode,
  5520. struct intel_load_detect_pipe *old)
  5521. {
  5522. struct intel_crtc *intel_crtc;
  5523. struct intel_encoder *intel_encoder =
  5524. intel_attached_encoder(connector);
  5525. struct drm_crtc *possible_crtc;
  5526. struct drm_encoder *encoder = &intel_encoder->base;
  5527. struct drm_crtc *crtc = NULL;
  5528. struct drm_device *dev = encoder->dev;
  5529. struct drm_framebuffer *fb;
  5530. int i = -1;
  5531. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5532. connector->base.id, drm_get_connector_name(connector),
  5533. encoder->base.id, drm_get_encoder_name(encoder));
  5534. /*
  5535. * Algorithm gets a little messy:
  5536. *
  5537. * - if the connector already has an assigned crtc, use it (but make
  5538. * sure it's on first)
  5539. *
  5540. * - try to find the first unused crtc that can drive this connector,
  5541. * and use that if we find one
  5542. */
  5543. /* See if we already have a CRTC for this connector */
  5544. if (encoder->crtc) {
  5545. crtc = encoder->crtc;
  5546. mutex_lock(&crtc->mutex);
  5547. old->dpms_mode = connector->dpms;
  5548. old->load_detect_temp = false;
  5549. /* Make sure the crtc and connector are running */
  5550. if (connector->dpms != DRM_MODE_DPMS_ON)
  5551. connector->funcs->dpms(connector, DRM_MODE_DPMS_ON);
  5552. return true;
  5553. }
  5554. /* Find an unused one (if possible) */
  5555. list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) {
  5556. i++;
  5557. if (!(encoder->possible_crtcs & (1 << i)))
  5558. continue;
  5559. if (!possible_crtc->enabled) {
  5560. crtc = possible_crtc;
  5561. break;
  5562. }
  5563. }
  5564. /*
  5565. * If we didn't find an unused CRTC, don't use any.
  5566. */
  5567. if (!crtc) {
  5568. DRM_DEBUG_KMS("no pipe available for load-detect\n");
  5569. return false;
  5570. }
  5571. mutex_lock(&crtc->mutex);
  5572. intel_encoder->new_crtc = to_intel_crtc(crtc);
  5573. to_intel_connector(connector)->new_encoder = intel_encoder;
  5574. intel_crtc = to_intel_crtc(crtc);
  5575. old->dpms_mode = connector->dpms;
  5576. old->load_detect_temp = true;
  5577. old->release_fb = NULL;
  5578. if (!mode)
  5579. mode = &load_detect_mode;
  5580. /* We need a framebuffer large enough to accommodate all accesses
  5581. * that the plane may generate whilst we perform load detection.
  5582. * We can not rely on the fbcon either being present (we get called
  5583. * during its initialisation to detect all boot displays, or it may
  5584. * not even exist) or that it is large enough to satisfy the
  5585. * requested mode.
  5586. */
  5587. fb = mode_fits_in_fbdev(dev, mode);
  5588. if (fb == NULL) {
  5589. DRM_DEBUG_KMS("creating tmp fb for load-detection\n");
  5590. fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32);
  5591. old->release_fb = fb;
  5592. } else
  5593. DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n");
  5594. if (IS_ERR(fb)) {
  5595. DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n");
  5596. mutex_unlock(&crtc->mutex);
  5597. return false;
  5598. }
  5599. if (intel_set_mode(crtc, mode, 0, 0, fb)) {
  5600. DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n");
  5601. if (old->release_fb)
  5602. old->release_fb->funcs->destroy(old->release_fb);
  5603. mutex_unlock(&crtc->mutex);
  5604. return false;
  5605. }
  5606. /* let the connector get through one full cycle before testing */
  5607. intel_wait_for_vblank(dev, intel_crtc->pipe);
  5608. return true;
  5609. }
  5610. void intel_release_load_detect_pipe(struct drm_connector *connector,
  5611. struct intel_load_detect_pipe *old)
  5612. {
  5613. struct intel_encoder *intel_encoder =
  5614. intel_attached_encoder(connector);
  5615. struct drm_encoder *encoder = &intel_encoder->base;
  5616. struct drm_crtc *crtc = encoder->crtc;
  5617. DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n",
  5618. connector->base.id, drm_get_connector_name(connector),
  5619. encoder->base.id, drm_get_encoder_name(encoder));
  5620. if (old->load_detect_temp) {
  5621. to_intel_connector(connector)->new_encoder = NULL;
  5622. intel_encoder->new_crtc = NULL;
  5623. intel_set_mode(crtc, NULL, 0, 0, NULL);
  5624. if (old->release_fb) {
  5625. drm_framebuffer_unregister_private(old->release_fb);
  5626. drm_framebuffer_unreference(old->release_fb);
  5627. }
  5628. mutex_unlock(&crtc->mutex);
  5629. return;
  5630. }
  5631. /* Switch crtc and encoder back off if necessary */
  5632. if (old->dpms_mode != DRM_MODE_DPMS_ON)
  5633. connector->funcs->dpms(connector, old->dpms_mode);
  5634. mutex_unlock(&crtc->mutex);
  5635. }
  5636. /* Returns the clock of the currently programmed mode of the given pipe. */
  5637. static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc)
  5638. {
  5639. struct drm_i915_private *dev_priv = dev->dev_private;
  5640. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5641. int pipe = intel_crtc->pipe;
  5642. u32 dpll = I915_READ(DPLL(pipe));
  5643. u32 fp;
  5644. intel_clock_t clock;
  5645. if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0)
  5646. fp = I915_READ(FP0(pipe));
  5647. else
  5648. fp = I915_READ(FP1(pipe));
  5649. clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT;
  5650. if (IS_PINEVIEW(dev)) {
  5651. clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1;
  5652. clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5653. } else {
  5654. clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT;
  5655. clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT;
  5656. }
  5657. if (!IS_GEN2(dev)) {
  5658. if (IS_PINEVIEW(dev))
  5659. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >>
  5660. DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW);
  5661. else
  5662. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >>
  5663. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5664. switch (dpll & DPLL_MODE_MASK) {
  5665. case DPLLB_MODE_DAC_SERIAL:
  5666. clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ?
  5667. 5 : 10;
  5668. break;
  5669. case DPLLB_MODE_LVDS:
  5670. clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ?
  5671. 7 : 14;
  5672. break;
  5673. default:
  5674. DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed "
  5675. "mode\n", (int)(dpll & DPLL_MODE_MASK));
  5676. return 0;
  5677. }
  5678. /* XXX: Handle the 100Mhz refclk */
  5679. intel_clock(dev, 96000, &clock);
  5680. } else {
  5681. bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN);
  5682. if (is_lvds) {
  5683. clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >>
  5684. DPLL_FPA01_P1_POST_DIV_SHIFT);
  5685. clock.p2 = 14;
  5686. if ((dpll & PLL_REF_INPUT_MASK) ==
  5687. PLLB_REF_INPUT_SPREADSPECTRUMIN) {
  5688. /* XXX: might not be 66MHz */
  5689. intel_clock(dev, 66000, &clock);
  5690. } else
  5691. intel_clock(dev, 48000, &clock);
  5692. } else {
  5693. if (dpll & PLL_P1_DIVIDE_BY_TWO)
  5694. clock.p1 = 2;
  5695. else {
  5696. clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >>
  5697. DPLL_FPA01_P1_POST_DIV_SHIFT) + 2;
  5698. }
  5699. if (dpll & PLL_P2_DIVIDE_BY_4)
  5700. clock.p2 = 4;
  5701. else
  5702. clock.p2 = 2;
  5703. intel_clock(dev, 48000, &clock);
  5704. }
  5705. }
  5706. /* XXX: It would be nice to validate the clocks, but we can't reuse
  5707. * i830PllIsValid() because it relies on the xf86_config connector
  5708. * configuration being accurate, which it isn't necessarily.
  5709. */
  5710. return clock.dot;
  5711. }
  5712. /** Returns the currently programmed mode of the given pipe. */
  5713. struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev,
  5714. struct drm_crtc *crtc)
  5715. {
  5716. struct drm_i915_private *dev_priv = dev->dev_private;
  5717. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5718. enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder;
  5719. struct drm_display_mode *mode;
  5720. int htot = I915_READ(HTOTAL(cpu_transcoder));
  5721. int hsync = I915_READ(HSYNC(cpu_transcoder));
  5722. int vtot = I915_READ(VTOTAL(cpu_transcoder));
  5723. int vsync = I915_READ(VSYNC(cpu_transcoder));
  5724. mode = kzalloc(sizeof(*mode), GFP_KERNEL);
  5725. if (!mode)
  5726. return NULL;
  5727. mode->clock = intel_crtc_clock_get(dev, crtc);
  5728. mode->hdisplay = (htot & 0xffff) + 1;
  5729. mode->htotal = ((htot & 0xffff0000) >> 16) + 1;
  5730. mode->hsync_start = (hsync & 0xffff) + 1;
  5731. mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1;
  5732. mode->vdisplay = (vtot & 0xffff) + 1;
  5733. mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1;
  5734. mode->vsync_start = (vsync & 0xffff) + 1;
  5735. mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1;
  5736. drm_mode_set_name(mode);
  5737. return mode;
  5738. }
  5739. static void intel_increase_pllclock(struct drm_crtc *crtc)
  5740. {
  5741. struct drm_device *dev = crtc->dev;
  5742. drm_i915_private_t *dev_priv = dev->dev_private;
  5743. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5744. int pipe = intel_crtc->pipe;
  5745. int dpll_reg = DPLL(pipe);
  5746. int dpll;
  5747. if (HAS_PCH_SPLIT(dev))
  5748. return;
  5749. if (!dev_priv->lvds_downclock_avail)
  5750. return;
  5751. dpll = I915_READ(dpll_reg);
  5752. if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) {
  5753. DRM_DEBUG_DRIVER("upclocking LVDS\n");
  5754. assert_panel_unlocked(dev_priv, pipe);
  5755. dpll &= ~DISPLAY_RATE_SELECT_FPA1;
  5756. I915_WRITE(dpll_reg, dpll);
  5757. intel_wait_for_vblank(dev, pipe);
  5758. dpll = I915_READ(dpll_reg);
  5759. if (dpll & DISPLAY_RATE_SELECT_FPA1)
  5760. DRM_DEBUG_DRIVER("failed to upclock LVDS!\n");
  5761. }
  5762. }
  5763. static void intel_decrease_pllclock(struct drm_crtc *crtc)
  5764. {
  5765. struct drm_device *dev = crtc->dev;
  5766. drm_i915_private_t *dev_priv = dev->dev_private;
  5767. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5768. if (HAS_PCH_SPLIT(dev))
  5769. return;
  5770. if (!dev_priv->lvds_downclock_avail)
  5771. return;
  5772. /*
  5773. * Since this is called by a timer, we should never get here in
  5774. * the manual case.
  5775. */
  5776. if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) {
  5777. int pipe = intel_crtc->pipe;
  5778. int dpll_reg = DPLL(pipe);
  5779. int dpll;
  5780. DRM_DEBUG_DRIVER("downclocking LVDS\n");
  5781. assert_panel_unlocked(dev_priv, pipe);
  5782. dpll = I915_READ(dpll_reg);
  5783. dpll |= DISPLAY_RATE_SELECT_FPA1;
  5784. I915_WRITE(dpll_reg, dpll);
  5785. intel_wait_for_vblank(dev, pipe);
  5786. dpll = I915_READ(dpll_reg);
  5787. if (!(dpll & DISPLAY_RATE_SELECT_FPA1))
  5788. DRM_DEBUG_DRIVER("failed to downclock LVDS!\n");
  5789. }
  5790. }
  5791. void intel_mark_busy(struct drm_device *dev)
  5792. {
  5793. i915_update_gfx_val(dev->dev_private);
  5794. }
  5795. void intel_mark_idle(struct drm_device *dev)
  5796. {
  5797. struct drm_crtc *crtc;
  5798. if (!i915_powersave)
  5799. return;
  5800. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5801. if (!crtc->fb)
  5802. continue;
  5803. intel_decrease_pllclock(crtc);
  5804. }
  5805. }
  5806. void intel_mark_fb_busy(struct drm_i915_gem_object *obj)
  5807. {
  5808. struct drm_device *dev = obj->base.dev;
  5809. struct drm_crtc *crtc;
  5810. if (!i915_powersave)
  5811. return;
  5812. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  5813. if (!crtc->fb)
  5814. continue;
  5815. if (to_intel_framebuffer(crtc->fb)->obj == obj)
  5816. intel_increase_pllclock(crtc);
  5817. }
  5818. }
  5819. static void intel_crtc_destroy(struct drm_crtc *crtc)
  5820. {
  5821. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5822. struct drm_device *dev = crtc->dev;
  5823. struct intel_unpin_work *work;
  5824. unsigned long flags;
  5825. spin_lock_irqsave(&dev->event_lock, flags);
  5826. work = intel_crtc->unpin_work;
  5827. intel_crtc->unpin_work = NULL;
  5828. spin_unlock_irqrestore(&dev->event_lock, flags);
  5829. if (work) {
  5830. cancel_work_sync(&work->work);
  5831. kfree(work);
  5832. }
  5833. drm_crtc_cleanup(crtc);
  5834. kfree(intel_crtc);
  5835. }
  5836. static void intel_unpin_work_fn(struct work_struct *__work)
  5837. {
  5838. struct intel_unpin_work *work =
  5839. container_of(__work, struct intel_unpin_work, work);
  5840. struct drm_device *dev = work->crtc->dev;
  5841. mutex_lock(&dev->struct_mutex);
  5842. intel_unpin_fb_obj(work->old_fb_obj);
  5843. drm_gem_object_unreference(&work->pending_flip_obj->base);
  5844. drm_gem_object_unreference(&work->old_fb_obj->base);
  5845. intel_update_fbc(dev);
  5846. mutex_unlock(&dev->struct_mutex);
  5847. BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0);
  5848. atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count);
  5849. kfree(work);
  5850. }
  5851. static void do_intel_finish_page_flip(struct drm_device *dev,
  5852. struct drm_crtc *crtc)
  5853. {
  5854. drm_i915_private_t *dev_priv = dev->dev_private;
  5855. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5856. struct intel_unpin_work *work;
  5857. struct drm_i915_gem_object *obj;
  5858. unsigned long flags;
  5859. /* Ignore early vblank irqs */
  5860. if (intel_crtc == NULL)
  5861. return;
  5862. spin_lock_irqsave(&dev->event_lock, flags);
  5863. work = intel_crtc->unpin_work;
  5864. /* Ensure we don't miss a work->pending update ... */
  5865. smp_rmb();
  5866. if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) {
  5867. spin_unlock_irqrestore(&dev->event_lock, flags);
  5868. return;
  5869. }
  5870. /* and that the unpin work is consistent wrt ->pending. */
  5871. smp_rmb();
  5872. intel_crtc->unpin_work = NULL;
  5873. if (work->event)
  5874. drm_send_vblank_event(dev, intel_crtc->pipe, work->event);
  5875. drm_vblank_put(dev, intel_crtc->pipe);
  5876. spin_unlock_irqrestore(&dev->event_lock, flags);
  5877. obj = work->old_fb_obj;
  5878. wake_up_all(&dev_priv->pending_flip_queue);
  5879. queue_work(dev_priv->wq, &work->work);
  5880. trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj);
  5881. }
  5882. void intel_finish_page_flip(struct drm_device *dev, int pipe)
  5883. {
  5884. drm_i915_private_t *dev_priv = dev->dev_private;
  5885. struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
  5886. do_intel_finish_page_flip(dev, crtc);
  5887. }
  5888. void intel_finish_page_flip_plane(struct drm_device *dev, int plane)
  5889. {
  5890. drm_i915_private_t *dev_priv = dev->dev_private;
  5891. struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane];
  5892. do_intel_finish_page_flip(dev, crtc);
  5893. }
  5894. void intel_prepare_page_flip(struct drm_device *dev, int plane)
  5895. {
  5896. drm_i915_private_t *dev_priv = dev->dev_private;
  5897. struct intel_crtc *intel_crtc =
  5898. to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]);
  5899. unsigned long flags;
  5900. /* NB: An MMIO update of the plane base pointer will also
  5901. * generate a page-flip completion irq, i.e. every modeset
  5902. * is also accompanied by a spurious intel_prepare_page_flip().
  5903. */
  5904. spin_lock_irqsave(&dev->event_lock, flags);
  5905. if (intel_crtc->unpin_work)
  5906. atomic_inc_not_zero(&intel_crtc->unpin_work->pending);
  5907. spin_unlock_irqrestore(&dev->event_lock, flags);
  5908. }
  5909. inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc)
  5910. {
  5911. /* Ensure that the work item is consistent when activating it ... */
  5912. smp_wmb();
  5913. atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING);
  5914. /* and that it is marked active as soon as the irq could fire. */
  5915. smp_wmb();
  5916. }
  5917. static int intel_gen2_queue_flip(struct drm_device *dev,
  5918. struct drm_crtc *crtc,
  5919. struct drm_framebuffer *fb,
  5920. struct drm_i915_gem_object *obj)
  5921. {
  5922. struct drm_i915_private *dev_priv = dev->dev_private;
  5923. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5924. u32 flip_mask;
  5925. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5926. int ret;
  5927. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5928. if (ret)
  5929. goto err;
  5930. ret = intel_ring_begin(ring, 6);
  5931. if (ret)
  5932. goto err_unpin;
  5933. /* Can't queue multiple flips, so wait for the previous
  5934. * one to finish before executing the next.
  5935. */
  5936. if (intel_crtc->plane)
  5937. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5938. else
  5939. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5940. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5941. intel_ring_emit(ring, MI_NOOP);
  5942. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  5943. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5944. intel_ring_emit(ring, fb->pitches[0]);
  5945. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5946. intel_ring_emit(ring, 0); /* aux display base address, unused */
  5947. intel_mark_page_flip_active(intel_crtc);
  5948. intel_ring_advance(ring);
  5949. return 0;
  5950. err_unpin:
  5951. intel_unpin_fb_obj(obj);
  5952. err:
  5953. return ret;
  5954. }
  5955. static int intel_gen3_queue_flip(struct drm_device *dev,
  5956. struct drm_crtc *crtc,
  5957. struct drm_framebuffer *fb,
  5958. struct drm_i915_gem_object *obj)
  5959. {
  5960. struct drm_i915_private *dev_priv = dev->dev_private;
  5961. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5962. u32 flip_mask;
  5963. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5964. int ret;
  5965. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  5966. if (ret)
  5967. goto err;
  5968. ret = intel_ring_begin(ring, 6);
  5969. if (ret)
  5970. goto err_unpin;
  5971. if (intel_crtc->plane)
  5972. flip_mask = MI_WAIT_FOR_PLANE_B_FLIP;
  5973. else
  5974. flip_mask = MI_WAIT_FOR_PLANE_A_FLIP;
  5975. intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask);
  5976. intel_ring_emit(ring, MI_NOOP);
  5977. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 |
  5978. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  5979. intel_ring_emit(ring, fb->pitches[0]);
  5980. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  5981. intel_ring_emit(ring, MI_NOOP);
  5982. intel_mark_page_flip_active(intel_crtc);
  5983. intel_ring_advance(ring);
  5984. return 0;
  5985. err_unpin:
  5986. intel_unpin_fb_obj(obj);
  5987. err:
  5988. return ret;
  5989. }
  5990. static int intel_gen4_queue_flip(struct drm_device *dev,
  5991. struct drm_crtc *crtc,
  5992. struct drm_framebuffer *fb,
  5993. struct drm_i915_gem_object *obj)
  5994. {
  5995. struct drm_i915_private *dev_priv = dev->dev_private;
  5996. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  5997. uint32_t pf, pipesrc;
  5998. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  5999. int ret;
  6000. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  6001. if (ret)
  6002. goto err;
  6003. ret = intel_ring_begin(ring, 4);
  6004. if (ret)
  6005. goto err_unpin;
  6006. /* i965+ uses the linear or tiled offsets from the
  6007. * Display Registers (which do not change across a page-flip)
  6008. * so we need only reprogram the base address.
  6009. */
  6010. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  6011. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  6012. intel_ring_emit(ring, fb->pitches[0]);
  6013. intel_ring_emit(ring,
  6014. (obj->gtt_offset + intel_crtc->dspaddr_offset) |
  6015. obj->tiling_mode);
  6016. /* XXX Enabling the panel-fitter across page-flip is so far
  6017. * untested on non-native modes, so ignore it for now.
  6018. * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE;
  6019. */
  6020. pf = 0;
  6021. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  6022. intel_ring_emit(ring, pf | pipesrc);
  6023. intel_mark_page_flip_active(intel_crtc);
  6024. intel_ring_advance(ring);
  6025. return 0;
  6026. err_unpin:
  6027. intel_unpin_fb_obj(obj);
  6028. err:
  6029. return ret;
  6030. }
  6031. static int intel_gen6_queue_flip(struct drm_device *dev,
  6032. struct drm_crtc *crtc,
  6033. struct drm_framebuffer *fb,
  6034. struct drm_i915_gem_object *obj)
  6035. {
  6036. struct drm_i915_private *dev_priv = dev->dev_private;
  6037. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6038. struct intel_ring_buffer *ring = &dev_priv->ring[RCS];
  6039. uint32_t pf, pipesrc;
  6040. int ret;
  6041. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  6042. if (ret)
  6043. goto err;
  6044. ret = intel_ring_begin(ring, 4);
  6045. if (ret)
  6046. goto err_unpin;
  6047. intel_ring_emit(ring, MI_DISPLAY_FLIP |
  6048. MI_DISPLAY_FLIP_PLANE(intel_crtc->plane));
  6049. intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode);
  6050. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  6051. /* Contrary to the suggestions in the documentation,
  6052. * "Enable Panel Fitter" does not seem to be required when page
  6053. * flipping with a non-native mode, and worse causes a normal
  6054. * modeset to fail.
  6055. * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE;
  6056. */
  6057. pf = 0;
  6058. pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff;
  6059. intel_ring_emit(ring, pf | pipesrc);
  6060. intel_mark_page_flip_active(intel_crtc);
  6061. intel_ring_advance(ring);
  6062. return 0;
  6063. err_unpin:
  6064. intel_unpin_fb_obj(obj);
  6065. err:
  6066. return ret;
  6067. }
  6068. /*
  6069. * On gen7 we currently use the blit ring because (in early silicon at least)
  6070. * the render ring doesn't give us interrpts for page flip completion, which
  6071. * means clients will hang after the first flip is queued. Fortunately the
  6072. * blit ring generates interrupts properly, so use it instead.
  6073. */
  6074. static int intel_gen7_queue_flip(struct drm_device *dev,
  6075. struct drm_crtc *crtc,
  6076. struct drm_framebuffer *fb,
  6077. struct drm_i915_gem_object *obj)
  6078. {
  6079. struct drm_i915_private *dev_priv = dev->dev_private;
  6080. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6081. struct intel_ring_buffer *ring = &dev_priv->ring[BCS];
  6082. uint32_t plane_bit = 0;
  6083. int ret;
  6084. ret = intel_pin_and_fence_fb_obj(dev, obj, ring);
  6085. if (ret)
  6086. goto err;
  6087. switch(intel_crtc->plane) {
  6088. case PLANE_A:
  6089. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A;
  6090. break;
  6091. case PLANE_B:
  6092. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B;
  6093. break;
  6094. case PLANE_C:
  6095. plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C;
  6096. break;
  6097. default:
  6098. WARN_ONCE(1, "unknown plane in flip command\n");
  6099. ret = -ENODEV;
  6100. goto err_unpin;
  6101. }
  6102. ret = intel_ring_begin(ring, 4);
  6103. if (ret)
  6104. goto err_unpin;
  6105. intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit);
  6106. intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode));
  6107. intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset);
  6108. intel_ring_emit(ring, (MI_NOOP));
  6109. intel_mark_page_flip_active(intel_crtc);
  6110. intel_ring_advance(ring);
  6111. return 0;
  6112. err_unpin:
  6113. intel_unpin_fb_obj(obj);
  6114. err:
  6115. return ret;
  6116. }
  6117. static int intel_default_queue_flip(struct drm_device *dev,
  6118. struct drm_crtc *crtc,
  6119. struct drm_framebuffer *fb,
  6120. struct drm_i915_gem_object *obj)
  6121. {
  6122. return -ENODEV;
  6123. }
  6124. static int intel_crtc_page_flip(struct drm_crtc *crtc,
  6125. struct drm_framebuffer *fb,
  6126. struct drm_pending_vblank_event *event)
  6127. {
  6128. struct drm_device *dev = crtc->dev;
  6129. struct drm_i915_private *dev_priv = dev->dev_private;
  6130. struct intel_framebuffer *intel_fb;
  6131. struct drm_i915_gem_object *obj;
  6132. struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
  6133. struct intel_unpin_work *work;
  6134. unsigned long flags;
  6135. int ret;
  6136. /* Can't change pixel format via MI display flips. */
  6137. if (fb->pixel_format != crtc->fb->pixel_format)
  6138. return -EINVAL;
  6139. /*
  6140. * TILEOFF/LINOFF registers can't be changed via MI display flips.
  6141. * Note that pitch changes could also affect these register.
  6142. */
  6143. if (INTEL_INFO(dev)->gen > 3 &&
  6144. (fb->offsets[0] != crtc->fb->offsets[0] ||
  6145. fb->pitches[0] != crtc->fb->pitches[0]))
  6146. return -EINVAL;
  6147. work = kzalloc(sizeof *work, GFP_KERNEL);
  6148. if (work == NULL)
  6149. return -ENOMEM;
  6150. work->event = event;
  6151. work->crtc = crtc;
  6152. intel_fb = to_intel_framebuffer(crtc->fb);
  6153. work->old_fb_obj = intel_fb->obj;
  6154. INIT_WORK(&work->work, intel_unpin_work_fn);
  6155. ret = drm_vblank_get(dev, intel_crtc->pipe);
  6156. if (ret)
  6157. goto free_work;
  6158. /* We borrow the event spin lock for protecting unpin_work */
  6159. spin_lock_irqsave(&dev->event_lock, flags);
  6160. if (intel_crtc->unpin_work) {
  6161. spin_unlock_irqrestore(&dev->event_lock, flags);
  6162. kfree(work);
  6163. drm_vblank_put(dev, intel_crtc->pipe);
  6164. DRM_DEBUG_DRIVER("flip queue: crtc already busy\n");
  6165. return -EBUSY;
  6166. }
  6167. intel_crtc->unpin_work = work;
  6168. spin_unlock_irqrestore(&dev->event_lock, flags);
  6169. intel_fb = to_intel_framebuffer(fb);
  6170. obj = intel_fb->obj;
  6171. if (atomic_read(&intel_crtc->unpin_work_count) >= 2)
  6172. flush_workqueue(dev_priv->wq);
  6173. ret = i915_mutex_lock_interruptible(dev);
  6174. if (ret)
  6175. goto cleanup;
  6176. /* Reference the objects for the scheduled work. */
  6177. drm_gem_object_reference(&work->old_fb_obj->base);
  6178. drm_gem_object_reference(&obj->base);
  6179. crtc->fb = fb;
  6180. work->pending_flip_obj = obj;
  6181. work->enable_stall_check = true;
  6182. atomic_inc(&intel_crtc->unpin_work_count);
  6183. intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter);
  6184. ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
  6185. if (ret)
  6186. goto cleanup_pending;
  6187. intel_disable_fbc(dev);
  6188. intel_mark_fb_busy(obj);
  6189. mutex_unlock(&dev->struct_mutex);
  6190. trace_i915_flip_request(intel_crtc->plane, obj);
  6191. return 0;
  6192. cleanup_pending:
  6193. atomic_dec(&intel_crtc->unpin_work_count);
  6194. drm_gem_object_unreference(&work->old_fb_obj->base);
  6195. drm_gem_object_unreference(&obj->base);
  6196. mutex_unlock(&dev->struct_mutex);
  6197. cleanup:
  6198. spin_lock_irqsave(&dev->event_lock, flags);
  6199. intel_crtc->unpin_work = NULL;
  6200. spin_unlock_irqrestore(&dev->event_lock, flags);
  6201. drm_vblank_put(dev, intel_crtc->pipe);
  6202. free_work:
  6203. kfree(work);
  6204. return ret;
  6205. }
  6206. static struct drm_crtc_helper_funcs intel_helper_funcs = {
  6207. .mode_set_base_atomic = intel_pipe_set_base_atomic,
  6208. .load_lut = intel_crtc_load_lut,
  6209. };
  6210. bool intel_encoder_check_is_cloned(struct intel_encoder *encoder)
  6211. {
  6212. struct intel_encoder *other_encoder;
  6213. struct drm_crtc *crtc = &encoder->new_crtc->base;
  6214. if (WARN_ON(!crtc))
  6215. return false;
  6216. list_for_each_entry(other_encoder,
  6217. &crtc->dev->mode_config.encoder_list,
  6218. base.head) {
  6219. if (&other_encoder->new_crtc->base != crtc ||
  6220. encoder == other_encoder)
  6221. continue;
  6222. else
  6223. return true;
  6224. }
  6225. return false;
  6226. }
  6227. static bool intel_encoder_crtc_ok(struct drm_encoder *encoder,
  6228. struct drm_crtc *crtc)
  6229. {
  6230. struct drm_device *dev;
  6231. struct drm_crtc *tmp;
  6232. int crtc_mask = 1;
  6233. WARN(!crtc, "checking null crtc?\n");
  6234. dev = crtc->dev;
  6235. list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) {
  6236. if (tmp == crtc)
  6237. break;
  6238. crtc_mask <<= 1;
  6239. }
  6240. if (encoder->possible_crtcs & crtc_mask)
  6241. return true;
  6242. return false;
  6243. }
  6244. /**
  6245. * intel_modeset_update_staged_output_state
  6246. *
  6247. * Updates the staged output configuration state, e.g. after we've read out the
  6248. * current hw state.
  6249. */
  6250. static void intel_modeset_update_staged_output_state(struct drm_device *dev)
  6251. {
  6252. struct intel_encoder *encoder;
  6253. struct intel_connector *connector;
  6254. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6255. base.head) {
  6256. connector->new_encoder =
  6257. to_intel_encoder(connector->base.encoder);
  6258. }
  6259. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6260. base.head) {
  6261. encoder->new_crtc =
  6262. to_intel_crtc(encoder->base.crtc);
  6263. }
  6264. }
  6265. /**
  6266. * intel_modeset_commit_output_state
  6267. *
  6268. * This function copies the stage display pipe configuration to the real one.
  6269. */
  6270. static void intel_modeset_commit_output_state(struct drm_device *dev)
  6271. {
  6272. struct intel_encoder *encoder;
  6273. struct intel_connector *connector;
  6274. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6275. base.head) {
  6276. connector->base.encoder = &connector->new_encoder->base;
  6277. }
  6278. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6279. base.head) {
  6280. encoder->base.crtc = &encoder->new_crtc->base;
  6281. }
  6282. }
  6283. static struct drm_display_mode *
  6284. intel_modeset_adjusted_mode(struct drm_crtc *crtc,
  6285. struct drm_display_mode *mode)
  6286. {
  6287. struct drm_device *dev = crtc->dev;
  6288. struct drm_display_mode *adjusted_mode;
  6289. struct drm_encoder_helper_funcs *encoder_funcs;
  6290. struct intel_encoder *encoder;
  6291. adjusted_mode = drm_mode_duplicate(dev, mode);
  6292. if (!adjusted_mode)
  6293. return ERR_PTR(-ENOMEM);
  6294. /* Pass our mode to the connectors and the CRTC to give them a chance to
  6295. * adjust it according to limitations or connector properties, and also
  6296. * a chance to reject the mode entirely.
  6297. */
  6298. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6299. base.head) {
  6300. if (&encoder->new_crtc->base != crtc)
  6301. continue;
  6302. encoder_funcs = encoder->base.helper_private;
  6303. if (!(encoder_funcs->mode_fixup(&encoder->base, mode,
  6304. adjusted_mode))) {
  6305. DRM_DEBUG_KMS("Encoder fixup failed\n");
  6306. goto fail;
  6307. }
  6308. }
  6309. if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) {
  6310. DRM_DEBUG_KMS("CRTC fixup failed\n");
  6311. goto fail;
  6312. }
  6313. DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id);
  6314. return adjusted_mode;
  6315. fail:
  6316. drm_mode_destroy(dev, adjusted_mode);
  6317. return ERR_PTR(-EINVAL);
  6318. }
  6319. /* Computes which crtcs are affected and sets the relevant bits in the mask. For
  6320. * simplicity we use the crtc's pipe number (because it's easier to obtain). */
  6321. static void
  6322. intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes,
  6323. unsigned *prepare_pipes, unsigned *disable_pipes)
  6324. {
  6325. struct intel_crtc *intel_crtc;
  6326. struct drm_device *dev = crtc->dev;
  6327. struct intel_encoder *encoder;
  6328. struct intel_connector *connector;
  6329. struct drm_crtc *tmp_crtc;
  6330. *disable_pipes = *modeset_pipes = *prepare_pipes = 0;
  6331. /* Check which crtcs have changed outputs connected to them, these need
  6332. * to be part of the prepare_pipes mask. We don't (yet) support global
  6333. * modeset across multiple crtcs, so modeset_pipes will only have one
  6334. * bit set at most. */
  6335. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6336. base.head) {
  6337. if (connector->base.encoder == &connector->new_encoder->base)
  6338. continue;
  6339. if (connector->base.encoder) {
  6340. tmp_crtc = connector->base.encoder->crtc;
  6341. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6342. }
  6343. if (connector->new_encoder)
  6344. *prepare_pipes |=
  6345. 1 << connector->new_encoder->new_crtc->pipe;
  6346. }
  6347. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6348. base.head) {
  6349. if (encoder->base.crtc == &encoder->new_crtc->base)
  6350. continue;
  6351. if (encoder->base.crtc) {
  6352. tmp_crtc = encoder->base.crtc;
  6353. *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe;
  6354. }
  6355. if (encoder->new_crtc)
  6356. *prepare_pipes |= 1 << encoder->new_crtc->pipe;
  6357. }
  6358. /* Check for any pipes that will be fully disabled ... */
  6359. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6360. base.head) {
  6361. bool used = false;
  6362. /* Don't try to disable disabled crtcs. */
  6363. if (!intel_crtc->base.enabled)
  6364. continue;
  6365. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6366. base.head) {
  6367. if (encoder->new_crtc == intel_crtc)
  6368. used = true;
  6369. }
  6370. if (!used)
  6371. *disable_pipes |= 1 << intel_crtc->pipe;
  6372. }
  6373. /* set_mode is also used to update properties on life display pipes. */
  6374. intel_crtc = to_intel_crtc(crtc);
  6375. if (crtc->enabled)
  6376. *prepare_pipes |= 1 << intel_crtc->pipe;
  6377. /* We only support modeset on one single crtc, hence we need to do that
  6378. * only for the passed in crtc iff we change anything else than just
  6379. * disable crtcs.
  6380. *
  6381. * This is actually not true, to be fully compatible with the old crtc
  6382. * helper we automatically disable _any_ output (i.e. doesn't need to be
  6383. * connected to the crtc we're modesetting on) if it's disconnected.
  6384. * Which is a rather nutty api (since changed the output configuration
  6385. * without userspace's explicit request can lead to confusion), but
  6386. * alas. Hence we currently need to modeset on all pipes we prepare. */
  6387. if (*prepare_pipes)
  6388. *modeset_pipes = *prepare_pipes;
  6389. /* ... and mask these out. */
  6390. *modeset_pipes &= ~(*disable_pipes);
  6391. *prepare_pipes &= ~(*disable_pipes);
  6392. }
  6393. static bool intel_crtc_in_use(struct drm_crtc *crtc)
  6394. {
  6395. struct drm_encoder *encoder;
  6396. struct drm_device *dev = crtc->dev;
  6397. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
  6398. if (encoder->crtc == crtc)
  6399. return true;
  6400. return false;
  6401. }
  6402. static void
  6403. intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes)
  6404. {
  6405. struct intel_encoder *intel_encoder;
  6406. struct intel_crtc *intel_crtc;
  6407. struct drm_connector *connector;
  6408. list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list,
  6409. base.head) {
  6410. if (!intel_encoder->base.crtc)
  6411. continue;
  6412. intel_crtc = to_intel_crtc(intel_encoder->base.crtc);
  6413. if (prepare_pipes & (1 << intel_crtc->pipe))
  6414. intel_encoder->connectors_active = false;
  6415. }
  6416. intel_modeset_commit_output_state(dev);
  6417. /* Update computed state. */
  6418. list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list,
  6419. base.head) {
  6420. intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base);
  6421. }
  6422. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6423. if (!connector->encoder || !connector->encoder->crtc)
  6424. continue;
  6425. intel_crtc = to_intel_crtc(connector->encoder->crtc);
  6426. if (prepare_pipes & (1 << intel_crtc->pipe)) {
  6427. struct drm_property *dpms_property =
  6428. dev->mode_config.dpms_property;
  6429. connector->dpms = DRM_MODE_DPMS_ON;
  6430. drm_object_property_set_value(&connector->base,
  6431. dpms_property,
  6432. DRM_MODE_DPMS_ON);
  6433. intel_encoder = to_intel_encoder(connector->encoder);
  6434. intel_encoder->connectors_active = true;
  6435. }
  6436. }
  6437. }
  6438. #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \
  6439. list_for_each_entry((intel_crtc), \
  6440. &(dev)->mode_config.crtc_list, \
  6441. base.head) \
  6442. if (mask & (1 <<(intel_crtc)->pipe)) \
  6443. void
  6444. intel_modeset_check_state(struct drm_device *dev)
  6445. {
  6446. struct intel_crtc *crtc;
  6447. struct intel_encoder *encoder;
  6448. struct intel_connector *connector;
  6449. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6450. base.head) {
  6451. /* This also checks the encoder/connector hw state with the
  6452. * ->get_hw_state callbacks. */
  6453. intel_connector_check_state(connector);
  6454. WARN(&connector->new_encoder->base != connector->base.encoder,
  6455. "connector's staged encoder doesn't match current encoder\n");
  6456. }
  6457. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6458. base.head) {
  6459. bool enabled = false;
  6460. bool active = false;
  6461. enum pipe pipe, tracked_pipe;
  6462. DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
  6463. encoder->base.base.id,
  6464. drm_get_encoder_name(&encoder->base));
  6465. WARN(&encoder->new_crtc->base != encoder->base.crtc,
  6466. "encoder's stage crtc doesn't match current crtc\n");
  6467. WARN(encoder->connectors_active && !encoder->base.crtc,
  6468. "encoder's active_connectors set, but no crtc\n");
  6469. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6470. base.head) {
  6471. if (connector->base.encoder != &encoder->base)
  6472. continue;
  6473. enabled = true;
  6474. if (connector->base.dpms != DRM_MODE_DPMS_OFF)
  6475. active = true;
  6476. }
  6477. WARN(!!encoder->base.crtc != enabled,
  6478. "encoder's enabled state mismatch "
  6479. "(expected %i, found %i)\n",
  6480. !!encoder->base.crtc, enabled);
  6481. WARN(active && !encoder->base.crtc,
  6482. "active encoder with no crtc\n");
  6483. WARN(encoder->connectors_active != active,
  6484. "encoder's computed active state doesn't match tracked active state "
  6485. "(expected %i, found %i)\n", active, encoder->connectors_active);
  6486. active = encoder->get_hw_state(encoder, &pipe);
  6487. WARN(active != encoder->connectors_active,
  6488. "encoder's hw state doesn't match sw tracking "
  6489. "(expected %i, found %i)\n",
  6490. encoder->connectors_active, active);
  6491. if (!encoder->base.crtc)
  6492. continue;
  6493. tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe;
  6494. WARN(active && pipe != tracked_pipe,
  6495. "active encoder's pipe doesn't match"
  6496. "(expected %i, found %i)\n",
  6497. tracked_pipe, pipe);
  6498. }
  6499. list_for_each_entry(crtc, &dev->mode_config.crtc_list,
  6500. base.head) {
  6501. bool enabled = false;
  6502. bool active = false;
  6503. DRM_DEBUG_KMS("[CRTC:%d]\n",
  6504. crtc->base.base.id);
  6505. WARN(crtc->active && !crtc->base.enabled,
  6506. "active crtc, but not enabled in sw tracking\n");
  6507. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6508. base.head) {
  6509. if (encoder->base.crtc != &crtc->base)
  6510. continue;
  6511. enabled = true;
  6512. if (encoder->connectors_active)
  6513. active = true;
  6514. }
  6515. WARN(active != crtc->active,
  6516. "crtc's computed active state doesn't match tracked active state "
  6517. "(expected %i, found %i)\n", active, crtc->active);
  6518. WARN(enabled != crtc->base.enabled,
  6519. "crtc's computed enabled state doesn't match tracked enabled state "
  6520. "(expected %i, found %i)\n", enabled, crtc->base.enabled);
  6521. assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
  6522. }
  6523. }
  6524. int intel_set_mode(struct drm_crtc *crtc,
  6525. struct drm_display_mode *mode,
  6526. int x, int y, struct drm_framebuffer *fb)
  6527. {
  6528. struct drm_device *dev = crtc->dev;
  6529. drm_i915_private_t *dev_priv = dev->dev_private;
  6530. struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode;
  6531. struct intel_crtc *intel_crtc;
  6532. unsigned disable_pipes, prepare_pipes, modeset_pipes;
  6533. int ret = 0;
  6534. saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL);
  6535. if (!saved_mode)
  6536. return -ENOMEM;
  6537. saved_hwmode = saved_mode + 1;
  6538. intel_modeset_affected_pipes(crtc, &modeset_pipes,
  6539. &prepare_pipes, &disable_pipes);
  6540. DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n",
  6541. modeset_pipes, prepare_pipes, disable_pipes);
  6542. for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc)
  6543. intel_crtc_disable(&intel_crtc->base);
  6544. *saved_hwmode = crtc->hwmode;
  6545. *saved_mode = crtc->mode;
  6546. /* Hack: Because we don't (yet) support global modeset on multiple
  6547. * crtcs, we don't keep track of the new mode for more than one crtc.
  6548. * Hence simply check whether any bit is set in modeset_pipes in all the
  6549. * pieces of code that are not yet converted to deal with mutliple crtcs
  6550. * changing their mode at the same time. */
  6551. adjusted_mode = NULL;
  6552. if (modeset_pipes) {
  6553. adjusted_mode = intel_modeset_adjusted_mode(crtc, mode);
  6554. if (IS_ERR(adjusted_mode)) {
  6555. ret = PTR_ERR(adjusted_mode);
  6556. goto out;
  6557. }
  6558. }
  6559. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) {
  6560. if (intel_crtc->base.enabled)
  6561. dev_priv->display.crtc_disable(&intel_crtc->base);
  6562. }
  6563. /* crtc->mode is already used by the ->mode_set callbacks, hence we need
  6564. * to set it here already despite that we pass it down the callchain.
  6565. */
  6566. if (modeset_pipes)
  6567. crtc->mode = *mode;
  6568. /* Only after disabling all output pipelines that will be changed can we
  6569. * update the the output configuration. */
  6570. intel_modeset_update_state(dev, prepare_pipes);
  6571. if (dev_priv->display.modeset_global_resources)
  6572. dev_priv->display.modeset_global_resources(dev);
  6573. /* Set up the DPLL and any encoders state that needs to adjust or depend
  6574. * on the DPLL.
  6575. */
  6576. for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) {
  6577. ret = intel_crtc_mode_set(&intel_crtc->base,
  6578. mode, adjusted_mode,
  6579. x, y, fb);
  6580. if (ret)
  6581. goto done;
  6582. }
  6583. /* Now enable the clocks, plane, pipe, and connectors that we set up. */
  6584. for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc)
  6585. dev_priv->display.crtc_enable(&intel_crtc->base);
  6586. if (modeset_pipes) {
  6587. /* Store real post-adjustment hardware mode. */
  6588. crtc->hwmode = *adjusted_mode;
  6589. /* Calculate and store various constants which
  6590. * are later needed by vblank and swap-completion
  6591. * timestamping. They are derived from true hwmode.
  6592. */
  6593. drm_calc_timestamping_constants(crtc);
  6594. }
  6595. /* FIXME: add subpixel order */
  6596. done:
  6597. drm_mode_destroy(dev, adjusted_mode);
  6598. if (ret && crtc->enabled) {
  6599. crtc->hwmode = *saved_hwmode;
  6600. crtc->mode = *saved_mode;
  6601. } else {
  6602. intel_modeset_check_state(dev);
  6603. }
  6604. out:
  6605. kfree(saved_mode);
  6606. return ret;
  6607. }
  6608. void intel_crtc_restore_mode(struct drm_crtc *crtc)
  6609. {
  6610. intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb);
  6611. }
  6612. #undef for_each_intel_crtc_masked
  6613. static void intel_set_config_free(struct intel_set_config *config)
  6614. {
  6615. if (!config)
  6616. return;
  6617. kfree(config->save_connector_encoders);
  6618. kfree(config->save_encoder_crtcs);
  6619. kfree(config);
  6620. }
  6621. static int intel_set_config_save_state(struct drm_device *dev,
  6622. struct intel_set_config *config)
  6623. {
  6624. struct drm_encoder *encoder;
  6625. struct drm_connector *connector;
  6626. int count;
  6627. config->save_encoder_crtcs =
  6628. kcalloc(dev->mode_config.num_encoder,
  6629. sizeof(struct drm_crtc *), GFP_KERNEL);
  6630. if (!config->save_encoder_crtcs)
  6631. return -ENOMEM;
  6632. config->save_connector_encoders =
  6633. kcalloc(dev->mode_config.num_connector,
  6634. sizeof(struct drm_encoder *), GFP_KERNEL);
  6635. if (!config->save_connector_encoders)
  6636. return -ENOMEM;
  6637. /* Copy data. Note that driver private data is not affected.
  6638. * Should anything bad happen only the expected state is
  6639. * restored, not the drivers personal bookkeeping.
  6640. */
  6641. count = 0;
  6642. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  6643. config->save_encoder_crtcs[count++] = encoder->crtc;
  6644. }
  6645. count = 0;
  6646. list_for_each_entry(connector, &dev->mode_config.connector_list, head) {
  6647. config->save_connector_encoders[count++] = connector->encoder;
  6648. }
  6649. return 0;
  6650. }
  6651. static void intel_set_config_restore_state(struct drm_device *dev,
  6652. struct intel_set_config *config)
  6653. {
  6654. struct intel_encoder *encoder;
  6655. struct intel_connector *connector;
  6656. int count;
  6657. count = 0;
  6658. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  6659. encoder->new_crtc =
  6660. to_intel_crtc(config->save_encoder_crtcs[count++]);
  6661. }
  6662. count = 0;
  6663. list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) {
  6664. connector->new_encoder =
  6665. to_intel_encoder(config->save_connector_encoders[count++]);
  6666. }
  6667. }
  6668. static void
  6669. intel_set_config_compute_mode_changes(struct drm_mode_set *set,
  6670. struct intel_set_config *config)
  6671. {
  6672. /* We should be able to check here if the fb has the same properties
  6673. * and then just flip_or_move it */
  6674. if (set->crtc->fb != set->fb) {
  6675. /* If we have no fb then treat it as a full mode set */
  6676. if (set->crtc->fb == NULL) {
  6677. DRM_DEBUG_KMS("crtc has no fb, full mode set\n");
  6678. config->mode_changed = true;
  6679. } else if (set->fb == NULL) {
  6680. config->mode_changed = true;
  6681. } else if (set->fb->depth != set->crtc->fb->depth) {
  6682. config->mode_changed = true;
  6683. } else if (set->fb->bits_per_pixel !=
  6684. set->crtc->fb->bits_per_pixel) {
  6685. config->mode_changed = true;
  6686. } else
  6687. config->fb_changed = true;
  6688. }
  6689. if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y))
  6690. config->fb_changed = true;
  6691. if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) {
  6692. DRM_DEBUG_KMS("modes are different, full mode set\n");
  6693. drm_mode_debug_printmodeline(&set->crtc->mode);
  6694. drm_mode_debug_printmodeline(set->mode);
  6695. config->mode_changed = true;
  6696. }
  6697. }
  6698. static int
  6699. intel_modeset_stage_output_state(struct drm_device *dev,
  6700. struct drm_mode_set *set,
  6701. struct intel_set_config *config)
  6702. {
  6703. struct drm_crtc *new_crtc;
  6704. struct intel_connector *connector;
  6705. struct intel_encoder *encoder;
  6706. int count, ro;
  6707. /* The upper layers ensure that we either disable a crtc or have a list
  6708. * of connectors. For paranoia, double-check this. */
  6709. WARN_ON(!set->fb && (set->num_connectors != 0));
  6710. WARN_ON(set->fb && (set->num_connectors == 0));
  6711. count = 0;
  6712. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6713. base.head) {
  6714. /* Otherwise traverse passed in connector list and get encoders
  6715. * for them. */
  6716. for (ro = 0; ro < set->num_connectors; ro++) {
  6717. if (set->connectors[ro] == &connector->base) {
  6718. connector->new_encoder = connector->encoder;
  6719. break;
  6720. }
  6721. }
  6722. /* If we disable the crtc, disable all its connectors. Also, if
  6723. * the connector is on the changing crtc but not on the new
  6724. * connector list, disable it. */
  6725. if ((!set->fb || ro == set->num_connectors) &&
  6726. connector->base.encoder &&
  6727. connector->base.encoder->crtc == set->crtc) {
  6728. connector->new_encoder = NULL;
  6729. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n",
  6730. connector->base.base.id,
  6731. drm_get_connector_name(&connector->base));
  6732. }
  6733. if (&connector->new_encoder->base != connector->base.encoder) {
  6734. DRM_DEBUG_KMS("encoder changed, full mode switch\n");
  6735. config->mode_changed = true;
  6736. }
  6737. }
  6738. /* connector->new_encoder is now updated for all connectors. */
  6739. /* Update crtc of enabled connectors. */
  6740. count = 0;
  6741. list_for_each_entry(connector, &dev->mode_config.connector_list,
  6742. base.head) {
  6743. if (!connector->new_encoder)
  6744. continue;
  6745. new_crtc = connector->new_encoder->base.crtc;
  6746. for (ro = 0; ro < set->num_connectors; ro++) {
  6747. if (set->connectors[ro] == &connector->base)
  6748. new_crtc = set->crtc;
  6749. }
  6750. /* Make sure the new CRTC will work with the encoder */
  6751. if (!intel_encoder_crtc_ok(&connector->new_encoder->base,
  6752. new_crtc)) {
  6753. return -EINVAL;
  6754. }
  6755. connector->encoder->new_crtc = to_intel_crtc(new_crtc);
  6756. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n",
  6757. connector->base.base.id,
  6758. drm_get_connector_name(&connector->base),
  6759. new_crtc->base.id);
  6760. }
  6761. /* Check for any encoders that needs to be disabled. */
  6762. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  6763. base.head) {
  6764. list_for_each_entry(connector,
  6765. &dev->mode_config.connector_list,
  6766. base.head) {
  6767. if (connector->new_encoder == encoder) {
  6768. WARN_ON(!connector->new_encoder->new_crtc);
  6769. goto next_encoder;
  6770. }
  6771. }
  6772. encoder->new_crtc = NULL;
  6773. next_encoder:
  6774. /* Only now check for crtc changes so we don't miss encoders
  6775. * that will be disabled. */
  6776. if (&encoder->new_crtc->base != encoder->base.crtc) {
  6777. DRM_DEBUG_KMS("crtc changed, full mode switch\n");
  6778. config->mode_changed = true;
  6779. }
  6780. }
  6781. /* Now we've also updated encoder->new_crtc for all encoders. */
  6782. return 0;
  6783. }
  6784. static int intel_crtc_set_config(struct drm_mode_set *set)
  6785. {
  6786. struct drm_device *dev;
  6787. struct drm_mode_set save_set;
  6788. struct intel_set_config *config;
  6789. int ret;
  6790. BUG_ON(!set);
  6791. BUG_ON(!set->crtc);
  6792. BUG_ON(!set->crtc->helper_private);
  6793. /* Enforce sane interface api - has been abused by the fb helper. */
  6794. BUG_ON(!set->mode && set->fb);
  6795. BUG_ON(set->fb && set->num_connectors == 0);
  6796. if (set->fb) {
  6797. DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n",
  6798. set->crtc->base.id, set->fb->base.id,
  6799. (int)set->num_connectors, set->x, set->y);
  6800. } else {
  6801. DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id);
  6802. }
  6803. dev = set->crtc->dev;
  6804. ret = -ENOMEM;
  6805. config = kzalloc(sizeof(*config), GFP_KERNEL);
  6806. if (!config)
  6807. goto out_config;
  6808. ret = intel_set_config_save_state(dev, config);
  6809. if (ret)
  6810. goto out_config;
  6811. save_set.crtc = set->crtc;
  6812. save_set.mode = &set->crtc->mode;
  6813. save_set.x = set->crtc->x;
  6814. save_set.y = set->crtc->y;
  6815. save_set.fb = set->crtc->fb;
  6816. /* Compute whether we need a full modeset, only an fb base update or no
  6817. * change at all. In the future we might also check whether only the
  6818. * mode changed, e.g. for LVDS where we only change the panel fitter in
  6819. * such cases. */
  6820. intel_set_config_compute_mode_changes(set, config);
  6821. ret = intel_modeset_stage_output_state(dev, set, config);
  6822. if (ret)
  6823. goto fail;
  6824. if (config->mode_changed) {
  6825. if (set->mode) {
  6826. DRM_DEBUG_KMS("attempting to set mode from"
  6827. " userspace\n");
  6828. drm_mode_debug_printmodeline(set->mode);
  6829. }
  6830. ret = intel_set_mode(set->crtc, set->mode,
  6831. set->x, set->y, set->fb);
  6832. if (ret) {
  6833. DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n",
  6834. set->crtc->base.id, ret);
  6835. goto fail;
  6836. }
  6837. } else if (config->fb_changed) {
  6838. ret = intel_pipe_set_base(set->crtc,
  6839. set->x, set->y, set->fb);
  6840. }
  6841. intel_set_config_free(config);
  6842. return 0;
  6843. fail:
  6844. intel_set_config_restore_state(dev, config);
  6845. /* Try to restore the config */
  6846. if (config->mode_changed &&
  6847. intel_set_mode(save_set.crtc, save_set.mode,
  6848. save_set.x, save_set.y, save_set.fb))
  6849. DRM_ERROR("failed to restore config after modeset failure\n");
  6850. out_config:
  6851. intel_set_config_free(config);
  6852. return ret;
  6853. }
  6854. static const struct drm_crtc_funcs intel_crtc_funcs = {
  6855. .cursor_set = intel_crtc_cursor_set,
  6856. .cursor_move = intel_crtc_cursor_move,
  6857. .gamma_set = intel_crtc_gamma_set,
  6858. .set_config = intel_crtc_set_config,
  6859. .destroy = intel_crtc_destroy,
  6860. .page_flip = intel_crtc_page_flip,
  6861. };
  6862. static void intel_cpu_pll_init(struct drm_device *dev)
  6863. {
  6864. if (HAS_DDI(dev))
  6865. intel_ddi_pll_init(dev);
  6866. }
  6867. static void intel_pch_pll_init(struct drm_device *dev)
  6868. {
  6869. drm_i915_private_t *dev_priv = dev->dev_private;
  6870. int i;
  6871. if (dev_priv->num_pch_pll == 0) {
  6872. DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n");
  6873. return;
  6874. }
  6875. for (i = 0; i < dev_priv->num_pch_pll; i++) {
  6876. dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i);
  6877. dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i);
  6878. dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i);
  6879. }
  6880. }
  6881. static void intel_crtc_init(struct drm_device *dev, int pipe)
  6882. {
  6883. drm_i915_private_t *dev_priv = dev->dev_private;
  6884. struct intel_crtc *intel_crtc;
  6885. int i;
  6886. intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL);
  6887. if (intel_crtc == NULL)
  6888. return;
  6889. drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs);
  6890. drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
  6891. for (i = 0; i < 256; i++) {
  6892. intel_crtc->lut_r[i] = i;
  6893. intel_crtc->lut_g[i] = i;
  6894. intel_crtc->lut_b[i] = i;
  6895. }
  6896. /* Swap pipes & planes for FBC on pre-965 */
  6897. intel_crtc->pipe = pipe;
  6898. intel_crtc->plane = pipe;
  6899. intel_crtc->cpu_transcoder = pipe;
  6900. if (IS_MOBILE(dev) && IS_GEN3(dev)) {
  6901. DRM_DEBUG_KMS("swapping pipes & planes for FBC\n");
  6902. intel_crtc->plane = !pipe;
  6903. }
  6904. BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) ||
  6905. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL);
  6906. dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base;
  6907. dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base;
  6908. intel_crtc->bpp = 24; /* default for pre-Ironlake */
  6909. drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs);
  6910. }
  6911. int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data,
  6912. struct drm_file *file)
  6913. {
  6914. struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data;
  6915. struct drm_mode_object *drmmode_obj;
  6916. struct intel_crtc *crtc;
  6917. if (!drm_core_check_feature(dev, DRIVER_MODESET))
  6918. return -ENODEV;
  6919. drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id,
  6920. DRM_MODE_OBJECT_CRTC);
  6921. if (!drmmode_obj) {
  6922. DRM_ERROR("no such CRTC id\n");
  6923. return -EINVAL;
  6924. }
  6925. crtc = to_intel_crtc(obj_to_crtc(drmmode_obj));
  6926. pipe_from_crtc_id->pipe = crtc->pipe;
  6927. return 0;
  6928. }
  6929. static int intel_encoder_clones(struct intel_encoder *encoder)
  6930. {
  6931. struct drm_device *dev = encoder->base.dev;
  6932. struct intel_encoder *source_encoder;
  6933. int index_mask = 0;
  6934. int entry = 0;
  6935. list_for_each_entry(source_encoder,
  6936. &dev->mode_config.encoder_list, base.head) {
  6937. if (encoder == source_encoder)
  6938. index_mask |= (1 << entry);
  6939. /* Intel hw has only one MUX where enocoders could be cloned. */
  6940. if (encoder->cloneable && source_encoder->cloneable)
  6941. index_mask |= (1 << entry);
  6942. entry++;
  6943. }
  6944. return index_mask;
  6945. }
  6946. static bool has_edp_a(struct drm_device *dev)
  6947. {
  6948. struct drm_i915_private *dev_priv = dev->dev_private;
  6949. if (!IS_MOBILE(dev))
  6950. return false;
  6951. if ((I915_READ(DP_A) & DP_DETECTED) == 0)
  6952. return false;
  6953. if (IS_GEN5(dev) &&
  6954. (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE))
  6955. return false;
  6956. return true;
  6957. }
  6958. static void intel_setup_outputs(struct drm_device *dev)
  6959. {
  6960. struct drm_i915_private *dev_priv = dev->dev_private;
  6961. struct intel_encoder *encoder;
  6962. bool dpd_is_edp = false;
  6963. bool has_lvds;
  6964. has_lvds = intel_lvds_init(dev);
  6965. if (!has_lvds && !HAS_PCH_SPLIT(dev)) {
  6966. /* disable the panel fitter on everything but LVDS */
  6967. I915_WRITE(PFIT_CONTROL, 0);
  6968. }
  6969. if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES)))
  6970. intel_crt_init(dev);
  6971. if (HAS_DDI(dev)) {
  6972. int found;
  6973. /* Haswell uses DDI functions to detect digital outputs */
  6974. found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED;
  6975. /* DDI A only supports eDP */
  6976. if (found)
  6977. intel_ddi_init(dev, PORT_A);
  6978. /* DDI B, C and D detection is indicated by the SFUSE_STRAP
  6979. * register */
  6980. found = I915_READ(SFUSE_STRAP);
  6981. if (found & SFUSE_STRAP_DDIB_DETECTED)
  6982. intel_ddi_init(dev, PORT_B);
  6983. if (found & SFUSE_STRAP_DDIC_DETECTED)
  6984. intel_ddi_init(dev, PORT_C);
  6985. if (found & SFUSE_STRAP_DDID_DETECTED)
  6986. intel_ddi_init(dev, PORT_D);
  6987. } else if (HAS_PCH_SPLIT(dev)) {
  6988. int found;
  6989. dpd_is_edp = intel_dpd_is_edp(dev);
  6990. if (has_edp_a(dev))
  6991. intel_dp_init(dev, DP_A, PORT_A);
  6992. if (I915_READ(HDMIB) & PORT_DETECTED) {
  6993. /* PCH SDVOB multiplex with HDMIB */
  6994. found = intel_sdvo_init(dev, PCH_SDVOB, true);
  6995. if (!found)
  6996. intel_hdmi_init(dev, HDMIB, PORT_B);
  6997. if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED))
  6998. intel_dp_init(dev, PCH_DP_B, PORT_B);
  6999. }
  7000. if (I915_READ(HDMIC) & PORT_DETECTED)
  7001. intel_hdmi_init(dev, HDMIC, PORT_C);
  7002. if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED)
  7003. intel_hdmi_init(dev, HDMID, PORT_D);
  7004. if (I915_READ(PCH_DP_C) & DP_DETECTED)
  7005. intel_dp_init(dev, PCH_DP_C, PORT_C);
  7006. if (I915_READ(PCH_DP_D) & DP_DETECTED)
  7007. intel_dp_init(dev, PCH_DP_D, PORT_D);
  7008. } else if (IS_VALLEYVIEW(dev)) {
  7009. /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */
  7010. if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED)
  7011. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C);
  7012. if (I915_READ(VLV_DISPLAY_BASE + SDVOB) & PORT_DETECTED) {
  7013. intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOB, PORT_B);
  7014. if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED)
  7015. intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B);
  7016. }
  7017. if (I915_READ(VLV_DISPLAY_BASE + SDVOC) & PORT_DETECTED)
  7018. intel_hdmi_init(dev, VLV_DISPLAY_BASE + SDVOC, PORT_C);
  7019. } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) {
  7020. bool found = false;
  7021. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  7022. DRM_DEBUG_KMS("probing SDVOB\n");
  7023. found = intel_sdvo_init(dev, SDVOB, true);
  7024. if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) {
  7025. DRM_DEBUG_KMS("probing HDMI on SDVOB\n");
  7026. intel_hdmi_init(dev, SDVOB, PORT_B);
  7027. }
  7028. if (!found && SUPPORTS_INTEGRATED_DP(dev)) {
  7029. DRM_DEBUG_KMS("probing DP_B\n");
  7030. intel_dp_init(dev, DP_B, PORT_B);
  7031. }
  7032. }
  7033. /* Before G4X SDVOC doesn't have its own detect register */
  7034. if (I915_READ(SDVOB) & SDVO_DETECTED) {
  7035. DRM_DEBUG_KMS("probing SDVOC\n");
  7036. found = intel_sdvo_init(dev, SDVOC, false);
  7037. }
  7038. if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) {
  7039. if (SUPPORTS_INTEGRATED_HDMI(dev)) {
  7040. DRM_DEBUG_KMS("probing HDMI on SDVOC\n");
  7041. intel_hdmi_init(dev, SDVOC, PORT_C);
  7042. }
  7043. if (SUPPORTS_INTEGRATED_DP(dev)) {
  7044. DRM_DEBUG_KMS("probing DP_C\n");
  7045. intel_dp_init(dev, DP_C, PORT_C);
  7046. }
  7047. }
  7048. if (SUPPORTS_INTEGRATED_DP(dev) &&
  7049. (I915_READ(DP_D) & DP_DETECTED)) {
  7050. DRM_DEBUG_KMS("probing DP_D\n");
  7051. intel_dp_init(dev, DP_D, PORT_D);
  7052. }
  7053. } else if (IS_GEN2(dev))
  7054. intel_dvo_init(dev);
  7055. if (SUPPORTS_TV(dev))
  7056. intel_tv_init(dev);
  7057. list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) {
  7058. encoder->base.possible_crtcs = encoder->crtc_mask;
  7059. encoder->base.possible_clones =
  7060. intel_encoder_clones(encoder);
  7061. }
  7062. intel_init_pch_refclk(dev);
  7063. drm_helper_move_panel_connectors_to_head(dev);
  7064. }
  7065. static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb)
  7066. {
  7067. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  7068. drm_framebuffer_cleanup(fb);
  7069. drm_gem_object_unreference_unlocked(&intel_fb->obj->base);
  7070. kfree(intel_fb);
  7071. }
  7072. static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb,
  7073. struct drm_file *file,
  7074. unsigned int *handle)
  7075. {
  7076. struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
  7077. struct drm_i915_gem_object *obj = intel_fb->obj;
  7078. return drm_gem_handle_create(file, &obj->base, handle);
  7079. }
  7080. static const struct drm_framebuffer_funcs intel_fb_funcs = {
  7081. .destroy = intel_user_framebuffer_destroy,
  7082. .create_handle = intel_user_framebuffer_create_handle,
  7083. };
  7084. int intel_framebuffer_init(struct drm_device *dev,
  7085. struct intel_framebuffer *intel_fb,
  7086. struct drm_mode_fb_cmd2 *mode_cmd,
  7087. struct drm_i915_gem_object *obj)
  7088. {
  7089. int ret;
  7090. if (obj->tiling_mode == I915_TILING_Y) {
  7091. DRM_DEBUG("hardware does not support tiling Y\n");
  7092. return -EINVAL;
  7093. }
  7094. if (mode_cmd->pitches[0] & 63) {
  7095. DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n",
  7096. mode_cmd->pitches[0]);
  7097. return -EINVAL;
  7098. }
  7099. /* FIXME <= Gen4 stride limits are bit unclear */
  7100. if (mode_cmd->pitches[0] > 32768) {
  7101. DRM_DEBUG("pitch (%d) must be at less than 32768\n",
  7102. mode_cmd->pitches[0]);
  7103. return -EINVAL;
  7104. }
  7105. if (obj->tiling_mode != I915_TILING_NONE &&
  7106. mode_cmd->pitches[0] != obj->stride) {
  7107. DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n",
  7108. mode_cmd->pitches[0], obj->stride);
  7109. return -EINVAL;
  7110. }
  7111. /* Reject formats not supported by any plane early. */
  7112. switch (mode_cmd->pixel_format) {
  7113. case DRM_FORMAT_C8:
  7114. case DRM_FORMAT_RGB565:
  7115. case DRM_FORMAT_XRGB8888:
  7116. case DRM_FORMAT_ARGB8888:
  7117. break;
  7118. case DRM_FORMAT_XRGB1555:
  7119. case DRM_FORMAT_ARGB1555:
  7120. if (INTEL_INFO(dev)->gen > 3) {
  7121. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7122. return -EINVAL;
  7123. }
  7124. break;
  7125. case DRM_FORMAT_XBGR8888:
  7126. case DRM_FORMAT_ABGR8888:
  7127. case DRM_FORMAT_XRGB2101010:
  7128. case DRM_FORMAT_ARGB2101010:
  7129. case DRM_FORMAT_XBGR2101010:
  7130. case DRM_FORMAT_ABGR2101010:
  7131. if (INTEL_INFO(dev)->gen < 4) {
  7132. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7133. return -EINVAL;
  7134. }
  7135. break;
  7136. case DRM_FORMAT_YUYV:
  7137. case DRM_FORMAT_UYVY:
  7138. case DRM_FORMAT_YVYU:
  7139. case DRM_FORMAT_VYUY:
  7140. if (INTEL_INFO(dev)->gen < 5) {
  7141. DRM_DEBUG("invalid format: 0x%08x\n", mode_cmd->pixel_format);
  7142. return -EINVAL;
  7143. }
  7144. break;
  7145. default:
  7146. DRM_DEBUG("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format);
  7147. return -EINVAL;
  7148. }
  7149. /* FIXME need to adjust LINOFF/TILEOFF accordingly. */
  7150. if (mode_cmd->offsets[0] != 0)
  7151. return -EINVAL;
  7152. drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd);
  7153. intel_fb->obj = obj;
  7154. ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs);
  7155. if (ret) {
  7156. DRM_ERROR("framebuffer init failed %d\n", ret);
  7157. return ret;
  7158. }
  7159. return 0;
  7160. }
  7161. static struct drm_framebuffer *
  7162. intel_user_framebuffer_create(struct drm_device *dev,
  7163. struct drm_file *filp,
  7164. struct drm_mode_fb_cmd2 *mode_cmd)
  7165. {
  7166. struct drm_i915_gem_object *obj;
  7167. obj = to_intel_bo(drm_gem_object_lookup(dev, filp,
  7168. mode_cmd->handles[0]));
  7169. if (&obj->base == NULL)
  7170. return ERR_PTR(-ENOENT);
  7171. return intel_framebuffer_create(dev, mode_cmd, obj);
  7172. }
  7173. static const struct drm_mode_config_funcs intel_mode_funcs = {
  7174. .fb_create = intel_user_framebuffer_create,
  7175. .output_poll_changed = intel_fb_output_poll_changed,
  7176. };
  7177. /* Set up chip specific display functions */
  7178. static void intel_init_display(struct drm_device *dev)
  7179. {
  7180. struct drm_i915_private *dev_priv = dev->dev_private;
  7181. /* We always want a DPMS function */
  7182. if (HAS_DDI(dev)) {
  7183. dev_priv->display.crtc_mode_set = haswell_crtc_mode_set;
  7184. dev_priv->display.crtc_enable = haswell_crtc_enable;
  7185. dev_priv->display.crtc_disable = haswell_crtc_disable;
  7186. dev_priv->display.off = haswell_crtc_off;
  7187. dev_priv->display.update_plane = ironlake_update_plane;
  7188. } else if (HAS_PCH_SPLIT(dev)) {
  7189. dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set;
  7190. dev_priv->display.crtc_enable = ironlake_crtc_enable;
  7191. dev_priv->display.crtc_disable = ironlake_crtc_disable;
  7192. dev_priv->display.off = ironlake_crtc_off;
  7193. dev_priv->display.update_plane = ironlake_update_plane;
  7194. } else {
  7195. dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set;
  7196. dev_priv->display.crtc_enable = i9xx_crtc_enable;
  7197. dev_priv->display.crtc_disable = i9xx_crtc_disable;
  7198. dev_priv->display.off = i9xx_crtc_off;
  7199. dev_priv->display.update_plane = i9xx_update_plane;
  7200. }
  7201. /* Returns the core display clock speed */
  7202. if (IS_VALLEYVIEW(dev))
  7203. dev_priv->display.get_display_clock_speed =
  7204. valleyview_get_display_clock_speed;
  7205. else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev)))
  7206. dev_priv->display.get_display_clock_speed =
  7207. i945_get_display_clock_speed;
  7208. else if (IS_I915G(dev))
  7209. dev_priv->display.get_display_clock_speed =
  7210. i915_get_display_clock_speed;
  7211. else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev))
  7212. dev_priv->display.get_display_clock_speed =
  7213. i9xx_misc_get_display_clock_speed;
  7214. else if (IS_I915GM(dev))
  7215. dev_priv->display.get_display_clock_speed =
  7216. i915gm_get_display_clock_speed;
  7217. else if (IS_I865G(dev))
  7218. dev_priv->display.get_display_clock_speed =
  7219. i865_get_display_clock_speed;
  7220. else if (IS_I85X(dev))
  7221. dev_priv->display.get_display_clock_speed =
  7222. i855_get_display_clock_speed;
  7223. else /* 852, 830 */
  7224. dev_priv->display.get_display_clock_speed =
  7225. i830_get_display_clock_speed;
  7226. if (HAS_PCH_SPLIT(dev)) {
  7227. if (IS_GEN5(dev)) {
  7228. dev_priv->display.fdi_link_train = ironlake_fdi_link_train;
  7229. dev_priv->display.write_eld = ironlake_write_eld;
  7230. } else if (IS_GEN6(dev)) {
  7231. dev_priv->display.fdi_link_train = gen6_fdi_link_train;
  7232. dev_priv->display.write_eld = ironlake_write_eld;
  7233. } else if (IS_IVYBRIDGE(dev)) {
  7234. /* FIXME: detect B0+ stepping and use auto training */
  7235. dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train;
  7236. dev_priv->display.write_eld = ironlake_write_eld;
  7237. dev_priv->display.modeset_global_resources =
  7238. ivb_modeset_global_resources;
  7239. } else if (IS_HASWELL(dev)) {
  7240. dev_priv->display.fdi_link_train = hsw_fdi_link_train;
  7241. dev_priv->display.write_eld = haswell_write_eld;
  7242. dev_priv->display.modeset_global_resources =
  7243. haswell_modeset_global_resources;
  7244. }
  7245. } else if (IS_G4X(dev)) {
  7246. dev_priv->display.write_eld = g4x_write_eld;
  7247. }
  7248. /* Default just returns -ENODEV to indicate unsupported */
  7249. dev_priv->display.queue_flip = intel_default_queue_flip;
  7250. switch (INTEL_INFO(dev)->gen) {
  7251. case 2:
  7252. dev_priv->display.queue_flip = intel_gen2_queue_flip;
  7253. break;
  7254. case 3:
  7255. dev_priv->display.queue_flip = intel_gen3_queue_flip;
  7256. break;
  7257. case 4:
  7258. case 5:
  7259. dev_priv->display.queue_flip = intel_gen4_queue_flip;
  7260. break;
  7261. case 6:
  7262. dev_priv->display.queue_flip = intel_gen6_queue_flip;
  7263. break;
  7264. case 7:
  7265. dev_priv->display.queue_flip = intel_gen7_queue_flip;
  7266. break;
  7267. }
  7268. }
  7269. /*
  7270. * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend,
  7271. * resume, or other times. This quirk makes sure that's the case for
  7272. * affected systems.
  7273. */
  7274. static void quirk_pipea_force(struct drm_device *dev)
  7275. {
  7276. struct drm_i915_private *dev_priv = dev->dev_private;
  7277. dev_priv->quirks |= QUIRK_PIPEA_FORCE;
  7278. DRM_INFO("applying pipe a force quirk\n");
  7279. }
  7280. /*
  7281. * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason
  7282. */
  7283. static void quirk_ssc_force_disable(struct drm_device *dev)
  7284. {
  7285. struct drm_i915_private *dev_priv = dev->dev_private;
  7286. dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE;
  7287. DRM_INFO("applying lvds SSC disable quirk\n");
  7288. }
  7289. /*
  7290. * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight
  7291. * brightness value
  7292. */
  7293. static void quirk_invert_brightness(struct drm_device *dev)
  7294. {
  7295. struct drm_i915_private *dev_priv = dev->dev_private;
  7296. dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS;
  7297. DRM_INFO("applying inverted panel brightness quirk\n");
  7298. }
  7299. struct intel_quirk {
  7300. int device;
  7301. int subsystem_vendor;
  7302. int subsystem_device;
  7303. void (*hook)(struct drm_device *dev);
  7304. };
  7305. /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
  7306. struct intel_dmi_quirk {
  7307. void (*hook)(struct drm_device *dev);
  7308. const struct dmi_system_id (*dmi_id_list)[];
  7309. };
  7310. static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
  7311. {
  7312. DRM_INFO("Backlight polarity reversed on %s\n", id->ident);
  7313. return 1;
  7314. }
  7315. static const struct intel_dmi_quirk intel_dmi_quirks[] = {
  7316. {
  7317. .dmi_id_list = &(const struct dmi_system_id[]) {
  7318. {
  7319. .callback = intel_dmi_reverse_brightness,
  7320. .ident = "NCR Corporation",
  7321. .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
  7322. DMI_MATCH(DMI_PRODUCT_NAME, ""),
  7323. },
  7324. },
  7325. { } /* terminating entry */
  7326. },
  7327. .hook = quirk_invert_brightness,
  7328. },
  7329. };
  7330. static struct intel_quirk intel_quirks[] = {
  7331. /* HP Mini needs pipe A force quirk (LP: #322104) */
  7332. { 0x27ae, 0x103c, 0x361a, quirk_pipea_force },
  7333. /* Toshiba Protege R-205, S-209 needs pipe A force quirk */
  7334. { 0x2592, 0x1179, 0x0001, quirk_pipea_force },
  7335. /* ThinkPad T60 needs pipe A force quirk (bug #16494) */
  7336. { 0x2782, 0x17aa, 0x201a, quirk_pipea_force },
  7337. /* 830/845 need to leave pipe A & dpll A up */
  7338. { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7339. { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force },
  7340. /* Lenovo U160 cannot use SSC on LVDS */
  7341. { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable },
  7342. /* Sony Vaio Y cannot use SSC on LVDS */
  7343. { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable },
  7344. /* Acer Aspire 5734Z must invert backlight brightness */
  7345. { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness },
  7346. /* Acer/eMachines G725 */
  7347. { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness },
  7348. /* Acer/eMachines e725 */
  7349. { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness },
  7350. /* Acer/Packard Bell NCL20 */
  7351. { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness },
  7352. /* Acer Aspire 4736Z */
  7353. { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness },
  7354. };
  7355. static void intel_init_quirks(struct drm_device *dev)
  7356. {
  7357. struct pci_dev *d = dev->pdev;
  7358. int i;
  7359. for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) {
  7360. struct intel_quirk *q = &intel_quirks[i];
  7361. if (d->device == q->device &&
  7362. (d->subsystem_vendor == q->subsystem_vendor ||
  7363. q->subsystem_vendor == PCI_ANY_ID) &&
  7364. (d->subsystem_device == q->subsystem_device ||
  7365. q->subsystem_device == PCI_ANY_ID))
  7366. q->hook(dev);
  7367. }
  7368. for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) {
  7369. if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0)
  7370. intel_dmi_quirks[i].hook(dev);
  7371. }
  7372. }
  7373. /* Disable the VGA plane that we never use */
  7374. static void i915_disable_vga(struct drm_device *dev)
  7375. {
  7376. struct drm_i915_private *dev_priv = dev->dev_private;
  7377. u8 sr1;
  7378. u32 vga_reg = i915_vgacntrl_reg(dev);
  7379. vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO);
  7380. outb(SR01, VGA_SR_INDEX);
  7381. sr1 = inb(VGA_SR_DATA);
  7382. outb(sr1 | 1<<5, VGA_SR_DATA);
  7383. vga_put(dev->pdev, VGA_RSRC_LEGACY_IO);
  7384. udelay(300);
  7385. I915_WRITE(vga_reg, VGA_DISP_DISABLE);
  7386. POSTING_READ(vga_reg);
  7387. }
  7388. void intel_modeset_init_hw(struct drm_device *dev)
  7389. {
  7390. intel_init_power_well(dev);
  7391. intel_prepare_ddi(dev);
  7392. intel_init_clock_gating(dev);
  7393. mutex_lock(&dev->struct_mutex);
  7394. intel_enable_gt_powersave(dev);
  7395. mutex_unlock(&dev->struct_mutex);
  7396. }
  7397. void intel_modeset_init(struct drm_device *dev)
  7398. {
  7399. struct drm_i915_private *dev_priv = dev->dev_private;
  7400. int i, ret;
  7401. drm_mode_config_init(dev);
  7402. dev->mode_config.min_width = 0;
  7403. dev->mode_config.min_height = 0;
  7404. dev->mode_config.preferred_depth = 24;
  7405. dev->mode_config.prefer_shadow = 1;
  7406. dev->mode_config.funcs = &intel_mode_funcs;
  7407. intel_init_quirks(dev);
  7408. intel_init_pm(dev);
  7409. intel_init_display(dev);
  7410. if (IS_GEN2(dev)) {
  7411. dev->mode_config.max_width = 2048;
  7412. dev->mode_config.max_height = 2048;
  7413. } else if (IS_GEN3(dev)) {
  7414. dev->mode_config.max_width = 4096;
  7415. dev->mode_config.max_height = 4096;
  7416. } else {
  7417. dev->mode_config.max_width = 8192;
  7418. dev->mode_config.max_height = 8192;
  7419. }
  7420. dev->mode_config.fb_base = dev_priv->gtt.mappable_base;
  7421. DRM_DEBUG_KMS("%d display pipe%s available.\n",
  7422. dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : "");
  7423. for (i = 0; i < dev_priv->num_pipe; i++) {
  7424. intel_crtc_init(dev, i);
  7425. ret = intel_plane_init(dev, i);
  7426. if (ret)
  7427. DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret);
  7428. }
  7429. intel_cpu_pll_init(dev);
  7430. intel_pch_pll_init(dev);
  7431. /* Just disable it once at startup */
  7432. i915_disable_vga(dev);
  7433. intel_setup_outputs(dev);
  7434. /* Just in case the BIOS is doing something questionable. */
  7435. intel_disable_fbc(dev);
  7436. }
  7437. static void
  7438. intel_connector_break_all_links(struct intel_connector *connector)
  7439. {
  7440. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7441. connector->base.encoder = NULL;
  7442. connector->encoder->connectors_active = false;
  7443. connector->encoder->base.crtc = NULL;
  7444. }
  7445. static void intel_enable_pipe_a(struct drm_device *dev)
  7446. {
  7447. struct intel_connector *connector;
  7448. struct drm_connector *crt = NULL;
  7449. struct intel_load_detect_pipe load_detect_temp;
  7450. /* We can't just switch on the pipe A, we need to set things up with a
  7451. * proper mode and output configuration. As a gross hack, enable pipe A
  7452. * by enabling the load detect pipe once. */
  7453. list_for_each_entry(connector,
  7454. &dev->mode_config.connector_list,
  7455. base.head) {
  7456. if (connector->encoder->type == INTEL_OUTPUT_ANALOG) {
  7457. crt = &connector->base;
  7458. break;
  7459. }
  7460. }
  7461. if (!crt)
  7462. return;
  7463. if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp))
  7464. intel_release_load_detect_pipe(crt, &load_detect_temp);
  7465. }
  7466. static bool
  7467. intel_check_plane_mapping(struct intel_crtc *crtc)
  7468. {
  7469. struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
  7470. u32 reg, val;
  7471. if (dev_priv->num_pipe == 1)
  7472. return true;
  7473. reg = DSPCNTR(!crtc->plane);
  7474. val = I915_READ(reg);
  7475. if ((val & DISPLAY_PLANE_ENABLE) &&
  7476. (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe))
  7477. return false;
  7478. return true;
  7479. }
  7480. static void intel_sanitize_crtc(struct intel_crtc *crtc)
  7481. {
  7482. struct drm_device *dev = crtc->base.dev;
  7483. struct drm_i915_private *dev_priv = dev->dev_private;
  7484. u32 reg;
  7485. /* Clear any frame start delays used for debugging left by the BIOS */
  7486. reg = PIPECONF(crtc->cpu_transcoder);
  7487. I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK);
  7488. /* We need to sanitize the plane -> pipe mapping first because this will
  7489. * disable the crtc (and hence change the state) if it is wrong. Note
  7490. * that gen4+ has a fixed plane -> pipe mapping. */
  7491. if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) {
  7492. struct intel_connector *connector;
  7493. bool plane;
  7494. DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n",
  7495. crtc->base.base.id);
  7496. /* Pipe has the wrong plane attached and the plane is active.
  7497. * Temporarily change the plane mapping and disable everything
  7498. * ... */
  7499. plane = crtc->plane;
  7500. crtc->plane = !plane;
  7501. dev_priv->display.crtc_disable(&crtc->base);
  7502. crtc->plane = plane;
  7503. /* ... and break all links. */
  7504. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7505. base.head) {
  7506. if (connector->encoder->base.crtc != &crtc->base)
  7507. continue;
  7508. intel_connector_break_all_links(connector);
  7509. }
  7510. WARN_ON(crtc->active);
  7511. crtc->base.enabled = false;
  7512. }
  7513. if (dev_priv->quirks & QUIRK_PIPEA_FORCE &&
  7514. crtc->pipe == PIPE_A && !crtc->active) {
  7515. /* BIOS forgot to enable pipe A, this mostly happens after
  7516. * resume. Force-enable the pipe to fix this, the update_dpms
  7517. * call below we restore the pipe to the right state, but leave
  7518. * the required bits on. */
  7519. intel_enable_pipe_a(dev);
  7520. }
  7521. /* Adjust the state of the output pipe according to whether we
  7522. * have active connectors/encoders. */
  7523. intel_crtc_update_dpms(&crtc->base);
  7524. if (crtc->active != crtc->base.enabled) {
  7525. struct intel_encoder *encoder;
  7526. /* This can happen either due to bugs in the get_hw_state
  7527. * functions or because the pipe is force-enabled due to the
  7528. * pipe A quirk. */
  7529. DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n",
  7530. crtc->base.base.id,
  7531. crtc->base.enabled ? "enabled" : "disabled",
  7532. crtc->active ? "enabled" : "disabled");
  7533. crtc->base.enabled = crtc->active;
  7534. /* Because we only establish the connector -> encoder ->
  7535. * crtc links if something is active, this means the
  7536. * crtc is now deactivated. Break the links. connector
  7537. * -> encoder links are only establish when things are
  7538. * actually up, hence no need to break them. */
  7539. WARN_ON(crtc->active);
  7540. for_each_encoder_on_crtc(dev, &crtc->base, encoder) {
  7541. WARN_ON(encoder->connectors_active);
  7542. encoder->base.crtc = NULL;
  7543. }
  7544. }
  7545. }
  7546. static void intel_sanitize_encoder(struct intel_encoder *encoder)
  7547. {
  7548. struct intel_connector *connector;
  7549. struct drm_device *dev = encoder->base.dev;
  7550. /* We need to check both for a crtc link (meaning that the
  7551. * encoder is active and trying to read from a pipe) and the
  7552. * pipe itself being active. */
  7553. bool has_active_crtc = encoder->base.crtc &&
  7554. to_intel_crtc(encoder->base.crtc)->active;
  7555. if (encoder->connectors_active && !has_active_crtc) {
  7556. DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n",
  7557. encoder->base.base.id,
  7558. drm_get_encoder_name(&encoder->base));
  7559. /* Connector is active, but has no active pipe. This is
  7560. * fallout from our resume register restoring. Disable
  7561. * the encoder manually again. */
  7562. if (encoder->base.crtc) {
  7563. DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n",
  7564. encoder->base.base.id,
  7565. drm_get_encoder_name(&encoder->base));
  7566. encoder->disable(encoder);
  7567. }
  7568. /* Inconsistent output/port/pipe state happens presumably due to
  7569. * a bug in one of the get_hw_state functions. Or someplace else
  7570. * in our code, like the register restore mess on resume. Clamp
  7571. * things to off as a safer default. */
  7572. list_for_each_entry(connector,
  7573. &dev->mode_config.connector_list,
  7574. base.head) {
  7575. if (connector->encoder != encoder)
  7576. continue;
  7577. intel_connector_break_all_links(connector);
  7578. }
  7579. }
  7580. /* Enabled encoders without active connectors will be fixed in
  7581. * the crtc fixup. */
  7582. }
  7583. void i915_redisable_vga(struct drm_device *dev)
  7584. {
  7585. struct drm_i915_private *dev_priv = dev->dev_private;
  7586. u32 vga_reg = i915_vgacntrl_reg(dev);
  7587. if (I915_READ(vga_reg) != VGA_DISP_DISABLE) {
  7588. DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n");
  7589. i915_disable_vga(dev);
  7590. }
  7591. }
  7592. /* Scan out the current hw modeset state, sanitizes it and maps it into the drm
  7593. * and i915 state tracking structures. */
  7594. void intel_modeset_setup_hw_state(struct drm_device *dev,
  7595. bool force_restore)
  7596. {
  7597. struct drm_i915_private *dev_priv = dev->dev_private;
  7598. enum pipe pipe;
  7599. u32 tmp;
  7600. struct intel_crtc *crtc;
  7601. struct intel_encoder *encoder;
  7602. struct intel_connector *connector;
  7603. if (HAS_DDI(dev)) {
  7604. tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP));
  7605. if (tmp & TRANS_DDI_FUNC_ENABLE) {
  7606. switch (tmp & TRANS_DDI_EDP_INPUT_MASK) {
  7607. case TRANS_DDI_EDP_INPUT_A_ON:
  7608. case TRANS_DDI_EDP_INPUT_A_ONOFF:
  7609. pipe = PIPE_A;
  7610. break;
  7611. case TRANS_DDI_EDP_INPUT_B_ONOFF:
  7612. pipe = PIPE_B;
  7613. break;
  7614. case TRANS_DDI_EDP_INPUT_C_ONOFF:
  7615. pipe = PIPE_C;
  7616. break;
  7617. }
  7618. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7619. crtc->cpu_transcoder = TRANSCODER_EDP;
  7620. DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n",
  7621. pipe_name(pipe));
  7622. }
  7623. }
  7624. for_each_pipe(pipe) {
  7625. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7626. tmp = I915_READ(PIPECONF(crtc->cpu_transcoder));
  7627. if (tmp & PIPECONF_ENABLE)
  7628. crtc->active = true;
  7629. else
  7630. crtc->active = false;
  7631. crtc->base.enabled = crtc->active;
  7632. DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n",
  7633. crtc->base.base.id,
  7634. crtc->active ? "enabled" : "disabled");
  7635. }
  7636. if (HAS_DDI(dev))
  7637. intel_ddi_setup_hw_pll_state(dev);
  7638. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7639. base.head) {
  7640. pipe = 0;
  7641. if (encoder->get_hw_state(encoder, &pipe)) {
  7642. encoder->base.crtc =
  7643. dev_priv->pipe_to_crtc_mapping[pipe];
  7644. } else {
  7645. encoder->base.crtc = NULL;
  7646. }
  7647. encoder->connectors_active = false;
  7648. DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n",
  7649. encoder->base.base.id,
  7650. drm_get_encoder_name(&encoder->base),
  7651. encoder->base.crtc ? "enabled" : "disabled",
  7652. pipe);
  7653. }
  7654. list_for_each_entry(connector, &dev->mode_config.connector_list,
  7655. base.head) {
  7656. if (connector->get_hw_state(connector)) {
  7657. connector->base.dpms = DRM_MODE_DPMS_ON;
  7658. connector->encoder->connectors_active = true;
  7659. connector->base.encoder = &connector->encoder->base;
  7660. } else {
  7661. connector->base.dpms = DRM_MODE_DPMS_OFF;
  7662. connector->base.encoder = NULL;
  7663. }
  7664. DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n",
  7665. connector->base.base.id,
  7666. drm_get_connector_name(&connector->base),
  7667. connector->base.encoder ? "enabled" : "disabled");
  7668. }
  7669. /* HW state is read out, now we need to sanitize this mess. */
  7670. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  7671. base.head) {
  7672. intel_sanitize_encoder(encoder);
  7673. }
  7674. for_each_pipe(pipe) {
  7675. crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
  7676. intel_sanitize_crtc(crtc);
  7677. }
  7678. if (force_restore) {
  7679. for_each_pipe(pipe) {
  7680. intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]);
  7681. }
  7682. i915_redisable_vga(dev);
  7683. } else {
  7684. intel_modeset_update_staged_output_state(dev);
  7685. }
  7686. intel_modeset_check_state(dev);
  7687. drm_mode_config_reset(dev);
  7688. }
  7689. void intel_modeset_gem_init(struct drm_device *dev)
  7690. {
  7691. intel_modeset_init_hw(dev);
  7692. intel_setup_overlay(dev);
  7693. intel_modeset_setup_hw_state(dev, false);
  7694. }
  7695. void intel_modeset_cleanup(struct drm_device *dev)
  7696. {
  7697. struct drm_i915_private *dev_priv = dev->dev_private;
  7698. struct drm_crtc *crtc;
  7699. struct intel_crtc *intel_crtc;
  7700. drm_kms_helper_poll_fini(dev);
  7701. mutex_lock(&dev->struct_mutex);
  7702. intel_unregister_dsm_handler();
  7703. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  7704. /* Skip inactive CRTCs */
  7705. if (!crtc->fb)
  7706. continue;
  7707. intel_crtc = to_intel_crtc(crtc);
  7708. intel_increase_pllclock(crtc);
  7709. }
  7710. intel_disable_fbc(dev);
  7711. intel_disable_gt_powersave(dev);
  7712. ironlake_teardown_rc6(dev);
  7713. if (IS_VALLEYVIEW(dev))
  7714. vlv_init_dpio(dev);
  7715. mutex_unlock(&dev->struct_mutex);
  7716. /* Disable the irq before mode object teardown, for the irq might
  7717. * enqueue unpin/hotplug work. */
  7718. drm_irq_uninstall(dev);
  7719. cancel_work_sync(&dev_priv->hotplug_work);
  7720. cancel_work_sync(&dev_priv->rps.work);
  7721. /* flush any delayed tasks or pending work */
  7722. flush_scheduled_work();
  7723. drm_mode_config_cleanup(dev);
  7724. intel_cleanup_overlay(dev);
  7725. }
  7726. /*
  7727. * Return which encoder is currently attached for connector.
  7728. */
  7729. struct drm_encoder *intel_best_encoder(struct drm_connector *connector)
  7730. {
  7731. return &intel_attached_encoder(connector)->base;
  7732. }
  7733. void intel_connector_attach_encoder(struct intel_connector *connector,
  7734. struct intel_encoder *encoder)
  7735. {
  7736. connector->encoder = encoder;
  7737. drm_mode_connector_attach_encoder(&connector->base,
  7738. &encoder->base);
  7739. }
  7740. /*
  7741. * set vga decode state - true == enable VGA decode
  7742. */
  7743. int intel_modeset_vga_set_state(struct drm_device *dev, bool state)
  7744. {
  7745. struct drm_i915_private *dev_priv = dev->dev_private;
  7746. u16 gmch_ctrl;
  7747. pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl);
  7748. if (state)
  7749. gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE;
  7750. else
  7751. gmch_ctrl |= INTEL_GMCH_VGA_DISABLE;
  7752. pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl);
  7753. return 0;
  7754. }
  7755. #ifdef CONFIG_DEBUG_FS
  7756. #include <linux/seq_file.h>
  7757. struct intel_display_error_state {
  7758. struct intel_cursor_error_state {
  7759. u32 control;
  7760. u32 position;
  7761. u32 base;
  7762. u32 size;
  7763. } cursor[I915_MAX_PIPES];
  7764. struct intel_pipe_error_state {
  7765. u32 conf;
  7766. u32 source;
  7767. u32 htotal;
  7768. u32 hblank;
  7769. u32 hsync;
  7770. u32 vtotal;
  7771. u32 vblank;
  7772. u32 vsync;
  7773. } pipe[I915_MAX_PIPES];
  7774. struct intel_plane_error_state {
  7775. u32 control;
  7776. u32 stride;
  7777. u32 size;
  7778. u32 pos;
  7779. u32 addr;
  7780. u32 surface;
  7781. u32 tile_offset;
  7782. } plane[I915_MAX_PIPES];
  7783. };
  7784. struct intel_display_error_state *
  7785. intel_display_capture_error_state(struct drm_device *dev)
  7786. {
  7787. drm_i915_private_t *dev_priv = dev->dev_private;
  7788. struct intel_display_error_state *error;
  7789. enum transcoder cpu_transcoder;
  7790. int i;
  7791. error = kmalloc(sizeof(*error), GFP_ATOMIC);
  7792. if (error == NULL)
  7793. return NULL;
  7794. for_each_pipe(i) {
  7795. cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i);
  7796. error->cursor[i].control = I915_READ(CURCNTR(i));
  7797. error->cursor[i].position = I915_READ(CURPOS(i));
  7798. error->cursor[i].base = I915_READ(CURBASE(i));
  7799. error->plane[i].control = I915_READ(DSPCNTR(i));
  7800. error->plane[i].stride = I915_READ(DSPSTRIDE(i));
  7801. error->plane[i].size = I915_READ(DSPSIZE(i));
  7802. error->plane[i].pos = I915_READ(DSPPOS(i));
  7803. error->plane[i].addr = I915_READ(DSPADDR(i));
  7804. if (INTEL_INFO(dev)->gen >= 4) {
  7805. error->plane[i].surface = I915_READ(DSPSURF(i));
  7806. error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i));
  7807. }
  7808. error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder));
  7809. error->pipe[i].source = I915_READ(PIPESRC(i));
  7810. error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder));
  7811. error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder));
  7812. error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder));
  7813. error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder));
  7814. error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder));
  7815. error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder));
  7816. }
  7817. return error;
  7818. }
  7819. void
  7820. intel_display_print_error_state(struct seq_file *m,
  7821. struct drm_device *dev,
  7822. struct intel_display_error_state *error)
  7823. {
  7824. drm_i915_private_t *dev_priv = dev->dev_private;
  7825. int i;
  7826. seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe);
  7827. for_each_pipe(i) {
  7828. seq_printf(m, "Pipe [%d]:\n", i);
  7829. seq_printf(m, " CONF: %08x\n", error->pipe[i].conf);
  7830. seq_printf(m, " SRC: %08x\n", error->pipe[i].source);
  7831. seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal);
  7832. seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank);
  7833. seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync);
  7834. seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal);
  7835. seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank);
  7836. seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync);
  7837. seq_printf(m, "Plane [%d]:\n", i);
  7838. seq_printf(m, " CNTR: %08x\n", error->plane[i].control);
  7839. seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride);
  7840. seq_printf(m, " SIZE: %08x\n", error->plane[i].size);
  7841. seq_printf(m, " POS: %08x\n", error->plane[i].pos);
  7842. seq_printf(m, " ADDR: %08x\n", error->plane[i].addr);
  7843. if (INTEL_INFO(dev)->gen >= 4) {
  7844. seq_printf(m, " SURF: %08x\n", error->plane[i].surface);
  7845. seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset);
  7846. }
  7847. seq_printf(m, "Cursor [%d]:\n", i);
  7848. seq_printf(m, " CNTR: %08x\n", error->cursor[i].control);
  7849. seq_printf(m, " POS: %08x\n", error->cursor[i].position);
  7850. seq_printf(m, " BASE: %08x\n", error->cursor[i].base);
  7851. }
  7852. }
  7853. #endif