intel_display.c 248 KB

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