intel_display.c 262 KB

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