patch_realtek.c 198 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for Realtek ALC codecs
  5. *
  6. * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
  7. * PeiSen Hou <pshou@realtek.com.tw>
  8. * Takashi Iwai <tiwai@suse.de>
  9. * Jonathan Woithe <jwoithe@just42.net>
  10. *
  11. * This driver is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This driver is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <linux/slab.h>
  28. #include <linux/pci.h>
  29. #include <linux/module.h>
  30. #include <sound/core.h>
  31. #include <sound/jack.h>
  32. #include "hda_codec.h"
  33. #include "hda_local.h"
  34. #include "hda_auto_parser.h"
  35. #include "hda_beep.h"
  36. #include "hda_jack.h"
  37. /* unsol event tags */
  38. #define ALC_FRONT_EVENT 0x01
  39. #define ALC_DCVOL_EVENT 0x02
  40. #define ALC_HP_EVENT 0x04
  41. #define ALC_MIC_EVENT 0x08
  42. /* for GPIO Poll */
  43. #define GPIO_MASK 0x03
  44. /* extra amp-initialization sequence types */
  45. enum {
  46. ALC_INIT_NONE,
  47. ALC_INIT_DEFAULT,
  48. ALC_INIT_GPIO1,
  49. ALC_INIT_GPIO2,
  50. ALC_INIT_GPIO3,
  51. };
  52. struct alc_customize_define {
  53. unsigned int sku_cfg;
  54. unsigned char port_connectivity;
  55. unsigned char check_sum;
  56. unsigned char customization;
  57. unsigned char external_amp;
  58. unsigned int enable_pcbeep:1;
  59. unsigned int platform_type:1;
  60. unsigned int swap:1;
  61. unsigned int override:1;
  62. unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
  63. };
  64. struct alc_multi_io {
  65. hda_nid_t pin; /* multi-io widget pin NID */
  66. hda_nid_t dac; /* DAC to be connected */
  67. unsigned int ctl_in; /* cached input-pin control value */
  68. };
  69. enum {
  70. ALC_AUTOMUTE_PIN, /* change the pin control */
  71. ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
  72. ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
  73. };
  74. #define MAX_VOL_NIDS 0x40
  75. /* make compatible with old code */
  76. #define alc_apply_pincfgs snd_hda_apply_pincfgs
  77. #define alc_apply_fixup snd_hda_apply_fixup
  78. #define alc_pick_fixup snd_hda_pick_fixup
  79. #define alc_fixup hda_fixup
  80. #define alc_pincfg hda_pintbl
  81. #define alc_model_fixup hda_model_fixup
  82. #define ALC_FIXUP_PINS HDA_FIXUP_PINS
  83. #define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
  84. #define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
  85. #define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
  86. #define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
  87. #define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
  88. #define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
  89. struct alc_spec {
  90. struct hda_gen_spec gen;
  91. /* codec parameterization */
  92. const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
  93. unsigned int num_mixers;
  94. const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
  95. unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
  96. char stream_name_analog[32]; /* analog PCM stream */
  97. const struct hda_pcm_stream *stream_analog_playback;
  98. const struct hda_pcm_stream *stream_analog_capture;
  99. const struct hda_pcm_stream *stream_analog_alt_playback;
  100. const struct hda_pcm_stream *stream_analog_alt_capture;
  101. char stream_name_digital[32]; /* digital PCM stream */
  102. const struct hda_pcm_stream *stream_digital_playback;
  103. const struct hda_pcm_stream *stream_digital_capture;
  104. /* playback */
  105. struct hda_multi_out multiout; /* playback set-up
  106. * max_channels, dacs must be set
  107. * dig_out_nid and hp_nid are optional
  108. */
  109. hda_nid_t alt_dac_nid;
  110. hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
  111. int dig_out_type;
  112. /* capture */
  113. unsigned int num_adc_nids;
  114. const hda_nid_t *adc_nids;
  115. const hda_nid_t *capsrc_nids;
  116. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  117. hda_nid_t mixer_nid; /* analog-mixer NID */
  118. DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
  119. DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
  120. /* capture setup for dynamic dual-adc switch */
  121. hda_nid_t cur_adc;
  122. unsigned int cur_adc_stream_tag;
  123. unsigned int cur_adc_format;
  124. /* capture source */
  125. unsigned int num_mux_defs;
  126. const struct hda_input_mux *input_mux;
  127. unsigned int cur_mux[3];
  128. hda_nid_t ext_mic_pin;
  129. hda_nid_t dock_mic_pin;
  130. hda_nid_t int_mic_pin;
  131. /* channel model */
  132. const struct hda_channel_mode *channel_mode;
  133. int num_channel_mode;
  134. int need_dac_fix;
  135. int const_channel_count; /* min. channel count (for speakers) */
  136. int ext_channel_count; /* current channel count for multi-io */
  137. /* PCM information */
  138. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  139. /* dynamic controls, init_verbs and input_mux */
  140. struct auto_pin_cfg autocfg;
  141. struct alc_customize_define cdefine;
  142. struct snd_array kctls;
  143. struct hda_input_mux private_imux[3];
  144. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  145. hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
  146. hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
  147. hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
  148. unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
  149. int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
  150. hda_nid_t inv_dmic_pin;
  151. /* hooks */
  152. void (*init_hook)(struct hda_codec *codec);
  153. #ifdef CONFIG_PM
  154. void (*power_hook)(struct hda_codec *codec);
  155. #endif
  156. void (*shutup)(struct hda_codec *codec);
  157. void (*automute_hook)(struct hda_codec *codec);
  158. /* for pin sensing */
  159. unsigned int hp_jack_present:1;
  160. unsigned int line_jack_present:1;
  161. unsigned int master_mute:1;
  162. unsigned int auto_mic:1;
  163. unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
  164. unsigned int automute_speaker:1; /* automute speaker outputs */
  165. unsigned int automute_lo:1; /* automute LO outputs */
  166. unsigned int detect_hp:1; /* Headphone detection enabled */
  167. unsigned int detect_lo:1; /* Line-out detection enabled */
  168. unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
  169. unsigned int automute_lo_possible:1; /* there are line outs and HP */
  170. unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
  171. /* other flags */
  172. unsigned int no_analog :1; /* digital I/O only */
  173. unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
  174. unsigned int single_input_src:1;
  175. unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
  176. unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
  177. unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
  178. unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
  179. unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
  180. unsigned int no_primary_hp:1; /* Don't prefer HP pins to speaker pins */
  181. /* auto-mute control */
  182. int automute_mode;
  183. hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
  184. int init_amp;
  185. int codec_variant; /* flag for other variants */
  186. /* for virtual master */
  187. hda_nid_t vmaster_nid;
  188. struct hda_vmaster_mute_hook vmaster_mute;
  189. #ifdef CONFIG_PM
  190. struct hda_loopback_check loopback;
  191. int num_loopbacks;
  192. struct hda_amp_list loopback_list[8];
  193. #endif
  194. /* for PLL fix */
  195. hda_nid_t pll_nid;
  196. unsigned int pll_coef_idx, pll_coef_bit;
  197. unsigned int coef0;
  198. /* multi-io */
  199. int multi_ios;
  200. struct alc_multi_io multi_io[4];
  201. /* bind volumes */
  202. struct snd_array bind_ctls;
  203. };
  204. static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
  205. int dir, unsigned int bits)
  206. {
  207. if (!nid)
  208. return false;
  209. if (get_wcaps(codec, nid) & (1 << (dir + 1)))
  210. if (query_amp_caps(codec, nid, dir) & bits)
  211. return true;
  212. return false;
  213. }
  214. #define nid_has_mute(codec, nid, dir) \
  215. check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
  216. #define nid_has_volume(codec, nid, dir) \
  217. check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
  218. /*
  219. * input MUX handling
  220. */
  221. static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
  222. struct snd_ctl_elem_info *uinfo)
  223. {
  224. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  225. struct alc_spec *spec = codec->spec;
  226. unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
  227. if (mux_idx >= spec->num_mux_defs)
  228. mux_idx = 0;
  229. if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
  230. mux_idx = 0;
  231. return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
  232. }
  233. static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
  234. struct snd_ctl_elem_value *ucontrol)
  235. {
  236. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  237. struct alc_spec *spec = codec->spec;
  238. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  239. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  240. return 0;
  241. }
  242. static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
  243. {
  244. struct alc_spec *spec = codec->spec;
  245. hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
  246. if (spec->cur_adc && spec->cur_adc != new_adc) {
  247. /* stream is running, let's swap the current ADC */
  248. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  249. spec->cur_adc = new_adc;
  250. snd_hda_codec_setup_stream(codec, new_adc,
  251. spec->cur_adc_stream_tag, 0,
  252. spec->cur_adc_format);
  253. return true;
  254. }
  255. return false;
  256. }
  257. static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
  258. {
  259. return spec->capsrc_nids ?
  260. spec->capsrc_nids[idx] : spec->adc_nids[idx];
  261. }
  262. static void call_update_outputs(struct hda_codec *codec);
  263. static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
  264. /* for shared I/O, change the pin-control accordingly */
  265. static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
  266. {
  267. struct alc_spec *spec = codec->spec;
  268. unsigned int val;
  269. hda_nid_t pin = spec->autocfg.inputs[1].pin;
  270. /* NOTE: this assumes that there are only two inputs, the
  271. * first is the real internal mic and the second is HP/mic jack.
  272. */
  273. val = snd_hda_get_default_vref(codec, pin);
  274. /* This pin does not have vref caps - let's enable vref on pin 0x18
  275. instead, as suggested by Realtek */
  276. if (val == AC_PINCTL_VREF_HIZ) {
  277. const hda_nid_t vref_pin = 0x18;
  278. /* Sanity check pin 0x18 */
  279. if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
  280. get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
  281. unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
  282. if (vref_val != AC_PINCTL_VREF_HIZ)
  283. snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
  284. }
  285. }
  286. val = set_as_mic ? val | PIN_IN : PIN_HP;
  287. snd_hda_set_pin_ctl(codec, pin, val);
  288. spec->automute_speaker = !set_as_mic;
  289. call_update_outputs(codec);
  290. }
  291. /* select the given imux item; either unmute exclusively or select the route */
  292. static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
  293. unsigned int idx, bool force)
  294. {
  295. struct alc_spec *spec = codec->spec;
  296. const struct hda_input_mux *imux;
  297. unsigned int mux_idx;
  298. int i, type, num_conns;
  299. hda_nid_t nid;
  300. if (!spec->input_mux)
  301. return 0;
  302. mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
  303. imux = &spec->input_mux[mux_idx];
  304. if (!imux->num_items && mux_idx > 0)
  305. imux = &spec->input_mux[0];
  306. if (!imux->num_items)
  307. return 0;
  308. if (idx >= imux->num_items)
  309. idx = imux->num_items - 1;
  310. if (spec->cur_mux[adc_idx] == idx && !force)
  311. return 0;
  312. spec->cur_mux[adc_idx] = idx;
  313. if (spec->shared_mic_hp)
  314. update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
  315. if (spec->dyn_adc_switch) {
  316. alc_dyn_adc_pcm_resetup(codec, idx);
  317. adc_idx = spec->dyn_adc_idx[idx];
  318. }
  319. nid = get_capsrc(spec, adc_idx);
  320. /* no selection? */
  321. num_conns = snd_hda_get_num_conns(codec, nid);
  322. if (num_conns <= 1)
  323. return 1;
  324. type = get_wcaps_type(get_wcaps(codec, nid));
  325. if (type == AC_WID_AUD_MIX) {
  326. /* Matrix-mixer style (e.g. ALC882) */
  327. int active = imux->items[idx].index;
  328. for (i = 0; i < num_conns; i++) {
  329. unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
  330. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
  331. HDA_AMP_MUTE, v);
  332. }
  333. } else {
  334. /* MUX style (e.g. ALC880) */
  335. snd_hda_codec_write_cache(codec, nid, 0,
  336. AC_VERB_SET_CONNECT_SEL,
  337. imux->items[idx].index);
  338. }
  339. alc_inv_dmic_sync(codec, true);
  340. return 1;
  341. }
  342. static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
  343. struct snd_ctl_elem_value *ucontrol)
  344. {
  345. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  346. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  347. return alc_mux_select(codec, adc_idx,
  348. ucontrol->value.enumerated.item[0], false);
  349. }
  350. /*
  351. * set up the input pin config (depending on the given auto-pin type)
  352. */
  353. static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
  354. int auto_pin_type)
  355. {
  356. unsigned int val = PIN_IN;
  357. if (auto_pin_type == AUTO_PIN_MIC)
  358. val |= snd_hda_get_default_vref(codec, nid);
  359. snd_hda_set_pin_ctl(codec, nid, val);
  360. }
  361. /*
  362. * Append the given mixer and verb elements for the later use
  363. * The mixer array is referred in build_controls(), and init_verbs are
  364. * called in init().
  365. */
  366. static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
  367. {
  368. if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
  369. return;
  370. spec->mixers[spec->num_mixers++] = mix;
  371. }
  372. /*
  373. * GPIO setup tables, used in initialization
  374. */
  375. /* Enable GPIO mask and set output */
  376. static const struct hda_verb alc_gpio1_init_verbs[] = {
  377. {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
  378. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  379. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  380. { }
  381. };
  382. static const struct hda_verb alc_gpio2_init_verbs[] = {
  383. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  384. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  385. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  386. { }
  387. };
  388. static const struct hda_verb alc_gpio3_init_verbs[] = {
  389. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  390. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
  391. {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
  392. { }
  393. };
  394. /*
  395. * Fix hardware PLL issue
  396. * On some codecs, the analog PLL gating control must be off while
  397. * the default value is 1.
  398. */
  399. static void alc_fix_pll(struct hda_codec *codec)
  400. {
  401. struct alc_spec *spec = codec->spec;
  402. unsigned int val;
  403. if (!spec->pll_nid)
  404. return;
  405. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
  406. spec->pll_coef_idx);
  407. val = snd_hda_codec_read(codec, spec->pll_nid, 0,
  408. AC_VERB_GET_PROC_COEF, 0);
  409. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
  410. spec->pll_coef_idx);
  411. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
  412. val & ~(1 << spec->pll_coef_bit));
  413. }
  414. static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
  415. unsigned int coef_idx, unsigned int coef_bit)
  416. {
  417. struct alc_spec *spec = codec->spec;
  418. spec->pll_nid = nid;
  419. spec->pll_coef_idx = coef_idx;
  420. spec->pll_coef_bit = coef_bit;
  421. alc_fix_pll(codec);
  422. }
  423. /*
  424. * Jack detections for HP auto-mute and mic-switch
  425. */
  426. /* check each pin in the given array; returns true if any of them is plugged */
  427. static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  428. {
  429. int i, present = 0;
  430. for (i = 0; i < num_pins; i++) {
  431. hda_nid_t nid = pins[i];
  432. if (!nid)
  433. break;
  434. present |= snd_hda_jack_detect(codec, nid);
  435. }
  436. return present;
  437. }
  438. /* standard HP/line-out auto-mute helper */
  439. static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
  440. bool mute, bool hp_out)
  441. {
  442. struct alc_spec *spec = codec->spec;
  443. unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
  444. unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
  445. int i;
  446. for (i = 0; i < num_pins; i++) {
  447. hda_nid_t nid = pins[i];
  448. unsigned int val;
  449. if (!nid)
  450. break;
  451. switch (spec->automute_mode) {
  452. case ALC_AUTOMUTE_PIN:
  453. /* don't reset VREF value in case it's controlling
  454. * the amp (see alc861_fixup_asus_amp_vref_0f())
  455. */
  456. if (spec->keep_vref_in_automute) {
  457. val = snd_hda_codec_read(codec, nid, 0,
  458. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  459. val &= ~PIN_HP;
  460. } else
  461. val = 0;
  462. val |= pin_bits;
  463. snd_hda_set_pin_ctl(codec, nid, val);
  464. break;
  465. case ALC_AUTOMUTE_AMP:
  466. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  467. HDA_AMP_MUTE, mute_bits);
  468. break;
  469. case ALC_AUTOMUTE_MIXER:
  470. nid = spec->automute_mixer_nid[i];
  471. if (!nid)
  472. break;
  473. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
  474. HDA_AMP_MUTE, mute_bits);
  475. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
  476. HDA_AMP_MUTE, mute_bits);
  477. break;
  478. }
  479. }
  480. }
  481. /* Toggle outputs muting */
  482. static void update_outputs(struct hda_codec *codec)
  483. {
  484. struct alc_spec *spec = codec->spec;
  485. int on;
  486. /* Control HP pins/amps depending on master_mute state;
  487. * in general, HP pins/amps control should be enabled in all cases,
  488. * but currently set only for master_mute, just to be safe
  489. */
  490. if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
  491. do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
  492. spec->autocfg.hp_pins, spec->master_mute, true);
  493. if (!spec->automute_speaker)
  494. on = 0;
  495. else
  496. on = spec->hp_jack_present | spec->line_jack_present;
  497. on |= spec->master_mute;
  498. do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
  499. spec->autocfg.speaker_pins, on, false);
  500. /* toggle line-out mutes if needed, too */
  501. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  502. if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
  503. spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
  504. return;
  505. if (!spec->automute_lo)
  506. on = 0;
  507. else
  508. on = spec->hp_jack_present;
  509. on |= spec->master_mute;
  510. do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
  511. spec->autocfg.line_out_pins, on, false);
  512. }
  513. static void call_update_outputs(struct hda_codec *codec)
  514. {
  515. struct alc_spec *spec = codec->spec;
  516. if (spec->automute_hook)
  517. spec->automute_hook(codec);
  518. else
  519. update_outputs(codec);
  520. }
  521. /* standard HP-automute helper */
  522. static void alc_hp_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
  523. {
  524. struct alc_spec *spec = codec->spec;
  525. spec->hp_jack_present =
  526. detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
  527. spec->autocfg.hp_pins);
  528. if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
  529. return;
  530. call_update_outputs(codec);
  531. }
  532. /* standard line-out-automute helper */
  533. static void alc_line_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
  534. {
  535. struct alc_spec *spec = codec->spec;
  536. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  537. return;
  538. /* check LO jack only when it's different from HP */
  539. if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
  540. return;
  541. spec->line_jack_present =
  542. detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
  543. spec->autocfg.line_out_pins);
  544. if (!spec->automute_speaker || !spec->detect_lo)
  545. return;
  546. call_update_outputs(codec);
  547. }
  548. #define get_connection_index(codec, mux, nid) \
  549. snd_hda_get_conn_index(codec, mux, nid, 0)
  550. /* standard mic auto-switch helper */
  551. static void alc_mic_automute(struct hda_codec *codec, struct hda_jack_tbl *jack)
  552. {
  553. struct alc_spec *spec = codec->spec;
  554. hda_nid_t *pins = spec->imux_pins;
  555. if (!spec->auto_mic || !spec->auto_mic_valid_imux)
  556. return;
  557. if (snd_BUG_ON(!spec->adc_nids))
  558. return;
  559. if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
  560. return;
  561. if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
  562. alc_mux_select(codec, 0, spec->ext_mic_idx, false);
  563. else if (spec->dock_mic_idx >= 0 &&
  564. snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
  565. alc_mux_select(codec, 0, spec->dock_mic_idx, false);
  566. else
  567. alc_mux_select(codec, 0, spec->int_mic_idx, false);
  568. }
  569. /* update the master volume per volume-knob's unsol event */
  570. static void alc_update_knob_master(struct hda_codec *codec, struct hda_jack_tbl *jack)
  571. {
  572. unsigned int val;
  573. struct snd_kcontrol *kctl;
  574. struct snd_ctl_elem_value *uctl;
  575. kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
  576. if (!kctl)
  577. return;
  578. uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
  579. if (!uctl)
  580. return;
  581. val = snd_hda_codec_read(codec, jack->nid, 0,
  582. AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
  583. val &= HDA_AMP_VOLMASK;
  584. uctl->value.integer.value[0] = val;
  585. uctl->value.integer.value[1] = val;
  586. kctl->put(kctl, uctl);
  587. kfree(uctl);
  588. }
  589. static void alc880_unsol_event(struct hda_codec *codec, unsigned int res)
  590. {
  591. /* For some reason, the res given from ALC880 is broken.
  592. Here we adjust it properly. */
  593. snd_hda_jack_unsol_event(codec, res >> 2);
  594. }
  595. /* call init functions of standard auto-mute helpers */
  596. static void alc_inithook(struct hda_codec *codec)
  597. {
  598. alc_hp_automute(codec, NULL);
  599. alc_line_automute(codec, NULL);
  600. alc_mic_automute(codec, NULL);
  601. }
  602. /* additional initialization for ALC888 variants */
  603. static void alc888_coef_init(struct hda_codec *codec)
  604. {
  605. unsigned int tmp;
  606. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
  607. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  608. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  609. if ((tmp & 0xf0) == 0x20)
  610. /* alc888S-VC */
  611. snd_hda_codec_read(codec, 0x20, 0,
  612. AC_VERB_SET_PROC_COEF, 0x830);
  613. else
  614. /* alc888-VB */
  615. snd_hda_codec_read(codec, 0x20, 0,
  616. AC_VERB_SET_PROC_COEF, 0x3030);
  617. }
  618. /* additional initialization for ALC889 variants */
  619. static void alc889_coef_init(struct hda_codec *codec)
  620. {
  621. unsigned int tmp;
  622. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  623. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  624. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  625. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
  626. }
  627. /* turn on/off EAPD control (only if available) */
  628. static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
  629. {
  630. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  631. return;
  632. if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
  633. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  634. on ? 2 : 0);
  635. }
  636. /* turn on/off EAPD controls of the codec */
  637. static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
  638. {
  639. /* We currently only handle front, HP */
  640. static hda_nid_t pins[] = {
  641. 0x0f, 0x10, 0x14, 0x15, 0
  642. };
  643. hda_nid_t *p;
  644. for (p = pins; *p; p++)
  645. set_eapd(codec, *p, on);
  646. }
  647. /* generic shutup callback;
  648. * just turning off EPAD and a little pause for avoiding pop-noise
  649. */
  650. static void alc_eapd_shutup(struct hda_codec *codec)
  651. {
  652. alc_auto_setup_eapd(codec, false);
  653. msleep(200);
  654. }
  655. /* generic EAPD initialization */
  656. static void alc_auto_init_amp(struct hda_codec *codec, int type)
  657. {
  658. unsigned int tmp;
  659. alc_auto_setup_eapd(codec, true);
  660. switch (type) {
  661. case ALC_INIT_GPIO1:
  662. snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
  663. break;
  664. case ALC_INIT_GPIO2:
  665. snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
  666. break;
  667. case ALC_INIT_GPIO3:
  668. snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
  669. break;
  670. case ALC_INIT_DEFAULT:
  671. switch (codec->vendor_id) {
  672. case 0x10ec0260:
  673. snd_hda_codec_write(codec, 0x1a, 0,
  674. AC_VERB_SET_COEF_INDEX, 7);
  675. tmp = snd_hda_codec_read(codec, 0x1a, 0,
  676. AC_VERB_GET_PROC_COEF, 0);
  677. snd_hda_codec_write(codec, 0x1a, 0,
  678. AC_VERB_SET_COEF_INDEX, 7);
  679. snd_hda_codec_write(codec, 0x1a, 0,
  680. AC_VERB_SET_PROC_COEF,
  681. tmp | 0x2010);
  682. break;
  683. case 0x10ec0262:
  684. case 0x10ec0880:
  685. case 0x10ec0882:
  686. case 0x10ec0883:
  687. case 0x10ec0885:
  688. case 0x10ec0887:
  689. /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
  690. alc889_coef_init(codec);
  691. break;
  692. case 0x10ec0888:
  693. alc888_coef_init(codec);
  694. break;
  695. #if 0 /* XXX: This may cause the silent output on speaker on some machines */
  696. case 0x10ec0267:
  697. case 0x10ec0268:
  698. snd_hda_codec_write(codec, 0x20, 0,
  699. AC_VERB_SET_COEF_INDEX, 7);
  700. tmp = snd_hda_codec_read(codec, 0x20, 0,
  701. AC_VERB_GET_PROC_COEF, 0);
  702. snd_hda_codec_write(codec, 0x20, 0,
  703. AC_VERB_SET_COEF_INDEX, 7);
  704. snd_hda_codec_write(codec, 0x20, 0,
  705. AC_VERB_SET_PROC_COEF,
  706. tmp | 0x3000);
  707. break;
  708. #endif /* XXX */
  709. }
  710. break;
  711. }
  712. }
  713. /*
  714. * Auto-Mute mode mixer enum support
  715. */
  716. static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
  717. struct snd_ctl_elem_info *uinfo)
  718. {
  719. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  720. struct alc_spec *spec = codec->spec;
  721. static const char * const texts3[] = {
  722. "Disabled", "Speaker Only", "Line Out+Speaker"
  723. };
  724. if (spec->automute_speaker_possible && spec->automute_lo_possible)
  725. return snd_hda_enum_helper_info(kcontrol, uinfo, 3, texts3);
  726. return snd_hda_enum_bool_helper_info(kcontrol, uinfo);
  727. }
  728. static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
  729. struct snd_ctl_elem_value *ucontrol)
  730. {
  731. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  732. struct alc_spec *spec = codec->spec;
  733. unsigned int val = 0;
  734. if (spec->automute_speaker)
  735. val++;
  736. if (spec->automute_lo)
  737. val++;
  738. ucontrol->value.enumerated.item[0] = val;
  739. return 0;
  740. }
  741. static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
  742. struct snd_ctl_elem_value *ucontrol)
  743. {
  744. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  745. struct alc_spec *spec = codec->spec;
  746. switch (ucontrol->value.enumerated.item[0]) {
  747. case 0:
  748. if (!spec->automute_speaker && !spec->automute_lo)
  749. return 0;
  750. spec->automute_speaker = 0;
  751. spec->automute_lo = 0;
  752. break;
  753. case 1:
  754. if (spec->automute_speaker_possible) {
  755. if (!spec->automute_lo && spec->automute_speaker)
  756. return 0;
  757. spec->automute_speaker = 1;
  758. spec->automute_lo = 0;
  759. } else if (spec->automute_lo_possible) {
  760. if (spec->automute_lo)
  761. return 0;
  762. spec->automute_lo = 1;
  763. } else
  764. return -EINVAL;
  765. break;
  766. case 2:
  767. if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
  768. return -EINVAL;
  769. if (spec->automute_speaker && spec->automute_lo)
  770. return 0;
  771. spec->automute_speaker = 1;
  772. spec->automute_lo = 1;
  773. break;
  774. default:
  775. return -EINVAL;
  776. }
  777. call_update_outputs(codec);
  778. return 1;
  779. }
  780. static const struct snd_kcontrol_new alc_automute_mode_enum = {
  781. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  782. .name = "Auto-Mute Mode",
  783. .info = alc_automute_mode_info,
  784. .get = alc_automute_mode_get,
  785. .put = alc_automute_mode_put,
  786. };
  787. static struct snd_kcontrol_new *
  788. alc_kcontrol_new(struct alc_spec *spec, const char *name,
  789. const struct snd_kcontrol_new *temp)
  790. {
  791. struct snd_kcontrol_new *knew = snd_array_new(&spec->kctls);
  792. if (!knew)
  793. return NULL;
  794. *knew = *temp;
  795. knew->name = kstrdup(name, GFP_KERNEL);
  796. if (!knew->name)
  797. return NULL;
  798. return knew;
  799. }
  800. static int alc_add_automute_mode_enum(struct hda_codec *codec)
  801. {
  802. struct alc_spec *spec = codec->spec;
  803. if (!alc_kcontrol_new(spec, "Auto-Mute Mode", &alc_automute_mode_enum))
  804. return -ENOMEM;
  805. return 0;
  806. }
  807. /*
  808. * Check the availability of HP/line-out auto-mute;
  809. * Set up appropriately if really supported
  810. */
  811. static int alc_init_automute(struct hda_codec *codec)
  812. {
  813. struct alc_spec *spec = codec->spec;
  814. struct auto_pin_cfg *cfg = &spec->autocfg;
  815. int present = 0;
  816. int i, err;
  817. if (cfg->hp_pins[0])
  818. present++;
  819. if (cfg->line_out_pins[0])
  820. present++;
  821. if (cfg->speaker_pins[0])
  822. present++;
  823. if (present < 2) /* need two different output types */
  824. return 0;
  825. if (!cfg->speaker_pins[0] &&
  826. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  827. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  828. sizeof(cfg->speaker_pins));
  829. cfg->speaker_outs = cfg->line_outs;
  830. }
  831. if (!cfg->hp_pins[0] &&
  832. cfg->line_out_type == AUTO_PIN_HP_OUT) {
  833. memcpy(cfg->hp_pins, cfg->line_out_pins,
  834. sizeof(cfg->hp_pins));
  835. cfg->hp_outs = cfg->line_outs;
  836. }
  837. spec->automute_mode = ALC_AUTOMUTE_PIN;
  838. for (i = 0; i < cfg->hp_outs; i++) {
  839. hda_nid_t nid = cfg->hp_pins[i];
  840. if (!is_jack_detectable(codec, nid))
  841. continue;
  842. snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
  843. nid);
  844. snd_hda_jack_detect_enable_callback(codec, nid, ALC_HP_EVENT,
  845. alc_hp_automute);
  846. spec->detect_hp = 1;
  847. }
  848. if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
  849. if (cfg->speaker_outs)
  850. for (i = 0; i < cfg->line_outs; i++) {
  851. hda_nid_t nid = cfg->line_out_pins[i];
  852. if (!is_jack_detectable(codec, nid))
  853. continue;
  854. snd_printdd("realtek: Enable Line-Out "
  855. "auto-muting on NID 0x%x\n", nid);
  856. snd_hda_jack_detect_enable_callback(codec, nid, ALC_FRONT_EVENT,
  857. alc_line_automute);
  858. spec->detect_lo = 1;
  859. }
  860. spec->automute_lo_possible = spec->detect_hp;
  861. }
  862. spec->automute_speaker_possible = cfg->speaker_outs &&
  863. (spec->detect_hp || spec->detect_lo);
  864. spec->automute_lo = spec->automute_lo_possible;
  865. spec->automute_speaker = spec->automute_speaker_possible;
  866. if (spec->automute_speaker_possible || spec->automute_lo_possible) {
  867. /* create a control for automute mode */
  868. err = alc_add_automute_mode_enum(codec);
  869. if (err < 0)
  870. return err;
  871. }
  872. return 0;
  873. }
  874. /* return the position of NID in the list, or -1 if not found */
  875. static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  876. {
  877. int i;
  878. for (i = 0; i < nums; i++)
  879. if (list[i] == nid)
  880. return i;
  881. return -1;
  882. }
  883. /* check whether dynamic ADC-switching is available */
  884. static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
  885. {
  886. struct alc_spec *spec = codec->spec;
  887. struct hda_input_mux *imux = &spec->private_imux[0];
  888. int i, n, idx;
  889. hda_nid_t cap, pin;
  890. if (imux != spec->input_mux) /* no dynamic imux? */
  891. return false;
  892. for (n = 0; n < spec->num_adc_nids; n++) {
  893. cap = spec->private_capsrc_nids[n];
  894. for (i = 0; i < imux->num_items; i++) {
  895. pin = spec->imux_pins[i];
  896. if (!pin)
  897. return false;
  898. if (get_connection_index(codec, cap, pin) < 0)
  899. break;
  900. }
  901. if (i >= imux->num_items)
  902. return true; /* no ADC-switch is needed */
  903. }
  904. for (i = 0; i < imux->num_items; i++) {
  905. pin = spec->imux_pins[i];
  906. for (n = 0; n < spec->num_adc_nids; n++) {
  907. cap = spec->private_capsrc_nids[n];
  908. idx = get_connection_index(codec, cap, pin);
  909. if (idx >= 0) {
  910. imux->items[i].index = idx;
  911. spec->dyn_adc_idx[i] = n;
  912. break;
  913. }
  914. }
  915. }
  916. snd_printdd("realtek: enabling ADC switching\n");
  917. spec->dyn_adc_switch = 1;
  918. return true;
  919. }
  920. /* check whether all auto-mic pins are valid; setup indices if OK */
  921. static bool alc_auto_mic_check_imux(struct hda_codec *codec)
  922. {
  923. struct alc_spec *spec = codec->spec;
  924. const struct hda_input_mux *imux;
  925. if (!spec->auto_mic)
  926. return false;
  927. if (spec->auto_mic_valid_imux)
  928. return true; /* already checked */
  929. /* fill up imux indices */
  930. if (!alc_check_dyn_adc_switch(codec)) {
  931. spec->auto_mic = 0;
  932. return false;
  933. }
  934. imux = spec->input_mux;
  935. spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
  936. spec->imux_pins, imux->num_items);
  937. spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
  938. spec->imux_pins, imux->num_items);
  939. spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
  940. spec->imux_pins, imux->num_items);
  941. if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
  942. spec->auto_mic = 0;
  943. return false; /* no corresponding imux */
  944. }
  945. snd_hda_jack_detect_enable_callback(codec, spec->ext_mic_pin,
  946. ALC_MIC_EVENT, alc_mic_automute);
  947. if (spec->dock_mic_pin)
  948. snd_hda_jack_detect_enable_callback(codec, spec->dock_mic_pin,
  949. ALC_MIC_EVENT,
  950. alc_mic_automute);
  951. spec->auto_mic_valid_imux = 1;
  952. spec->auto_mic = 1;
  953. return true;
  954. }
  955. /*
  956. * Check the availability of auto-mic switch;
  957. * Set up if really supported
  958. */
  959. static int alc_init_auto_mic(struct hda_codec *codec)
  960. {
  961. struct alc_spec *spec = codec->spec;
  962. struct auto_pin_cfg *cfg = &spec->autocfg;
  963. hda_nid_t fixed, ext, dock;
  964. int i;
  965. if (spec->shared_mic_hp)
  966. return 0; /* no auto-mic for the shared I/O */
  967. spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
  968. fixed = ext = dock = 0;
  969. for (i = 0; i < cfg->num_inputs; i++) {
  970. hda_nid_t nid = cfg->inputs[i].pin;
  971. unsigned int defcfg;
  972. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  973. switch (snd_hda_get_input_pin_attr(defcfg)) {
  974. case INPUT_PIN_ATTR_INT:
  975. if (fixed)
  976. return 0; /* already occupied */
  977. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  978. return 0; /* invalid type */
  979. fixed = nid;
  980. break;
  981. case INPUT_PIN_ATTR_UNUSED:
  982. return 0; /* invalid entry */
  983. case INPUT_PIN_ATTR_DOCK:
  984. if (dock)
  985. return 0; /* already occupied */
  986. if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
  987. return 0; /* invalid type */
  988. dock = nid;
  989. break;
  990. default:
  991. if (ext)
  992. return 0; /* already occupied */
  993. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  994. return 0; /* invalid type */
  995. ext = nid;
  996. break;
  997. }
  998. }
  999. if (!ext && dock) {
  1000. ext = dock;
  1001. dock = 0;
  1002. }
  1003. if (!ext || !fixed)
  1004. return 0;
  1005. if (!is_jack_detectable(codec, ext))
  1006. return 0; /* no unsol support */
  1007. if (dock && !is_jack_detectable(codec, dock))
  1008. return 0; /* no unsol support */
  1009. /* check imux indices */
  1010. spec->ext_mic_pin = ext;
  1011. spec->int_mic_pin = fixed;
  1012. spec->dock_mic_pin = dock;
  1013. spec->auto_mic = 1;
  1014. if (!alc_auto_mic_check_imux(codec))
  1015. return 0;
  1016. snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
  1017. ext, fixed, dock);
  1018. return 0;
  1019. }
  1020. /* check the availabilities of auto-mute and auto-mic switches */
  1021. static int alc_auto_check_switches(struct hda_codec *codec)
  1022. {
  1023. int err;
  1024. err = alc_init_automute(codec);
  1025. if (err < 0)
  1026. return err;
  1027. err = alc_init_auto_mic(codec);
  1028. if (err < 0)
  1029. return err;
  1030. return 0;
  1031. }
  1032. /*
  1033. * Realtek SSID verification
  1034. */
  1035. /* Could be any non-zero and even value. When used as fixup, tells
  1036. * the driver to ignore any present sku defines.
  1037. */
  1038. #define ALC_FIXUP_SKU_IGNORE (2)
  1039. static void alc_fixup_sku_ignore(struct hda_codec *codec,
  1040. const struct hda_fixup *fix, int action)
  1041. {
  1042. struct alc_spec *spec = codec->spec;
  1043. if (action == HDA_FIXUP_ACT_PRE_PROBE) {
  1044. spec->cdefine.fixup = 1;
  1045. spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
  1046. }
  1047. }
  1048. static int alc_auto_parse_customize_define(struct hda_codec *codec)
  1049. {
  1050. unsigned int ass, tmp, i;
  1051. unsigned nid = 0;
  1052. struct alc_spec *spec = codec->spec;
  1053. spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
  1054. if (spec->cdefine.fixup) {
  1055. ass = spec->cdefine.sku_cfg;
  1056. if (ass == ALC_FIXUP_SKU_IGNORE)
  1057. return -1;
  1058. goto do_sku;
  1059. }
  1060. ass = codec->subsystem_id & 0xffff;
  1061. if (ass != codec->bus->pci->subsystem_device && (ass & 1))
  1062. goto do_sku;
  1063. nid = 0x1d;
  1064. if (codec->vendor_id == 0x10ec0260)
  1065. nid = 0x17;
  1066. ass = snd_hda_codec_get_pincfg(codec, nid);
  1067. if (!(ass & 1)) {
  1068. printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
  1069. codec->chip_name, ass);
  1070. return -1;
  1071. }
  1072. /* check sum */
  1073. tmp = 0;
  1074. for (i = 1; i < 16; i++) {
  1075. if ((ass >> i) & 1)
  1076. tmp++;
  1077. }
  1078. if (((ass >> 16) & 0xf) != tmp)
  1079. return -1;
  1080. spec->cdefine.port_connectivity = ass >> 30;
  1081. spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
  1082. spec->cdefine.check_sum = (ass >> 16) & 0xf;
  1083. spec->cdefine.customization = ass >> 8;
  1084. do_sku:
  1085. spec->cdefine.sku_cfg = ass;
  1086. spec->cdefine.external_amp = (ass & 0x38) >> 3;
  1087. spec->cdefine.platform_type = (ass & 0x4) >> 2;
  1088. spec->cdefine.swap = (ass & 0x2) >> 1;
  1089. spec->cdefine.override = ass & 0x1;
  1090. snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
  1091. nid, spec->cdefine.sku_cfg);
  1092. snd_printd("SKU: port_connectivity=0x%x\n",
  1093. spec->cdefine.port_connectivity);
  1094. snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
  1095. snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
  1096. snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
  1097. snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
  1098. snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
  1099. snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
  1100. snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
  1101. return 0;
  1102. }
  1103. /* return true if the given NID is found in the list */
  1104. static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  1105. {
  1106. return find_idx_in_nid_list(nid, list, nums) >= 0;
  1107. }
  1108. /* check subsystem ID and set up device-specific initialization;
  1109. * return 1 if initialized, 0 if invalid SSID
  1110. */
  1111. /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
  1112. * 31 ~ 16 : Manufacture ID
  1113. * 15 ~ 8 : SKU ID
  1114. * 7 ~ 0 : Assembly ID
  1115. * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
  1116. */
  1117. static int alc_subsystem_id(struct hda_codec *codec,
  1118. hda_nid_t porta, hda_nid_t porte,
  1119. hda_nid_t portd, hda_nid_t porti)
  1120. {
  1121. unsigned int ass, tmp, i;
  1122. unsigned nid;
  1123. struct alc_spec *spec = codec->spec;
  1124. if (spec->cdefine.fixup) {
  1125. ass = spec->cdefine.sku_cfg;
  1126. if (ass == ALC_FIXUP_SKU_IGNORE)
  1127. return 0;
  1128. goto do_sku;
  1129. }
  1130. ass = codec->subsystem_id & 0xffff;
  1131. if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
  1132. goto do_sku;
  1133. /* invalid SSID, check the special NID pin defcfg instead */
  1134. /*
  1135. * 31~30 : port connectivity
  1136. * 29~21 : reserve
  1137. * 20 : PCBEEP input
  1138. * 19~16 : Check sum (15:1)
  1139. * 15~1 : Custom
  1140. * 0 : override
  1141. */
  1142. nid = 0x1d;
  1143. if (codec->vendor_id == 0x10ec0260)
  1144. nid = 0x17;
  1145. ass = snd_hda_codec_get_pincfg(codec, nid);
  1146. snd_printd("realtek: No valid SSID, "
  1147. "checking pincfg 0x%08x for NID 0x%x\n",
  1148. ass, nid);
  1149. if (!(ass & 1))
  1150. return 0;
  1151. if ((ass >> 30) != 1) /* no physical connection */
  1152. return 0;
  1153. /* check sum */
  1154. tmp = 0;
  1155. for (i = 1; i < 16; i++) {
  1156. if ((ass >> i) & 1)
  1157. tmp++;
  1158. }
  1159. if (((ass >> 16) & 0xf) != tmp)
  1160. return 0;
  1161. do_sku:
  1162. snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
  1163. ass & 0xffff, codec->vendor_id);
  1164. /*
  1165. * 0 : override
  1166. * 1 : Swap Jack
  1167. * 2 : 0 --> Desktop, 1 --> Laptop
  1168. * 3~5 : External Amplifier control
  1169. * 7~6 : Reserved
  1170. */
  1171. tmp = (ass & 0x38) >> 3; /* external Amp control */
  1172. switch (tmp) {
  1173. case 1:
  1174. spec->init_amp = ALC_INIT_GPIO1;
  1175. break;
  1176. case 3:
  1177. spec->init_amp = ALC_INIT_GPIO2;
  1178. break;
  1179. case 7:
  1180. spec->init_amp = ALC_INIT_GPIO3;
  1181. break;
  1182. case 5:
  1183. default:
  1184. spec->init_amp = ALC_INIT_DEFAULT;
  1185. break;
  1186. }
  1187. /* is laptop or Desktop and enable the function "Mute internal speaker
  1188. * when the external headphone out jack is plugged"
  1189. */
  1190. if (!(ass & 0x8000))
  1191. return 1;
  1192. /*
  1193. * 10~8 : Jack location
  1194. * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
  1195. * 14~13: Resvered
  1196. * 15 : 1 --> enable the function "Mute internal speaker
  1197. * when the external headphone out jack is plugged"
  1198. */
  1199. if (!spec->autocfg.hp_pins[0] &&
  1200. !(spec->autocfg.line_out_pins[0] &&
  1201. spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
  1202. hda_nid_t nid;
  1203. tmp = (ass >> 11) & 0x3; /* HP to chassis */
  1204. if (tmp == 0)
  1205. nid = porta;
  1206. else if (tmp == 1)
  1207. nid = porte;
  1208. else if (tmp == 2)
  1209. nid = portd;
  1210. else if (tmp == 3)
  1211. nid = porti;
  1212. else
  1213. return 1;
  1214. if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
  1215. spec->autocfg.line_outs))
  1216. return 1;
  1217. spec->autocfg.hp_pins[0] = nid;
  1218. }
  1219. return 1;
  1220. }
  1221. /* Check the validity of ALC subsystem-id
  1222. * ports contains an array of 4 pin NIDs for port-A, E, D and I */
  1223. static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
  1224. {
  1225. if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
  1226. struct alc_spec *spec = codec->spec;
  1227. snd_printd("realtek: "
  1228. "Enable default setup for auto mode as fallback\n");
  1229. spec->init_amp = ALC_INIT_DEFAULT;
  1230. }
  1231. }
  1232. /*
  1233. * COEF access helper functions
  1234. */
  1235. static int alc_read_coef_idx(struct hda_codec *codec,
  1236. unsigned int coef_idx)
  1237. {
  1238. unsigned int val;
  1239. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
  1240. coef_idx);
  1241. val = snd_hda_codec_read(codec, 0x20, 0,
  1242. AC_VERB_GET_PROC_COEF, 0);
  1243. return val;
  1244. }
  1245. static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
  1246. unsigned int coef_val)
  1247. {
  1248. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
  1249. coef_idx);
  1250. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
  1251. coef_val);
  1252. }
  1253. /* a special bypass for COEF 0; read the cached value at the second time */
  1254. static unsigned int alc_get_coef0(struct hda_codec *codec)
  1255. {
  1256. struct alc_spec *spec = codec->spec;
  1257. if (!spec->coef0)
  1258. spec->coef0 = alc_read_coef_idx(codec, 0);
  1259. return spec->coef0;
  1260. }
  1261. /*
  1262. * Digital I/O handling
  1263. */
  1264. /* set right pin controls for digital I/O */
  1265. static void alc_auto_init_digital(struct hda_codec *codec)
  1266. {
  1267. struct alc_spec *spec = codec->spec;
  1268. int i;
  1269. hda_nid_t pin, dac;
  1270. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  1271. pin = spec->autocfg.dig_out_pins[i];
  1272. if (!pin)
  1273. continue;
  1274. snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
  1275. if (!i)
  1276. dac = spec->multiout.dig_out_nid;
  1277. else
  1278. dac = spec->slave_dig_outs[i - 1];
  1279. if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
  1280. continue;
  1281. snd_hda_codec_write(codec, dac, 0,
  1282. AC_VERB_SET_AMP_GAIN_MUTE,
  1283. AMP_OUT_UNMUTE);
  1284. }
  1285. pin = spec->autocfg.dig_in_pin;
  1286. if (pin)
  1287. snd_hda_set_pin_ctl(codec, pin, PIN_IN);
  1288. }
  1289. /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
  1290. static void alc_auto_parse_digital(struct hda_codec *codec)
  1291. {
  1292. struct alc_spec *spec = codec->spec;
  1293. int i, err, nums;
  1294. hda_nid_t dig_nid;
  1295. /* support multiple SPDIFs; the secondary is set up as a slave */
  1296. nums = 0;
  1297. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  1298. hda_nid_t conn[4];
  1299. err = snd_hda_get_connections(codec,
  1300. spec->autocfg.dig_out_pins[i],
  1301. conn, ARRAY_SIZE(conn));
  1302. if (err <= 0)
  1303. continue;
  1304. dig_nid = conn[0]; /* assume the first element is audio-out */
  1305. if (!nums) {
  1306. spec->multiout.dig_out_nid = dig_nid;
  1307. spec->dig_out_type = spec->autocfg.dig_out_type[0];
  1308. } else {
  1309. spec->multiout.slave_dig_outs = spec->slave_dig_outs;
  1310. if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
  1311. break;
  1312. spec->slave_dig_outs[nums - 1] = dig_nid;
  1313. }
  1314. nums++;
  1315. }
  1316. if (spec->autocfg.dig_in_pin) {
  1317. dig_nid = codec->start_nid;
  1318. for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
  1319. unsigned int wcaps = get_wcaps(codec, dig_nid);
  1320. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  1321. continue;
  1322. if (!(wcaps & AC_WCAP_DIGITAL))
  1323. continue;
  1324. if (!(wcaps & AC_WCAP_CONN_LIST))
  1325. continue;
  1326. err = get_connection_index(codec, dig_nid,
  1327. spec->autocfg.dig_in_pin);
  1328. if (err >= 0) {
  1329. spec->dig_in_nid = dig_nid;
  1330. break;
  1331. }
  1332. }
  1333. }
  1334. }
  1335. /*
  1336. * capture mixer elements
  1337. */
  1338. static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
  1339. struct snd_ctl_elem_info *uinfo)
  1340. {
  1341. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1342. struct alc_spec *spec = codec->spec;
  1343. unsigned long val;
  1344. int err;
  1345. mutex_lock(&codec->control_mutex);
  1346. if (spec->vol_in_capsrc)
  1347. val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
  1348. else
  1349. val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
  1350. kcontrol->private_value = val;
  1351. err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
  1352. mutex_unlock(&codec->control_mutex);
  1353. return err;
  1354. }
  1355. static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  1356. unsigned int size, unsigned int __user *tlv)
  1357. {
  1358. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1359. struct alc_spec *spec = codec->spec;
  1360. unsigned long val;
  1361. int err;
  1362. mutex_lock(&codec->control_mutex);
  1363. if (spec->vol_in_capsrc)
  1364. val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
  1365. else
  1366. val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
  1367. kcontrol->private_value = val;
  1368. err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
  1369. mutex_unlock(&codec->control_mutex);
  1370. return err;
  1371. }
  1372. typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
  1373. struct snd_ctl_elem_value *ucontrol);
  1374. static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
  1375. struct snd_ctl_elem_value *ucontrol,
  1376. getput_call_t func, bool is_put)
  1377. {
  1378. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1379. struct alc_spec *spec = codec->spec;
  1380. int i, err = 0;
  1381. mutex_lock(&codec->control_mutex);
  1382. if (is_put && spec->dyn_adc_switch) {
  1383. for (i = 0; i < spec->num_adc_nids; i++) {
  1384. kcontrol->private_value =
  1385. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
  1386. 3, 0, HDA_INPUT);
  1387. err = func(kcontrol, ucontrol);
  1388. if (err < 0)
  1389. goto error;
  1390. }
  1391. } else {
  1392. i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1393. if (spec->vol_in_capsrc)
  1394. kcontrol->private_value =
  1395. HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
  1396. 3, 0, HDA_OUTPUT);
  1397. else
  1398. kcontrol->private_value =
  1399. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
  1400. 3, 0, HDA_INPUT);
  1401. err = func(kcontrol, ucontrol);
  1402. }
  1403. if (err >= 0 && is_put)
  1404. alc_inv_dmic_sync(codec, false);
  1405. error:
  1406. mutex_unlock(&codec->control_mutex);
  1407. return err;
  1408. }
  1409. static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
  1410. struct snd_ctl_elem_value *ucontrol)
  1411. {
  1412. return alc_cap_getput_caller(kcontrol, ucontrol,
  1413. snd_hda_mixer_amp_volume_get, false);
  1414. }
  1415. static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
  1416. struct snd_ctl_elem_value *ucontrol)
  1417. {
  1418. return alc_cap_getput_caller(kcontrol, ucontrol,
  1419. snd_hda_mixer_amp_volume_put, true);
  1420. }
  1421. /* capture mixer elements */
  1422. #define alc_cap_sw_info snd_ctl_boolean_stereo_info
  1423. static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
  1424. struct snd_ctl_elem_value *ucontrol)
  1425. {
  1426. return alc_cap_getput_caller(kcontrol, ucontrol,
  1427. snd_hda_mixer_amp_switch_get, false);
  1428. }
  1429. static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
  1430. struct snd_ctl_elem_value *ucontrol)
  1431. {
  1432. return alc_cap_getput_caller(kcontrol, ucontrol,
  1433. snd_hda_mixer_amp_switch_put, true);
  1434. }
  1435. #define _DEFINE_CAPMIX(num) \
  1436. { \
  1437. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1438. .name = "Capture Switch", \
  1439. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  1440. .count = num, \
  1441. .info = alc_cap_sw_info, \
  1442. .get = alc_cap_sw_get, \
  1443. .put = alc_cap_sw_put, \
  1444. }, \
  1445. { \
  1446. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1447. .name = "Capture Volume", \
  1448. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  1449. SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  1450. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
  1451. .count = num, \
  1452. .info = alc_cap_vol_info, \
  1453. .get = alc_cap_vol_get, \
  1454. .put = alc_cap_vol_put, \
  1455. .tlv = { .c = alc_cap_vol_tlv }, \
  1456. }
  1457. #define _DEFINE_CAPSRC(num) \
  1458. { \
  1459. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1460. /* .name = "Capture Source", */ \
  1461. .name = "Input Source", \
  1462. .count = num, \
  1463. .info = alc_mux_enum_info, \
  1464. .get = alc_mux_enum_get, \
  1465. .put = alc_mux_enum_put, \
  1466. }
  1467. #define DEFINE_CAPMIX(num) \
  1468. static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
  1469. _DEFINE_CAPMIX(num), \
  1470. _DEFINE_CAPSRC(num), \
  1471. { } /* end */ \
  1472. }
  1473. #define DEFINE_CAPMIX_NOSRC(num) \
  1474. static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
  1475. _DEFINE_CAPMIX(num), \
  1476. { } /* end */ \
  1477. }
  1478. /* up to three ADCs */
  1479. DEFINE_CAPMIX(1);
  1480. DEFINE_CAPMIX(2);
  1481. DEFINE_CAPMIX(3);
  1482. DEFINE_CAPMIX_NOSRC(1);
  1483. DEFINE_CAPMIX_NOSRC(2);
  1484. DEFINE_CAPMIX_NOSRC(3);
  1485. /*
  1486. * Inverted digital-mic handling
  1487. *
  1488. * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
  1489. * gives the additional mute only to the right channel of the digital mic
  1490. * capture stream. This is a workaround for avoiding the almost silence
  1491. * by summing the stereo stream from some (known to be ForteMedia)
  1492. * digital mic unit.
  1493. *
  1494. * The logic is to call alc_inv_dmic_sync() after each action (possibly)
  1495. * modifying ADC amp. When the mute flag is set, it mutes the R-channel
  1496. * without caching so that the cache can still keep the original value.
  1497. * The cached value is then restored when the flag is set off or any other
  1498. * than d-mic is used as the current input source.
  1499. */
  1500. static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
  1501. {
  1502. struct alc_spec *spec = codec->spec;
  1503. int i;
  1504. if (!spec->inv_dmic_fixup)
  1505. return;
  1506. if (!spec->inv_dmic_muted && !force)
  1507. return;
  1508. for (i = 0; i < spec->num_adc_nids; i++) {
  1509. int src = spec->dyn_adc_switch ? 0 : i;
  1510. bool dmic_fixup = false;
  1511. hda_nid_t nid;
  1512. int parm, dir, v;
  1513. if (spec->inv_dmic_muted &&
  1514. spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
  1515. dmic_fixup = true;
  1516. if (!dmic_fixup && !force)
  1517. continue;
  1518. if (spec->vol_in_capsrc) {
  1519. nid = spec->capsrc_nids[i];
  1520. parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
  1521. dir = HDA_OUTPUT;
  1522. } else {
  1523. nid = spec->adc_nids[i];
  1524. parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
  1525. dir = HDA_INPUT;
  1526. }
  1527. /* we care only right channel */
  1528. v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
  1529. if (v & 0x80) /* if already muted, we don't need to touch */
  1530. continue;
  1531. if (dmic_fixup) /* add mute for d-mic */
  1532. v |= 0x80;
  1533. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1534. parm | v);
  1535. }
  1536. }
  1537. static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
  1538. struct snd_ctl_elem_value *ucontrol)
  1539. {
  1540. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1541. struct alc_spec *spec = codec->spec;
  1542. ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
  1543. return 0;
  1544. }
  1545. static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
  1546. struct snd_ctl_elem_value *ucontrol)
  1547. {
  1548. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1549. struct alc_spec *spec = codec->spec;
  1550. unsigned int val = !ucontrol->value.integer.value[0];
  1551. if (val == spec->inv_dmic_muted)
  1552. return 0;
  1553. spec->inv_dmic_muted = val;
  1554. alc_inv_dmic_sync(codec, true);
  1555. return 0;
  1556. }
  1557. static const struct snd_kcontrol_new alc_inv_dmic_sw = {
  1558. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1559. .info = snd_ctl_boolean_mono_info,
  1560. .get = alc_inv_dmic_sw_get,
  1561. .put = alc_inv_dmic_sw_put,
  1562. };
  1563. static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
  1564. {
  1565. struct alc_spec *spec = codec->spec;
  1566. if (!alc_kcontrol_new(spec, "Inverted Internal Mic Capture Switch",
  1567. &alc_inv_dmic_sw))
  1568. return -ENOMEM;
  1569. spec->inv_dmic_fixup = 1;
  1570. spec->inv_dmic_muted = 0;
  1571. spec->inv_dmic_pin = nid;
  1572. return 0;
  1573. }
  1574. /* typically the digital mic is put at node 0x12 */
  1575. static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
  1576. const struct alc_fixup *fix, int action)
  1577. {
  1578. if (action == ALC_FIXUP_ACT_PROBE)
  1579. alc_add_inv_dmic_mixer(codec, 0x12);
  1580. }
  1581. /*
  1582. * virtual master controls
  1583. */
  1584. /*
  1585. * slave controls for virtual master
  1586. */
  1587. static const char * const alc_slave_pfxs[] = {
  1588. "Front", "Surround", "Center", "LFE", "Side",
  1589. "Headphone", "Speaker", "Mono", "Line Out",
  1590. "CLFE", "Bass Speaker", "PCM",
  1591. NULL,
  1592. };
  1593. /*
  1594. * build control elements
  1595. */
  1596. #define NID_MAPPING (-1)
  1597. #define SUBDEV_SPEAKER_ (0 << 6)
  1598. #define SUBDEV_HP_ (1 << 6)
  1599. #define SUBDEV_LINE_ (2 << 6)
  1600. #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
  1601. #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
  1602. #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
  1603. static void alc_free_kctls(struct hda_codec *codec);
  1604. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1605. /* additional beep mixers; the actual parameters are overwritten at build */
  1606. static const struct snd_kcontrol_new alc_beep_mixer[] = {
  1607. HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
  1608. HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
  1609. { } /* end */
  1610. };
  1611. #endif
  1612. static int __alc_build_controls(struct hda_codec *codec)
  1613. {
  1614. struct alc_spec *spec = codec->spec;
  1615. struct snd_kcontrol *kctl = NULL;
  1616. const struct snd_kcontrol_new *knew;
  1617. int i, j, err;
  1618. unsigned int u;
  1619. hda_nid_t nid;
  1620. for (i = 0; i < spec->num_mixers; i++) {
  1621. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1622. if (err < 0)
  1623. return err;
  1624. }
  1625. if (spec->cap_mixer) {
  1626. err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
  1627. if (err < 0)
  1628. return err;
  1629. }
  1630. if (spec->multiout.dig_out_nid) {
  1631. err = snd_hda_create_dig_out_ctls(codec,
  1632. spec->multiout.dig_out_nid,
  1633. spec->multiout.dig_out_nid,
  1634. spec->pcm_rec[1].pcm_type);
  1635. if (err < 0)
  1636. return err;
  1637. if (!spec->no_analog) {
  1638. err = snd_hda_create_spdif_share_sw(codec,
  1639. &spec->multiout);
  1640. if (err < 0)
  1641. return err;
  1642. spec->multiout.share_spdif = 1;
  1643. }
  1644. }
  1645. if (spec->dig_in_nid) {
  1646. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1647. if (err < 0)
  1648. return err;
  1649. }
  1650. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1651. /* create beep controls if needed */
  1652. if (spec->beep_amp) {
  1653. const struct snd_kcontrol_new *knew;
  1654. for (knew = alc_beep_mixer; knew->name; knew++) {
  1655. struct snd_kcontrol *kctl;
  1656. kctl = snd_ctl_new1(knew, codec);
  1657. if (!kctl)
  1658. return -ENOMEM;
  1659. kctl->private_value = spec->beep_amp;
  1660. err = snd_hda_ctl_add(codec, 0, kctl);
  1661. if (err < 0)
  1662. return err;
  1663. }
  1664. }
  1665. #endif
  1666. /* if we have no master control, let's create it */
  1667. if (!spec->no_analog &&
  1668. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  1669. unsigned int vmaster_tlv[4];
  1670. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  1671. HDA_OUTPUT, vmaster_tlv);
  1672. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  1673. vmaster_tlv, alc_slave_pfxs,
  1674. "Playback Volume");
  1675. if (err < 0)
  1676. return err;
  1677. }
  1678. if (!spec->no_analog &&
  1679. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  1680. err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
  1681. NULL, alc_slave_pfxs,
  1682. "Playback Switch",
  1683. true, &spec->vmaster_mute.sw_kctl);
  1684. if (err < 0)
  1685. return err;
  1686. }
  1687. /* assign Capture Source enums to NID */
  1688. if (spec->capsrc_nids || spec->adc_nids) {
  1689. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  1690. if (!kctl)
  1691. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  1692. for (i = 0; kctl && i < kctl->count; i++) {
  1693. err = snd_hda_add_nid(codec, kctl, i,
  1694. get_capsrc(spec, i));
  1695. if (err < 0)
  1696. return err;
  1697. }
  1698. }
  1699. if (spec->cap_mixer && spec->adc_nids) {
  1700. const char *kname = kctl ? kctl->id.name : NULL;
  1701. for (knew = spec->cap_mixer; knew->name; knew++) {
  1702. if (kname && strcmp(knew->name, kname) == 0)
  1703. continue;
  1704. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1705. for (i = 0; kctl && i < kctl->count; i++) {
  1706. err = snd_hda_add_nid(codec, kctl, i,
  1707. spec->adc_nids[i]);
  1708. if (err < 0)
  1709. return err;
  1710. }
  1711. }
  1712. }
  1713. /* other nid->control mapping */
  1714. for (i = 0; i < spec->num_mixers; i++) {
  1715. for (knew = spec->mixers[i]; knew->name; knew++) {
  1716. if (knew->iface != NID_MAPPING)
  1717. continue;
  1718. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1719. if (kctl == NULL)
  1720. continue;
  1721. u = knew->subdevice;
  1722. for (j = 0; j < 4; j++, u >>= 8) {
  1723. nid = u & 0x3f;
  1724. if (nid == 0)
  1725. continue;
  1726. switch (u & 0xc0) {
  1727. case SUBDEV_SPEAKER_:
  1728. nid = spec->autocfg.speaker_pins[nid];
  1729. break;
  1730. case SUBDEV_LINE_:
  1731. nid = spec->autocfg.line_out_pins[nid];
  1732. break;
  1733. case SUBDEV_HP_:
  1734. nid = spec->autocfg.hp_pins[nid];
  1735. break;
  1736. default:
  1737. continue;
  1738. }
  1739. err = snd_hda_add_nid(codec, kctl, 0, nid);
  1740. if (err < 0)
  1741. return err;
  1742. }
  1743. u = knew->private_value;
  1744. for (j = 0; j < 4; j++, u >>= 8) {
  1745. nid = u & 0xff;
  1746. if (nid == 0)
  1747. continue;
  1748. err = snd_hda_add_nid(codec, kctl, 0, nid);
  1749. if (err < 0)
  1750. return err;
  1751. }
  1752. }
  1753. }
  1754. alc_free_kctls(codec); /* no longer needed */
  1755. return 0;
  1756. }
  1757. static int alc_build_jacks(struct hda_codec *codec)
  1758. {
  1759. struct alc_spec *spec = codec->spec;
  1760. if (spec->shared_mic_hp) {
  1761. int err;
  1762. int nid = spec->autocfg.inputs[1].pin;
  1763. err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
  1764. if (err < 0)
  1765. return err;
  1766. err = snd_hda_jack_detect_enable(codec, nid, 0);
  1767. if (err < 0)
  1768. return err;
  1769. }
  1770. return snd_hda_jack_add_kctls(codec, &spec->autocfg);
  1771. }
  1772. static int alc_build_controls(struct hda_codec *codec)
  1773. {
  1774. int err = __alc_build_controls(codec);
  1775. if (err < 0)
  1776. return err;
  1777. err = alc_build_jacks(codec);
  1778. if (err < 0)
  1779. return err;
  1780. alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
  1781. return 0;
  1782. }
  1783. /*
  1784. * Common callbacks
  1785. */
  1786. static void alc_init_special_input_src(struct hda_codec *codec);
  1787. static void alc_auto_init_std(struct hda_codec *codec);
  1788. static int alc_init(struct hda_codec *codec)
  1789. {
  1790. struct alc_spec *spec = codec->spec;
  1791. if (spec->init_hook)
  1792. spec->init_hook(codec);
  1793. alc_fix_pll(codec);
  1794. alc_auto_init_amp(codec, spec->init_amp);
  1795. snd_hda_gen_apply_verbs(codec);
  1796. alc_init_special_input_src(codec);
  1797. alc_auto_init_std(codec);
  1798. alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
  1799. hda_call_check_power_status(codec, 0x01);
  1800. return 0;
  1801. }
  1802. #ifdef CONFIG_PM
  1803. static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1804. {
  1805. struct alc_spec *spec = codec->spec;
  1806. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1807. }
  1808. #endif
  1809. /*
  1810. * Analog playback callbacks
  1811. */
  1812. static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1813. struct hda_codec *codec,
  1814. struct snd_pcm_substream *substream)
  1815. {
  1816. struct alc_spec *spec = codec->spec;
  1817. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1818. hinfo);
  1819. }
  1820. static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1821. struct hda_codec *codec,
  1822. unsigned int stream_tag,
  1823. unsigned int format,
  1824. struct snd_pcm_substream *substream)
  1825. {
  1826. struct alc_spec *spec = codec->spec;
  1827. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  1828. stream_tag, format, substream);
  1829. }
  1830. static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1831. struct hda_codec *codec,
  1832. struct snd_pcm_substream *substream)
  1833. {
  1834. struct alc_spec *spec = codec->spec;
  1835. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1836. }
  1837. /*
  1838. * Digital out
  1839. */
  1840. static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1841. struct hda_codec *codec,
  1842. struct snd_pcm_substream *substream)
  1843. {
  1844. struct alc_spec *spec = codec->spec;
  1845. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1846. }
  1847. static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1848. struct hda_codec *codec,
  1849. unsigned int stream_tag,
  1850. unsigned int format,
  1851. struct snd_pcm_substream *substream)
  1852. {
  1853. struct alc_spec *spec = codec->spec;
  1854. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1855. stream_tag, format, substream);
  1856. }
  1857. static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1858. struct hda_codec *codec,
  1859. struct snd_pcm_substream *substream)
  1860. {
  1861. struct alc_spec *spec = codec->spec;
  1862. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1863. }
  1864. static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1865. struct hda_codec *codec,
  1866. struct snd_pcm_substream *substream)
  1867. {
  1868. struct alc_spec *spec = codec->spec;
  1869. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1870. }
  1871. /*
  1872. * Analog capture
  1873. */
  1874. static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1875. struct hda_codec *codec,
  1876. unsigned int stream_tag,
  1877. unsigned int format,
  1878. struct snd_pcm_substream *substream)
  1879. {
  1880. struct alc_spec *spec = codec->spec;
  1881. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
  1882. stream_tag, 0, format);
  1883. return 0;
  1884. }
  1885. static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1886. struct hda_codec *codec,
  1887. struct snd_pcm_substream *substream)
  1888. {
  1889. struct alc_spec *spec = codec->spec;
  1890. snd_hda_codec_cleanup_stream(codec,
  1891. spec->adc_nids[substream->number + 1]);
  1892. return 0;
  1893. }
  1894. /* analog capture with dynamic dual-adc changes */
  1895. static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1896. struct hda_codec *codec,
  1897. unsigned int stream_tag,
  1898. unsigned int format,
  1899. struct snd_pcm_substream *substream)
  1900. {
  1901. struct alc_spec *spec = codec->spec;
  1902. spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
  1903. spec->cur_adc_stream_tag = stream_tag;
  1904. spec->cur_adc_format = format;
  1905. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  1906. return 0;
  1907. }
  1908. static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1909. struct hda_codec *codec,
  1910. struct snd_pcm_substream *substream)
  1911. {
  1912. struct alc_spec *spec = codec->spec;
  1913. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1914. spec->cur_adc = 0;
  1915. return 0;
  1916. }
  1917. static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
  1918. .substreams = 1,
  1919. .channels_min = 2,
  1920. .channels_max = 2,
  1921. .nid = 0, /* fill later */
  1922. .ops = {
  1923. .prepare = dyn_adc_capture_pcm_prepare,
  1924. .cleanup = dyn_adc_capture_pcm_cleanup
  1925. },
  1926. };
  1927. /*
  1928. */
  1929. static const struct hda_pcm_stream alc_pcm_analog_playback = {
  1930. .substreams = 1,
  1931. .channels_min = 2,
  1932. .channels_max = 8,
  1933. /* NID is set in alc_build_pcms */
  1934. .ops = {
  1935. .open = alc_playback_pcm_open,
  1936. .prepare = alc_playback_pcm_prepare,
  1937. .cleanup = alc_playback_pcm_cleanup
  1938. },
  1939. };
  1940. static const struct hda_pcm_stream alc_pcm_analog_capture = {
  1941. .substreams = 1,
  1942. .channels_min = 2,
  1943. .channels_max = 2,
  1944. /* NID is set in alc_build_pcms */
  1945. };
  1946. static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
  1947. .substreams = 1,
  1948. .channels_min = 2,
  1949. .channels_max = 2,
  1950. /* NID is set in alc_build_pcms */
  1951. };
  1952. static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
  1953. .substreams = 2, /* can be overridden */
  1954. .channels_min = 2,
  1955. .channels_max = 2,
  1956. /* NID is set in alc_build_pcms */
  1957. .ops = {
  1958. .prepare = alc_alt_capture_pcm_prepare,
  1959. .cleanup = alc_alt_capture_pcm_cleanup
  1960. },
  1961. };
  1962. static const struct hda_pcm_stream alc_pcm_digital_playback = {
  1963. .substreams = 1,
  1964. .channels_min = 2,
  1965. .channels_max = 2,
  1966. /* NID is set in alc_build_pcms */
  1967. .ops = {
  1968. .open = alc_dig_playback_pcm_open,
  1969. .close = alc_dig_playback_pcm_close,
  1970. .prepare = alc_dig_playback_pcm_prepare,
  1971. .cleanup = alc_dig_playback_pcm_cleanup
  1972. },
  1973. };
  1974. static const struct hda_pcm_stream alc_pcm_digital_capture = {
  1975. .substreams = 1,
  1976. .channels_min = 2,
  1977. .channels_max = 2,
  1978. /* NID is set in alc_build_pcms */
  1979. };
  1980. /* Used by alc_build_pcms to flag that a PCM has no playback stream */
  1981. static const struct hda_pcm_stream alc_pcm_null_stream = {
  1982. .substreams = 0,
  1983. .channels_min = 0,
  1984. .channels_max = 0,
  1985. };
  1986. static int alc_build_pcms(struct hda_codec *codec)
  1987. {
  1988. struct alc_spec *spec = codec->spec;
  1989. struct hda_pcm *info = spec->pcm_rec;
  1990. const struct hda_pcm_stream *p;
  1991. bool have_multi_adcs;
  1992. int i;
  1993. codec->num_pcms = 1;
  1994. codec->pcm_info = info;
  1995. if (spec->no_analog)
  1996. goto skip_analog;
  1997. snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
  1998. "%s Analog", codec->chip_name);
  1999. info->name = spec->stream_name_analog;
  2000. if (spec->multiout.num_dacs > 0) {
  2001. p = spec->stream_analog_playback;
  2002. if (!p)
  2003. p = &alc_pcm_analog_playback;
  2004. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2005. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  2006. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  2007. spec->multiout.max_channels;
  2008. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT &&
  2009. spec->autocfg.line_outs == 2)
  2010. info->stream[SNDRV_PCM_STREAM_PLAYBACK].chmap =
  2011. snd_pcm_2_1_chmaps;
  2012. }
  2013. if (spec->adc_nids) {
  2014. p = spec->stream_analog_capture;
  2015. if (!p) {
  2016. if (spec->dyn_adc_switch)
  2017. p = &dyn_adc_pcm_analog_capture;
  2018. else
  2019. p = &alc_pcm_analog_capture;
  2020. }
  2021. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2022. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  2023. }
  2024. if (spec->channel_mode) {
  2025. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
  2026. for (i = 0; i < spec->num_channel_mode; i++) {
  2027. if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
  2028. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
  2029. }
  2030. }
  2031. }
  2032. skip_analog:
  2033. /* SPDIF for stream index #1 */
  2034. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  2035. snprintf(spec->stream_name_digital,
  2036. sizeof(spec->stream_name_digital),
  2037. "%s Digital", codec->chip_name);
  2038. codec->num_pcms = 2;
  2039. codec->slave_dig_outs = spec->multiout.slave_dig_outs;
  2040. info = spec->pcm_rec + 1;
  2041. info->name = spec->stream_name_digital;
  2042. if (spec->dig_out_type)
  2043. info->pcm_type = spec->dig_out_type;
  2044. else
  2045. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  2046. if (spec->multiout.dig_out_nid) {
  2047. p = spec->stream_digital_playback;
  2048. if (!p)
  2049. p = &alc_pcm_digital_playback;
  2050. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2051. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  2052. }
  2053. if (spec->dig_in_nid) {
  2054. p = spec->stream_digital_capture;
  2055. if (!p)
  2056. p = &alc_pcm_digital_capture;
  2057. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2058. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  2059. }
  2060. /* FIXME: do we need this for all Realtek codec models? */
  2061. codec->spdif_status_reset = 1;
  2062. }
  2063. if (spec->no_analog)
  2064. return 0;
  2065. /* If the use of more than one ADC is requested for the current
  2066. * model, configure a second analog capture-only PCM.
  2067. */
  2068. have_multi_adcs = (spec->num_adc_nids > 1) &&
  2069. !spec->dyn_adc_switch && !spec->auto_mic &&
  2070. (!spec->input_mux || spec->input_mux->num_items > 1);
  2071. /* Additional Analaog capture for index #2 */
  2072. if (spec->alt_dac_nid || have_multi_adcs) {
  2073. codec->num_pcms = 3;
  2074. info = spec->pcm_rec + 2;
  2075. info->name = spec->stream_name_analog;
  2076. if (spec->alt_dac_nid) {
  2077. p = spec->stream_analog_alt_playback;
  2078. if (!p)
  2079. p = &alc_pcm_analog_alt_playback;
  2080. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2081. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  2082. spec->alt_dac_nid;
  2083. } else {
  2084. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  2085. alc_pcm_null_stream;
  2086. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
  2087. }
  2088. if (have_multi_adcs) {
  2089. p = spec->stream_analog_alt_capture;
  2090. if (!p)
  2091. p = &alc_pcm_analog_alt_capture;
  2092. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2093. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  2094. spec->adc_nids[1];
  2095. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  2096. spec->num_adc_nids - 1;
  2097. } else {
  2098. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  2099. alc_pcm_null_stream;
  2100. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
  2101. }
  2102. }
  2103. return 0;
  2104. }
  2105. static inline void alc_shutup(struct hda_codec *codec)
  2106. {
  2107. struct alc_spec *spec = codec->spec;
  2108. if (spec && spec->shutup)
  2109. spec->shutup(codec);
  2110. snd_hda_shutup_pins(codec);
  2111. }
  2112. static void alc_free_kctls(struct hda_codec *codec)
  2113. {
  2114. struct alc_spec *spec = codec->spec;
  2115. if (spec->kctls.list) {
  2116. struct snd_kcontrol_new *kctl = spec->kctls.list;
  2117. int i;
  2118. for (i = 0; i < spec->kctls.used; i++)
  2119. kfree(kctl[i].name);
  2120. }
  2121. snd_array_free(&spec->kctls);
  2122. }
  2123. static void alc_free_bind_ctls(struct hda_codec *codec)
  2124. {
  2125. struct alc_spec *spec = codec->spec;
  2126. if (spec->bind_ctls.list) {
  2127. struct hda_bind_ctls **ctl = spec->bind_ctls.list;
  2128. int i;
  2129. for (i = 0; i < spec->bind_ctls.used; i++)
  2130. kfree(ctl[i]);
  2131. }
  2132. snd_array_free(&spec->bind_ctls);
  2133. }
  2134. static void alc_free(struct hda_codec *codec)
  2135. {
  2136. struct alc_spec *spec = codec->spec;
  2137. if (!spec)
  2138. return;
  2139. alc_free_kctls(codec);
  2140. alc_free_bind_ctls(codec);
  2141. snd_hda_gen_free(&spec->gen);
  2142. kfree(spec);
  2143. snd_hda_detach_beep_device(codec);
  2144. }
  2145. #ifdef CONFIG_PM
  2146. static void alc_power_eapd(struct hda_codec *codec)
  2147. {
  2148. alc_auto_setup_eapd(codec, false);
  2149. }
  2150. static int alc_suspend(struct hda_codec *codec)
  2151. {
  2152. struct alc_spec *spec = codec->spec;
  2153. alc_shutup(codec);
  2154. if (spec && spec->power_hook)
  2155. spec->power_hook(codec);
  2156. return 0;
  2157. }
  2158. #endif
  2159. #ifdef CONFIG_PM
  2160. static int alc_resume(struct hda_codec *codec)
  2161. {
  2162. msleep(150); /* to avoid pop noise */
  2163. codec->patch_ops.init(codec);
  2164. snd_hda_codec_resume_amp(codec);
  2165. snd_hda_codec_resume_cache(codec);
  2166. alc_inv_dmic_sync(codec, true);
  2167. hda_call_check_power_status(codec, 0x01);
  2168. return 0;
  2169. }
  2170. #endif
  2171. /*
  2172. */
  2173. static const struct hda_codec_ops alc_patch_ops = {
  2174. .build_controls = alc_build_controls,
  2175. .build_pcms = alc_build_pcms,
  2176. .init = alc_init,
  2177. .free = alc_free,
  2178. .unsol_event = snd_hda_jack_unsol_event,
  2179. #ifdef CONFIG_PM
  2180. .resume = alc_resume,
  2181. #endif
  2182. #ifdef CONFIG_PM
  2183. .suspend = alc_suspend,
  2184. .check_power_status = alc_check_power_status,
  2185. #endif
  2186. .reboot_notify = alc_shutup,
  2187. };
  2188. /* replace the codec chip_name with the given string */
  2189. static int alc_codec_rename(struct hda_codec *codec, const char *name)
  2190. {
  2191. kfree(codec->chip_name);
  2192. codec->chip_name = kstrdup(name, GFP_KERNEL);
  2193. if (!codec->chip_name) {
  2194. alc_free(codec);
  2195. return -ENOMEM;
  2196. }
  2197. return 0;
  2198. }
  2199. /*
  2200. * Rename codecs appropriately from COEF value
  2201. */
  2202. struct alc_codec_rename_table {
  2203. unsigned int vendor_id;
  2204. unsigned short coef_mask;
  2205. unsigned short coef_bits;
  2206. const char *name;
  2207. };
  2208. static struct alc_codec_rename_table rename_tbl[] = {
  2209. { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
  2210. { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
  2211. { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
  2212. { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
  2213. { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
  2214. { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
  2215. { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
  2216. { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
  2217. { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
  2218. { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
  2219. { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
  2220. { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
  2221. { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
  2222. { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
  2223. { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
  2224. { } /* terminator */
  2225. };
  2226. static int alc_codec_rename_from_preset(struct hda_codec *codec)
  2227. {
  2228. const struct alc_codec_rename_table *p;
  2229. for (p = rename_tbl; p->vendor_id; p++) {
  2230. if (p->vendor_id != codec->vendor_id)
  2231. continue;
  2232. if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
  2233. return alc_codec_rename(codec, p->name);
  2234. }
  2235. return 0;
  2236. }
  2237. /*
  2238. * Automatic parse of I/O pins from the BIOS configuration
  2239. */
  2240. enum {
  2241. ALC_CTL_WIDGET_VOL,
  2242. ALC_CTL_WIDGET_MUTE,
  2243. ALC_CTL_BIND_MUTE,
  2244. ALC_CTL_BIND_VOL,
  2245. ALC_CTL_BIND_SW,
  2246. };
  2247. static const struct snd_kcontrol_new alc_control_templates[] = {
  2248. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2249. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2250. HDA_BIND_MUTE(NULL, 0, 0, 0),
  2251. HDA_BIND_VOL(NULL, 0),
  2252. HDA_BIND_SW(NULL, 0),
  2253. };
  2254. /* add dynamic controls */
  2255. static int add_control(struct alc_spec *spec, int type, const char *name,
  2256. int cidx, unsigned long val)
  2257. {
  2258. struct snd_kcontrol_new *knew;
  2259. knew = alc_kcontrol_new(spec, name, &alc_control_templates[type]);
  2260. if (!knew)
  2261. return -ENOMEM;
  2262. knew->index = cidx;
  2263. if (get_amp_nid_(val))
  2264. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  2265. knew->private_value = val;
  2266. return 0;
  2267. }
  2268. static int add_control_with_pfx(struct alc_spec *spec, int type,
  2269. const char *pfx, const char *dir,
  2270. const char *sfx, int cidx, unsigned long val)
  2271. {
  2272. char name[32];
  2273. snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
  2274. return add_control(spec, type, name, cidx, val);
  2275. }
  2276. #define add_pb_vol_ctrl(spec, type, pfx, val) \
  2277. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
  2278. #define add_pb_sw_ctrl(spec, type, pfx, val) \
  2279. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
  2280. #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
  2281. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
  2282. #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
  2283. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
  2284. static const char * const channel_name[4] = {
  2285. "Front", "Surround", "CLFE", "Side"
  2286. };
  2287. static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
  2288. bool can_be_master, int *index)
  2289. {
  2290. struct auto_pin_cfg *cfg = &spec->autocfg;
  2291. *index = 0;
  2292. if (cfg->line_outs == 1 && !spec->multi_ios &&
  2293. !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
  2294. return "Master";
  2295. switch (cfg->line_out_type) {
  2296. case AUTO_PIN_SPEAKER_OUT:
  2297. if (cfg->line_outs == 1)
  2298. return "Speaker";
  2299. if (cfg->line_outs == 2)
  2300. return ch ? "Bass Speaker" : "Speaker";
  2301. break;
  2302. case AUTO_PIN_HP_OUT:
  2303. /* for multi-io case, only the primary out */
  2304. if (ch && spec->multi_ios)
  2305. break;
  2306. *index = ch;
  2307. return "Headphone";
  2308. default:
  2309. if (cfg->line_outs == 1 && !spec->multi_ios)
  2310. return "PCM";
  2311. break;
  2312. }
  2313. if (ch >= ARRAY_SIZE(channel_name)) {
  2314. snd_BUG();
  2315. return "PCM";
  2316. }
  2317. return channel_name[ch];
  2318. }
  2319. #ifdef CONFIG_PM
  2320. /* add the powersave loopback-list entry */
  2321. static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
  2322. {
  2323. struct hda_amp_list *list;
  2324. if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
  2325. return;
  2326. list = spec->loopback_list + spec->num_loopbacks;
  2327. list->nid = mix;
  2328. list->dir = HDA_INPUT;
  2329. list->idx = idx;
  2330. spec->num_loopbacks++;
  2331. spec->loopback.amplist = spec->loopback_list;
  2332. }
  2333. #else
  2334. #define add_loopback_list(spec, mix, idx) /* NOP */
  2335. #endif
  2336. /* create input playback/capture controls for the given pin */
  2337. static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
  2338. const char *ctlname, int ctlidx,
  2339. int idx, hda_nid_t mix_nid)
  2340. {
  2341. int err;
  2342. err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
  2343. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2344. if (err < 0)
  2345. return err;
  2346. err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
  2347. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2348. if (err < 0)
  2349. return err;
  2350. add_loopback_list(spec, mix_nid, idx);
  2351. return 0;
  2352. }
  2353. static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
  2354. {
  2355. unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
  2356. return (pincap & AC_PINCAP_IN) != 0;
  2357. }
  2358. /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
  2359. static int alc_auto_fill_adc_caps(struct hda_codec *codec)
  2360. {
  2361. struct alc_spec *spec = codec->spec;
  2362. hda_nid_t nid;
  2363. hda_nid_t *adc_nids = spec->private_adc_nids;
  2364. hda_nid_t *cap_nids = spec->private_capsrc_nids;
  2365. int max_nums = ARRAY_SIZE(spec->private_adc_nids);
  2366. int i, nums = 0;
  2367. nid = codec->start_nid;
  2368. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2369. hda_nid_t src;
  2370. unsigned int caps = get_wcaps(codec, nid);
  2371. int type = get_wcaps_type(caps);
  2372. if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
  2373. continue;
  2374. adc_nids[nums] = nid;
  2375. cap_nids[nums] = nid;
  2376. src = nid;
  2377. for (;;) {
  2378. int n;
  2379. type = get_wcaps_type(get_wcaps(codec, src));
  2380. if (type == AC_WID_PIN)
  2381. break;
  2382. if (type == AC_WID_AUD_SEL) {
  2383. cap_nids[nums] = src;
  2384. break;
  2385. }
  2386. n = snd_hda_get_num_conns(codec, src);
  2387. if (n > 1) {
  2388. cap_nids[nums] = src;
  2389. break;
  2390. } else if (n != 1)
  2391. break;
  2392. if (snd_hda_get_connections(codec, src, &src, 1) != 1)
  2393. break;
  2394. }
  2395. if (++nums >= max_nums)
  2396. break;
  2397. }
  2398. spec->adc_nids = spec->private_adc_nids;
  2399. spec->capsrc_nids = spec->private_capsrc_nids;
  2400. spec->num_adc_nids = nums;
  2401. return nums;
  2402. }
  2403. /* create playback/capture controls for input pins */
  2404. static int alc_auto_create_input_ctls(struct hda_codec *codec)
  2405. {
  2406. struct alc_spec *spec = codec->spec;
  2407. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2408. hda_nid_t mixer = spec->mixer_nid;
  2409. struct hda_input_mux *imux = &spec->private_imux[0];
  2410. int num_adcs;
  2411. int i, c, err, idx, type_idx = 0;
  2412. const char *prev_label = NULL;
  2413. num_adcs = alc_auto_fill_adc_caps(codec);
  2414. if (num_adcs < 0)
  2415. return 0;
  2416. for (i = 0; i < cfg->num_inputs; i++) {
  2417. hda_nid_t pin;
  2418. const char *label;
  2419. pin = cfg->inputs[i].pin;
  2420. if (!alc_is_input_pin(codec, pin))
  2421. continue;
  2422. label = hda_get_autocfg_input_label(codec, cfg, i);
  2423. if (spec->shared_mic_hp && !strcmp(label, "Misc"))
  2424. label = "Headphone Mic";
  2425. if (prev_label && !strcmp(label, prev_label))
  2426. type_idx++;
  2427. else
  2428. type_idx = 0;
  2429. prev_label = label;
  2430. if (mixer) {
  2431. idx = get_connection_index(codec, mixer, pin);
  2432. if (idx >= 0) {
  2433. err = new_analog_input(spec, pin,
  2434. label, type_idx,
  2435. idx, mixer);
  2436. if (err < 0)
  2437. return err;
  2438. }
  2439. }
  2440. for (c = 0; c < num_adcs; c++) {
  2441. hda_nid_t cap = get_capsrc(spec, c);
  2442. idx = get_connection_index(codec, cap, pin);
  2443. if (idx >= 0) {
  2444. spec->imux_pins[imux->num_items] = pin;
  2445. snd_hda_add_imux_item(imux, label, idx, NULL);
  2446. break;
  2447. }
  2448. }
  2449. }
  2450. spec->num_mux_defs = 1;
  2451. spec->input_mux = imux;
  2452. return 0;
  2453. }
  2454. /* create a shared input with the headphone out */
  2455. static int alc_auto_create_shared_input(struct hda_codec *codec)
  2456. {
  2457. struct alc_spec *spec = codec->spec;
  2458. struct auto_pin_cfg *cfg = &spec->autocfg;
  2459. unsigned int defcfg;
  2460. hda_nid_t nid;
  2461. /* only one internal input pin? */
  2462. if (cfg->num_inputs != 1)
  2463. return 0;
  2464. defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
  2465. if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
  2466. return 0;
  2467. if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
  2468. nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
  2469. else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
  2470. nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
  2471. else
  2472. return 0; /* both not available */
  2473. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
  2474. return 0; /* no input */
  2475. cfg->inputs[1].pin = nid;
  2476. cfg->inputs[1].type = AUTO_PIN_MIC;
  2477. cfg->num_inputs = 2;
  2478. spec->shared_mic_hp = 1;
  2479. snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
  2480. return 0;
  2481. }
  2482. static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
  2483. unsigned int pin_type)
  2484. {
  2485. snd_hda_set_pin_ctl(codec, nid, pin_type);
  2486. /* unmute pin */
  2487. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  2488. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2489. AMP_OUT_UNMUTE);
  2490. }
  2491. static int get_pin_type(int line_out_type)
  2492. {
  2493. if (line_out_type == AUTO_PIN_HP_OUT)
  2494. return PIN_HP;
  2495. else
  2496. return PIN_OUT;
  2497. }
  2498. static void alc_auto_init_analog_input(struct hda_codec *codec)
  2499. {
  2500. struct alc_spec *spec = codec->spec;
  2501. struct auto_pin_cfg *cfg = &spec->autocfg;
  2502. int i;
  2503. for (i = 0; i < cfg->num_inputs; i++) {
  2504. hda_nid_t nid = cfg->inputs[i].pin;
  2505. if (alc_is_input_pin(codec, nid)) {
  2506. alc_set_input_pin(codec, nid, cfg->inputs[i].type);
  2507. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  2508. snd_hda_codec_write(codec, nid, 0,
  2509. AC_VERB_SET_AMP_GAIN_MUTE,
  2510. AMP_OUT_MUTE);
  2511. }
  2512. }
  2513. /* mute all loopback inputs */
  2514. if (spec->mixer_nid) {
  2515. int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
  2516. for (i = 0; i < nums; i++)
  2517. snd_hda_codec_write(codec, spec->mixer_nid, 0,
  2518. AC_VERB_SET_AMP_GAIN_MUTE,
  2519. AMP_IN_MUTE(i));
  2520. }
  2521. }
  2522. /* convert from MIX nid to DAC */
  2523. static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
  2524. {
  2525. hda_nid_t list[5];
  2526. int i, num;
  2527. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
  2528. return nid;
  2529. num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
  2530. for (i = 0; i < num; i++) {
  2531. if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
  2532. return list[i];
  2533. }
  2534. return 0;
  2535. }
  2536. /* go down to the selector widget before the mixer */
  2537. static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
  2538. {
  2539. hda_nid_t srcs[5];
  2540. int num = snd_hda_get_connections(codec, pin, srcs,
  2541. ARRAY_SIZE(srcs));
  2542. if (num != 1 ||
  2543. get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
  2544. return pin;
  2545. return srcs[0];
  2546. }
  2547. /* get MIX nid connected to the given pin targeted to DAC */
  2548. static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
  2549. hda_nid_t dac)
  2550. {
  2551. hda_nid_t mix[5];
  2552. int i, num;
  2553. pin = alc_go_down_to_selector(codec, pin);
  2554. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2555. for (i = 0; i < num; i++) {
  2556. if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
  2557. return mix[i];
  2558. }
  2559. return 0;
  2560. }
  2561. /* select the connection from pin to DAC if needed */
  2562. static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
  2563. hda_nid_t dac)
  2564. {
  2565. hda_nid_t mix[5];
  2566. int i, num;
  2567. pin = alc_go_down_to_selector(codec, pin);
  2568. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2569. if (num < 2)
  2570. return 0;
  2571. for (i = 0; i < num; i++) {
  2572. if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
  2573. snd_hda_codec_update_cache(codec, pin, 0,
  2574. AC_VERB_SET_CONNECT_SEL, i);
  2575. return 0;
  2576. }
  2577. }
  2578. return 0;
  2579. }
  2580. static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
  2581. {
  2582. struct alc_spec *spec = codec->spec;
  2583. int i;
  2584. if (found_in_nid_list(nid, spec->multiout.dac_nids,
  2585. ARRAY_SIZE(spec->private_dac_nids)) ||
  2586. found_in_nid_list(nid, spec->multiout.hp_out_nid,
  2587. ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
  2588. found_in_nid_list(nid, spec->multiout.extra_out_nid,
  2589. ARRAY_SIZE(spec->multiout.extra_out_nid)))
  2590. return true;
  2591. for (i = 0; i < spec->multi_ios; i++) {
  2592. if (spec->multi_io[i].dac == nid)
  2593. return true;
  2594. }
  2595. return false;
  2596. }
  2597. /* look for an empty DAC slot */
  2598. static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
  2599. {
  2600. hda_nid_t srcs[5];
  2601. int i, num;
  2602. pin = alc_go_down_to_selector(codec, pin);
  2603. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2604. for (i = 0; i < num; i++) {
  2605. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2606. if (!nid)
  2607. continue;
  2608. if (!alc_is_dac_already_used(codec, nid))
  2609. return nid;
  2610. }
  2611. return 0;
  2612. }
  2613. /* check whether the DAC is reachable from the pin */
  2614. static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
  2615. hda_nid_t pin, hda_nid_t dac)
  2616. {
  2617. hda_nid_t srcs[5];
  2618. int i, num;
  2619. if (!pin || !dac)
  2620. return false;
  2621. pin = alc_go_down_to_selector(codec, pin);
  2622. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2623. for (i = 0; i < num; i++) {
  2624. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2625. if (nid == dac)
  2626. return true;
  2627. }
  2628. return false;
  2629. }
  2630. static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
  2631. {
  2632. struct alc_spec *spec = codec->spec;
  2633. hda_nid_t sel = alc_go_down_to_selector(codec, pin);
  2634. hda_nid_t nid, nid_found, srcs[5];
  2635. int i, num = snd_hda_get_connections(codec, sel, srcs,
  2636. ARRAY_SIZE(srcs));
  2637. if (num == 1)
  2638. return alc_auto_look_for_dac(codec, pin);
  2639. nid_found = 0;
  2640. for (i = 0; i < num; i++) {
  2641. if (srcs[i] == spec->mixer_nid)
  2642. continue;
  2643. nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2644. if (nid && !alc_is_dac_already_used(codec, nid)) {
  2645. if (nid_found)
  2646. return 0;
  2647. nid_found = nid;
  2648. }
  2649. }
  2650. return nid_found;
  2651. }
  2652. /* mark up volume and mute control NIDs: used during badness parsing and
  2653. * at creating actual controls
  2654. */
  2655. static inline unsigned int get_ctl_pos(unsigned int data)
  2656. {
  2657. hda_nid_t nid = get_amp_nid_(data);
  2658. unsigned int dir;
  2659. if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
  2660. return 0;
  2661. dir = get_amp_direction_(data);
  2662. return (nid << 1) | dir;
  2663. }
  2664. #define is_ctl_used(bits, data) \
  2665. test_bit(get_ctl_pos(data), bits)
  2666. #define mark_ctl_usage(bits, data) \
  2667. set_bit(get_ctl_pos(data), bits)
  2668. static void clear_vol_marks(struct hda_codec *codec)
  2669. {
  2670. struct alc_spec *spec = codec->spec;
  2671. memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
  2672. memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
  2673. }
  2674. /* badness definition */
  2675. enum {
  2676. /* No primary DAC is found for the main output */
  2677. BAD_NO_PRIMARY_DAC = 0x10000,
  2678. /* No DAC is found for the extra output */
  2679. BAD_NO_DAC = 0x4000,
  2680. /* No possible multi-ios */
  2681. BAD_MULTI_IO = 0x103,
  2682. /* No individual DAC for extra output */
  2683. BAD_NO_EXTRA_DAC = 0x102,
  2684. /* No individual DAC for extra surrounds */
  2685. BAD_NO_EXTRA_SURR_DAC = 0x101,
  2686. /* Primary DAC shared with main surrounds */
  2687. BAD_SHARED_SURROUND = 0x100,
  2688. /* Primary DAC shared with main CLFE */
  2689. BAD_SHARED_CLFE = 0x10,
  2690. /* Primary DAC shared with extra surrounds */
  2691. BAD_SHARED_EXTRA_SURROUND = 0x10,
  2692. /* Volume widget is shared */
  2693. BAD_SHARED_VOL = 0x10,
  2694. };
  2695. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  2696. hda_nid_t pin, hda_nid_t dac);
  2697. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  2698. hda_nid_t pin, hda_nid_t dac);
  2699. static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
  2700. hda_nid_t dac)
  2701. {
  2702. struct alc_spec *spec = codec->spec;
  2703. hda_nid_t nid;
  2704. unsigned int val;
  2705. int badness = 0;
  2706. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  2707. if (nid) {
  2708. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2709. if (is_ctl_used(spec->vol_ctls, nid))
  2710. badness += BAD_SHARED_VOL;
  2711. else
  2712. mark_ctl_usage(spec->vol_ctls, val);
  2713. } else
  2714. badness += BAD_SHARED_VOL;
  2715. nid = alc_look_for_out_mute_nid(codec, pin, dac);
  2716. if (nid) {
  2717. unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
  2718. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
  2719. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2720. else
  2721. val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
  2722. if (is_ctl_used(spec->sw_ctls, val))
  2723. badness += BAD_SHARED_VOL;
  2724. else
  2725. mark_ctl_usage(spec->sw_ctls, val);
  2726. } else
  2727. badness += BAD_SHARED_VOL;
  2728. return badness;
  2729. }
  2730. struct badness_table {
  2731. int no_primary_dac; /* no primary DAC */
  2732. int no_dac; /* no secondary DACs */
  2733. int shared_primary; /* primary DAC is shared with main output */
  2734. int shared_surr; /* secondary DAC shared with main or primary */
  2735. int shared_clfe; /* third DAC shared with main or primary */
  2736. int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
  2737. };
  2738. static struct badness_table main_out_badness = {
  2739. .no_primary_dac = BAD_NO_PRIMARY_DAC,
  2740. .no_dac = BAD_NO_DAC,
  2741. .shared_primary = BAD_NO_PRIMARY_DAC,
  2742. .shared_surr = BAD_SHARED_SURROUND,
  2743. .shared_clfe = BAD_SHARED_CLFE,
  2744. .shared_surr_main = BAD_SHARED_SURROUND,
  2745. };
  2746. static struct badness_table extra_out_badness = {
  2747. .no_primary_dac = BAD_NO_DAC,
  2748. .no_dac = BAD_NO_DAC,
  2749. .shared_primary = BAD_NO_EXTRA_DAC,
  2750. .shared_surr = BAD_SHARED_EXTRA_SURROUND,
  2751. .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
  2752. .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
  2753. };
  2754. /* try to assign DACs to pins and return the resultant badness */
  2755. static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
  2756. const hda_nid_t *pins, hda_nid_t *dacs,
  2757. const struct badness_table *bad)
  2758. {
  2759. struct alc_spec *spec = codec->spec;
  2760. struct auto_pin_cfg *cfg = &spec->autocfg;
  2761. int i, j;
  2762. int badness = 0;
  2763. hda_nid_t dac;
  2764. if (!num_outs)
  2765. return 0;
  2766. for (i = 0; i < num_outs; i++) {
  2767. hda_nid_t pin = pins[i];
  2768. if (!dacs[i])
  2769. dacs[i] = alc_auto_look_for_dac(codec, pin);
  2770. if (!dacs[i] && !i) {
  2771. for (j = 1; j < num_outs; j++) {
  2772. if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
  2773. dacs[0] = dacs[j];
  2774. dacs[j] = 0;
  2775. break;
  2776. }
  2777. }
  2778. }
  2779. dac = dacs[i];
  2780. if (!dac) {
  2781. if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
  2782. dac = dacs[0];
  2783. else if (cfg->line_outs > i &&
  2784. alc_auto_is_dac_reachable(codec, pin,
  2785. spec->private_dac_nids[i]))
  2786. dac = spec->private_dac_nids[i];
  2787. if (dac) {
  2788. if (!i)
  2789. badness += bad->shared_primary;
  2790. else if (i == 1)
  2791. badness += bad->shared_surr;
  2792. else
  2793. badness += bad->shared_clfe;
  2794. } else if (alc_auto_is_dac_reachable(codec, pin,
  2795. spec->private_dac_nids[0])) {
  2796. dac = spec->private_dac_nids[0];
  2797. badness += bad->shared_surr_main;
  2798. } else if (!i)
  2799. badness += bad->no_primary_dac;
  2800. else
  2801. badness += bad->no_dac;
  2802. }
  2803. if (dac)
  2804. badness += eval_shared_vol_badness(codec, pin, dac);
  2805. }
  2806. return badness;
  2807. }
  2808. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  2809. hda_nid_t reference_pin,
  2810. bool hardwired, int offset);
  2811. static bool alc_map_singles(struct hda_codec *codec, int outs,
  2812. const hda_nid_t *pins, hda_nid_t *dacs)
  2813. {
  2814. int i;
  2815. bool found = false;
  2816. for (i = 0; i < outs; i++) {
  2817. if (dacs[i])
  2818. continue;
  2819. dacs[i] = get_dac_if_single(codec, pins[i]);
  2820. if (dacs[i])
  2821. found = true;
  2822. }
  2823. return found;
  2824. }
  2825. /* fill in the dac_nids table from the parsed pin configuration */
  2826. static int fill_and_eval_dacs(struct hda_codec *codec,
  2827. bool fill_hardwired,
  2828. bool fill_mio_first)
  2829. {
  2830. struct alc_spec *spec = codec->spec;
  2831. struct auto_pin_cfg *cfg = &spec->autocfg;
  2832. int i, err, badness;
  2833. /* set num_dacs once to full for alc_auto_look_for_dac() */
  2834. spec->multiout.num_dacs = cfg->line_outs;
  2835. spec->multiout.dac_nids = spec->private_dac_nids;
  2836. memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
  2837. memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
  2838. memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
  2839. spec->multi_ios = 0;
  2840. clear_vol_marks(codec);
  2841. badness = 0;
  2842. /* fill hard-wired DACs first */
  2843. if (fill_hardwired) {
  2844. bool mapped;
  2845. do {
  2846. mapped = alc_map_singles(codec, cfg->line_outs,
  2847. cfg->line_out_pins,
  2848. spec->private_dac_nids);
  2849. mapped |= alc_map_singles(codec, cfg->hp_outs,
  2850. cfg->hp_pins,
  2851. spec->multiout.hp_out_nid);
  2852. mapped |= alc_map_singles(codec, cfg->speaker_outs,
  2853. cfg->speaker_pins,
  2854. spec->multiout.extra_out_nid);
  2855. if (fill_mio_first && cfg->line_outs == 1 &&
  2856. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2857. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
  2858. if (!err)
  2859. mapped = true;
  2860. }
  2861. } while (mapped);
  2862. }
  2863. badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
  2864. spec->private_dac_nids,
  2865. &main_out_badness);
  2866. /* re-count num_dacs and squash invalid entries */
  2867. spec->multiout.num_dacs = 0;
  2868. for (i = 0; i < cfg->line_outs; i++) {
  2869. if (spec->private_dac_nids[i])
  2870. spec->multiout.num_dacs++;
  2871. else {
  2872. memmove(spec->private_dac_nids + i,
  2873. spec->private_dac_nids + i + 1,
  2874. sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
  2875. spec->private_dac_nids[cfg->line_outs - 1] = 0;
  2876. }
  2877. }
  2878. if (fill_mio_first &&
  2879. cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2880. /* try to fill multi-io first */
  2881. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
  2882. if (err < 0)
  2883. return err;
  2884. /* we don't count badness at this stage yet */
  2885. }
  2886. if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
  2887. err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
  2888. spec->multiout.hp_out_nid,
  2889. &extra_out_badness);
  2890. if (err < 0)
  2891. return err;
  2892. badness += err;
  2893. }
  2894. if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2895. err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
  2896. cfg->speaker_pins,
  2897. spec->multiout.extra_out_nid,
  2898. &extra_out_badness);
  2899. if (err < 0)
  2900. return err;
  2901. badness += err;
  2902. }
  2903. if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
  2904. err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
  2905. if (err < 0)
  2906. return err;
  2907. badness += err;
  2908. }
  2909. if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  2910. /* try multi-ios with HP + inputs */
  2911. int offset = 0;
  2912. if (cfg->line_outs >= 3)
  2913. offset = 1;
  2914. err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
  2915. offset);
  2916. if (err < 0)
  2917. return err;
  2918. badness += err;
  2919. }
  2920. if (spec->multi_ios == 2) {
  2921. for (i = 0; i < 2; i++)
  2922. spec->private_dac_nids[spec->multiout.num_dacs++] =
  2923. spec->multi_io[i].dac;
  2924. spec->ext_channel_count = 2;
  2925. } else if (spec->multi_ios) {
  2926. spec->multi_ios = 0;
  2927. badness += BAD_MULTI_IO;
  2928. }
  2929. return badness;
  2930. }
  2931. #define DEBUG_BADNESS
  2932. #ifdef DEBUG_BADNESS
  2933. #define debug_badness snd_printdd
  2934. #else
  2935. #define debug_badness(...)
  2936. #endif
  2937. static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
  2938. {
  2939. debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2940. cfg->line_out_pins[0], cfg->line_out_pins[1],
  2941. cfg->line_out_pins[2], cfg->line_out_pins[2],
  2942. spec->multiout.dac_nids[0],
  2943. spec->multiout.dac_nids[1],
  2944. spec->multiout.dac_nids[2],
  2945. spec->multiout.dac_nids[3]);
  2946. if (spec->multi_ios > 0)
  2947. debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
  2948. spec->multi_ios,
  2949. spec->multi_io[0].pin, spec->multi_io[1].pin,
  2950. spec->multi_io[0].dac, spec->multi_io[1].dac);
  2951. debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2952. cfg->hp_pins[0], cfg->hp_pins[1],
  2953. cfg->hp_pins[2], cfg->hp_pins[2],
  2954. spec->multiout.hp_out_nid[0],
  2955. spec->multiout.hp_out_nid[1],
  2956. spec->multiout.hp_out_nid[2],
  2957. spec->multiout.hp_out_nid[3]);
  2958. debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
  2959. cfg->speaker_pins[0], cfg->speaker_pins[1],
  2960. cfg->speaker_pins[2], cfg->speaker_pins[3],
  2961. spec->multiout.extra_out_nid[0],
  2962. spec->multiout.extra_out_nid[1],
  2963. spec->multiout.extra_out_nid[2],
  2964. spec->multiout.extra_out_nid[3]);
  2965. }
  2966. static int alc_auto_fill_dac_nids(struct hda_codec *codec)
  2967. {
  2968. struct alc_spec *spec = codec->spec;
  2969. struct auto_pin_cfg *cfg = &spec->autocfg;
  2970. struct auto_pin_cfg *best_cfg;
  2971. int best_badness = INT_MAX;
  2972. int badness;
  2973. bool fill_hardwired = true, fill_mio_first = true;
  2974. bool best_wired = true, best_mio = true;
  2975. bool hp_spk_swapped = false;
  2976. best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
  2977. if (!best_cfg)
  2978. return -ENOMEM;
  2979. *best_cfg = *cfg;
  2980. for (;;) {
  2981. badness = fill_and_eval_dacs(codec, fill_hardwired,
  2982. fill_mio_first);
  2983. if (badness < 0) {
  2984. kfree(best_cfg);
  2985. return badness;
  2986. }
  2987. debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
  2988. cfg->line_out_type, fill_hardwired, fill_mio_first,
  2989. badness);
  2990. debug_show_configs(spec, cfg);
  2991. if (badness < best_badness) {
  2992. best_badness = badness;
  2993. *best_cfg = *cfg;
  2994. best_wired = fill_hardwired;
  2995. best_mio = fill_mio_first;
  2996. }
  2997. if (!badness)
  2998. break;
  2999. fill_mio_first = !fill_mio_first;
  3000. if (!fill_mio_first)
  3001. continue;
  3002. fill_hardwired = !fill_hardwired;
  3003. if (!fill_hardwired)
  3004. continue;
  3005. if (hp_spk_swapped)
  3006. break;
  3007. hp_spk_swapped = true;
  3008. if (cfg->speaker_outs > 0 &&
  3009. cfg->line_out_type == AUTO_PIN_HP_OUT) {
  3010. cfg->hp_outs = cfg->line_outs;
  3011. memcpy(cfg->hp_pins, cfg->line_out_pins,
  3012. sizeof(cfg->hp_pins));
  3013. cfg->line_outs = cfg->speaker_outs;
  3014. memcpy(cfg->line_out_pins, cfg->speaker_pins,
  3015. sizeof(cfg->speaker_pins));
  3016. cfg->speaker_outs = 0;
  3017. memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
  3018. cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
  3019. fill_hardwired = true;
  3020. continue;
  3021. }
  3022. if (cfg->hp_outs > 0 &&
  3023. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  3024. cfg->speaker_outs = cfg->line_outs;
  3025. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  3026. sizeof(cfg->speaker_pins));
  3027. cfg->line_outs = cfg->hp_outs;
  3028. memcpy(cfg->line_out_pins, cfg->hp_pins,
  3029. sizeof(cfg->hp_pins));
  3030. cfg->hp_outs = 0;
  3031. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  3032. cfg->line_out_type = AUTO_PIN_HP_OUT;
  3033. fill_hardwired = true;
  3034. continue;
  3035. }
  3036. break;
  3037. }
  3038. if (badness) {
  3039. *cfg = *best_cfg;
  3040. fill_and_eval_dacs(codec, best_wired, best_mio);
  3041. }
  3042. debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
  3043. cfg->line_out_type, best_wired, best_mio);
  3044. debug_show_configs(spec, cfg);
  3045. if (cfg->line_out_pins[0])
  3046. spec->vmaster_nid =
  3047. alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
  3048. spec->multiout.dac_nids[0]);
  3049. /* clear the bitmap flags for creating controls */
  3050. clear_vol_marks(codec);
  3051. kfree(best_cfg);
  3052. return 0;
  3053. }
  3054. static int alc_auto_add_vol_ctl(struct hda_codec *codec,
  3055. const char *pfx, int cidx,
  3056. hda_nid_t nid, unsigned int chs)
  3057. {
  3058. struct alc_spec *spec = codec->spec;
  3059. unsigned int val;
  3060. if (!nid)
  3061. return 0;
  3062. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  3063. if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
  3064. return 0;
  3065. mark_ctl_usage(spec->vol_ctls, val);
  3066. return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
  3067. val);
  3068. }
  3069. static int alc_auto_add_stereo_vol(struct hda_codec *codec,
  3070. const char *pfx, int cidx,
  3071. hda_nid_t nid)
  3072. {
  3073. int chs = 1;
  3074. if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
  3075. chs = 3;
  3076. return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
  3077. }
  3078. /* create a mute-switch for the given mixer widget;
  3079. * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
  3080. */
  3081. static int alc_auto_add_sw_ctl(struct hda_codec *codec,
  3082. const char *pfx, int cidx,
  3083. hda_nid_t nid, unsigned int chs)
  3084. {
  3085. struct alc_spec *spec = codec->spec;
  3086. int wid_type;
  3087. int type;
  3088. unsigned long val;
  3089. if (!nid)
  3090. return 0;
  3091. wid_type = get_wcaps_type(get_wcaps(codec, nid));
  3092. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
  3093. type = ALC_CTL_WIDGET_MUTE;
  3094. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  3095. } else if (snd_hda_get_num_conns(codec, nid) == 1) {
  3096. type = ALC_CTL_WIDGET_MUTE;
  3097. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
  3098. } else {
  3099. type = ALC_CTL_BIND_MUTE;
  3100. val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
  3101. }
  3102. if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
  3103. return 0;
  3104. mark_ctl_usage(spec->sw_ctls, val);
  3105. return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
  3106. }
  3107. static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
  3108. int cidx, hda_nid_t nid)
  3109. {
  3110. int chs = 1;
  3111. if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
  3112. chs = 3;
  3113. return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
  3114. }
  3115. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  3116. hda_nid_t pin, hda_nid_t dac)
  3117. {
  3118. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  3119. if (nid_has_mute(codec, pin, HDA_OUTPUT))
  3120. return pin;
  3121. else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
  3122. return mix;
  3123. else if (nid_has_mute(codec, dac, HDA_OUTPUT))
  3124. return dac;
  3125. return 0;
  3126. }
  3127. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  3128. hda_nid_t pin, hda_nid_t dac)
  3129. {
  3130. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  3131. if (nid_has_volume(codec, dac, HDA_OUTPUT))
  3132. return dac;
  3133. else if (nid_has_volume(codec, mix, HDA_OUTPUT))
  3134. return mix;
  3135. else if (nid_has_volume(codec, pin, HDA_OUTPUT))
  3136. return pin;
  3137. return 0;
  3138. }
  3139. /* add playback controls from the parsed DAC table */
  3140. static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
  3141. const struct auto_pin_cfg *cfg)
  3142. {
  3143. struct alc_spec *spec = codec->spec;
  3144. int i, err, noutputs;
  3145. noutputs = cfg->line_outs;
  3146. if (spec->multi_ios > 0 && cfg->line_outs < 3)
  3147. noutputs += spec->multi_ios;
  3148. for (i = 0; i < noutputs; i++) {
  3149. const char *name;
  3150. int index;
  3151. hda_nid_t dac, pin;
  3152. hda_nid_t sw, vol;
  3153. dac = spec->multiout.dac_nids[i];
  3154. if (!dac)
  3155. continue;
  3156. if (i >= cfg->line_outs) {
  3157. pin = spec->multi_io[i - 1].pin;
  3158. index = 0;
  3159. name = channel_name[i];
  3160. } else {
  3161. pin = cfg->line_out_pins[i];
  3162. name = alc_get_line_out_pfx(spec, i, true, &index);
  3163. }
  3164. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  3165. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  3166. if (!name || !strcmp(name, "CLFE")) {
  3167. /* Center/LFE */
  3168. err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
  3169. if (err < 0)
  3170. return err;
  3171. err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
  3172. if (err < 0)
  3173. return err;
  3174. err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
  3175. if (err < 0)
  3176. return err;
  3177. err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
  3178. if (err < 0)
  3179. return err;
  3180. } else {
  3181. err = alc_auto_add_stereo_vol(codec, name, index, vol);
  3182. if (err < 0)
  3183. return err;
  3184. err = alc_auto_add_stereo_sw(codec, name, index, sw);
  3185. if (err < 0)
  3186. return err;
  3187. }
  3188. }
  3189. return 0;
  3190. }
  3191. static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  3192. hda_nid_t dac, const char *pfx,
  3193. int cidx)
  3194. {
  3195. struct alc_spec *spec = codec->spec;
  3196. hda_nid_t sw, vol;
  3197. int err;
  3198. if (!dac) {
  3199. unsigned int val;
  3200. /* the corresponding DAC is already occupied */
  3201. if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
  3202. return 0; /* no way */
  3203. /* create a switch only */
  3204. val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
  3205. if (is_ctl_used(spec->sw_ctls, val))
  3206. return 0; /* already created */
  3207. mark_ctl_usage(spec->sw_ctls, val);
  3208. return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
  3209. }
  3210. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  3211. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  3212. err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
  3213. if (err < 0)
  3214. return err;
  3215. err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
  3216. if (err < 0)
  3217. return err;
  3218. return 0;
  3219. }
  3220. static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
  3221. unsigned int nums,
  3222. struct hda_ctl_ops *ops)
  3223. {
  3224. struct alc_spec *spec = codec->spec;
  3225. struct hda_bind_ctls **ctlp, *ctl;
  3226. ctlp = snd_array_new(&spec->bind_ctls);
  3227. if (!ctlp)
  3228. return NULL;
  3229. ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
  3230. *ctlp = ctl;
  3231. if (ctl)
  3232. ctl->ops = ops;
  3233. return ctl;
  3234. }
  3235. /* add playback controls for speaker and HP outputs */
  3236. static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
  3237. const hda_nid_t *pins,
  3238. const hda_nid_t *dacs,
  3239. const char *pfx)
  3240. {
  3241. struct alc_spec *spec = codec->spec;
  3242. struct hda_bind_ctls *ctl;
  3243. char name[32];
  3244. int i, n, err;
  3245. if (!num_pins || !pins[0])
  3246. return 0;
  3247. if (num_pins == 1) {
  3248. hda_nid_t dac = *dacs;
  3249. if (!dac)
  3250. dac = spec->multiout.dac_nids[0];
  3251. return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
  3252. }
  3253. for (i = 0; i < num_pins; i++) {
  3254. hda_nid_t dac;
  3255. if (dacs[num_pins - 1])
  3256. dac = dacs[i]; /* with individual volumes */
  3257. else
  3258. dac = 0;
  3259. if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
  3260. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3261. "Bass Speaker", 0);
  3262. } else if (num_pins >= 3) {
  3263. snprintf(name, sizeof(name), "%s %s",
  3264. pfx, channel_name[i]);
  3265. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3266. name, 0);
  3267. } else {
  3268. err = alc_auto_create_extra_out(codec, pins[i], dac,
  3269. pfx, i);
  3270. }
  3271. if (err < 0)
  3272. return err;
  3273. }
  3274. if (dacs[num_pins - 1])
  3275. return 0;
  3276. /* Let's create a bind-controls for volumes */
  3277. ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
  3278. if (!ctl)
  3279. return -ENOMEM;
  3280. n = 0;
  3281. for (i = 0; i < num_pins; i++) {
  3282. hda_nid_t vol;
  3283. if (!pins[i] || !dacs[i])
  3284. continue;
  3285. vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
  3286. if (vol)
  3287. ctl->values[n++] =
  3288. HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
  3289. }
  3290. if (n) {
  3291. snprintf(name, sizeof(name), "%s Playback Volume", pfx);
  3292. err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
  3293. if (err < 0)
  3294. return err;
  3295. }
  3296. return 0;
  3297. }
  3298. static int alc_auto_create_hp_out(struct hda_codec *codec)
  3299. {
  3300. struct alc_spec *spec = codec->spec;
  3301. return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
  3302. spec->autocfg.hp_pins,
  3303. spec->multiout.hp_out_nid,
  3304. "Headphone");
  3305. }
  3306. static int alc_auto_create_speaker_out(struct hda_codec *codec)
  3307. {
  3308. struct alc_spec *spec = codec->spec;
  3309. return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
  3310. spec->autocfg.speaker_pins,
  3311. spec->multiout.extra_out_nid,
  3312. "Speaker");
  3313. }
  3314. static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
  3315. hda_nid_t pin, int pin_type,
  3316. hda_nid_t dac)
  3317. {
  3318. int i, num;
  3319. hda_nid_t nid, mix = 0;
  3320. hda_nid_t srcs[HDA_MAX_CONNECTIONS];
  3321. alc_set_pin_output(codec, pin, pin_type);
  3322. nid = alc_go_down_to_selector(codec, pin);
  3323. num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
  3324. for (i = 0; i < num; i++) {
  3325. if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
  3326. continue;
  3327. mix = srcs[i];
  3328. break;
  3329. }
  3330. if (!mix)
  3331. return;
  3332. /* need the manual connection? */
  3333. if (num > 1)
  3334. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
  3335. /* unmute mixer widget inputs */
  3336. if (nid_has_mute(codec, mix, HDA_INPUT)) {
  3337. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3338. AMP_IN_UNMUTE(0));
  3339. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3340. AMP_IN_UNMUTE(1));
  3341. }
  3342. /* initialize volume */
  3343. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  3344. if (nid)
  3345. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3346. AMP_OUT_ZERO);
  3347. /* unmute DAC if it's not assigned to a mixer */
  3348. nid = alc_look_for_out_mute_nid(codec, pin, dac);
  3349. if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
  3350. snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3351. AMP_OUT_ZERO);
  3352. }
  3353. static void alc_auto_init_multi_out(struct hda_codec *codec)
  3354. {
  3355. struct alc_spec *spec = codec->spec;
  3356. int pin_type = get_pin_type(spec->autocfg.line_out_type);
  3357. int i;
  3358. for (i = 0; i <= HDA_SIDE; i++) {
  3359. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  3360. if (nid)
  3361. alc_auto_set_output_and_unmute(codec, nid, pin_type,
  3362. spec->multiout.dac_nids[i]);
  3363. }
  3364. }
  3365. static void alc_auto_init_extra_out(struct hda_codec *codec)
  3366. {
  3367. struct alc_spec *spec = codec->spec;
  3368. int i;
  3369. hda_nid_t pin, dac;
  3370. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  3371. if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
  3372. break;
  3373. pin = spec->autocfg.hp_pins[i];
  3374. if (!pin)
  3375. break;
  3376. dac = spec->multiout.hp_out_nid[i];
  3377. if (!dac) {
  3378. if (i > 0 && spec->multiout.hp_out_nid[0])
  3379. dac = spec->multiout.hp_out_nid[0];
  3380. else
  3381. dac = spec->multiout.dac_nids[0];
  3382. }
  3383. alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
  3384. }
  3385. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  3386. if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
  3387. break;
  3388. pin = spec->autocfg.speaker_pins[i];
  3389. if (!pin)
  3390. break;
  3391. dac = spec->multiout.extra_out_nid[i];
  3392. if (!dac) {
  3393. if (i > 0 && spec->multiout.extra_out_nid[0])
  3394. dac = spec->multiout.extra_out_nid[0];
  3395. else
  3396. dac = spec->multiout.dac_nids[0];
  3397. }
  3398. alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
  3399. }
  3400. }
  3401. /* check whether the given pin can be a multi-io pin */
  3402. static bool can_be_multiio_pin(struct hda_codec *codec,
  3403. unsigned int location, hda_nid_t nid)
  3404. {
  3405. unsigned int defcfg, caps;
  3406. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  3407. if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
  3408. return false;
  3409. if (location && get_defcfg_location(defcfg) != location)
  3410. return false;
  3411. caps = snd_hda_query_pin_caps(codec, nid);
  3412. if (!(caps & AC_PINCAP_OUT))
  3413. return false;
  3414. return true;
  3415. }
  3416. /*
  3417. * multi-io helper
  3418. *
  3419. * When hardwired is set, try to fill ony hardwired pins, and returns
  3420. * zero if any pins are filled, non-zero if nothing found.
  3421. * When hardwired is off, try to fill possible input pins, and returns
  3422. * the badness value.
  3423. */
  3424. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  3425. hda_nid_t reference_pin,
  3426. bool hardwired, int offset)
  3427. {
  3428. struct alc_spec *spec = codec->spec;
  3429. struct auto_pin_cfg *cfg = &spec->autocfg;
  3430. int type, i, j, dacs, num_pins, old_pins;
  3431. unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
  3432. unsigned int location = get_defcfg_location(defcfg);
  3433. int badness = 0;
  3434. old_pins = spec->multi_ios;
  3435. if (old_pins >= 2)
  3436. goto end_fill;
  3437. num_pins = 0;
  3438. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  3439. for (i = 0; i < cfg->num_inputs; i++) {
  3440. if (cfg->inputs[i].type != type)
  3441. continue;
  3442. if (can_be_multiio_pin(codec, location,
  3443. cfg->inputs[i].pin))
  3444. num_pins++;
  3445. }
  3446. }
  3447. if (num_pins < 2)
  3448. goto end_fill;
  3449. dacs = spec->multiout.num_dacs;
  3450. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  3451. for (i = 0; i < cfg->num_inputs; i++) {
  3452. hda_nid_t nid = cfg->inputs[i].pin;
  3453. hda_nid_t dac = 0;
  3454. if (cfg->inputs[i].type != type)
  3455. continue;
  3456. if (!can_be_multiio_pin(codec, location, nid))
  3457. continue;
  3458. for (j = 0; j < spec->multi_ios; j++) {
  3459. if (nid == spec->multi_io[j].pin)
  3460. break;
  3461. }
  3462. if (j < spec->multi_ios)
  3463. continue;
  3464. if (offset && offset + spec->multi_ios < dacs) {
  3465. dac = spec->private_dac_nids[offset + spec->multi_ios];
  3466. if (!alc_auto_is_dac_reachable(codec, nid, dac))
  3467. dac = 0;
  3468. }
  3469. if (hardwired)
  3470. dac = get_dac_if_single(codec, nid);
  3471. else if (!dac)
  3472. dac = alc_auto_look_for_dac(codec, nid);
  3473. if (!dac) {
  3474. badness++;
  3475. continue;
  3476. }
  3477. spec->multi_io[spec->multi_ios].pin = nid;
  3478. spec->multi_io[spec->multi_ios].dac = dac;
  3479. spec->multi_ios++;
  3480. if (spec->multi_ios >= 2)
  3481. break;
  3482. }
  3483. }
  3484. end_fill:
  3485. if (badness)
  3486. badness = BAD_MULTI_IO;
  3487. if (old_pins == spec->multi_ios) {
  3488. if (hardwired)
  3489. return 1; /* nothing found */
  3490. else
  3491. return badness; /* no badness if nothing found */
  3492. }
  3493. if (!hardwired && spec->multi_ios < 2) {
  3494. spec->multi_ios = old_pins;
  3495. return badness;
  3496. }
  3497. return 0;
  3498. }
  3499. static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
  3500. struct snd_ctl_elem_info *uinfo)
  3501. {
  3502. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3503. struct alc_spec *spec = codec->spec;
  3504. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  3505. uinfo->count = 1;
  3506. uinfo->value.enumerated.items = spec->multi_ios + 1;
  3507. if (uinfo->value.enumerated.item > spec->multi_ios)
  3508. uinfo->value.enumerated.item = spec->multi_ios;
  3509. sprintf(uinfo->value.enumerated.name, "%dch",
  3510. (uinfo->value.enumerated.item + 1) * 2);
  3511. return 0;
  3512. }
  3513. static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
  3514. struct snd_ctl_elem_value *ucontrol)
  3515. {
  3516. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3517. struct alc_spec *spec = codec->spec;
  3518. ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
  3519. return 0;
  3520. }
  3521. static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
  3522. {
  3523. struct alc_spec *spec = codec->spec;
  3524. hda_nid_t nid = spec->multi_io[idx].pin;
  3525. if (!spec->multi_io[idx].ctl_in)
  3526. spec->multi_io[idx].ctl_in =
  3527. snd_hda_codec_read(codec, nid, 0,
  3528. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  3529. if (output) {
  3530. snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
  3531. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  3532. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  3533. HDA_AMP_MUTE, 0);
  3534. alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
  3535. } else {
  3536. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  3537. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  3538. HDA_AMP_MUTE, HDA_AMP_MUTE);
  3539. snd_hda_set_pin_ctl_cache(codec, nid,
  3540. spec->multi_io[idx].ctl_in);
  3541. }
  3542. return 0;
  3543. }
  3544. static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
  3545. struct snd_ctl_elem_value *ucontrol)
  3546. {
  3547. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3548. struct alc_spec *spec = codec->spec;
  3549. int i, ch;
  3550. ch = ucontrol->value.enumerated.item[0];
  3551. if (ch < 0 || ch > spec->multi_ios)
  3552. return -EINVAL;
  3553. if (ch == (spec->ext_channel_count - 1) / 2)
  3554. return 0;
  3555. spec->ext_channel_count = (ch + 1) * 2;
  3556. for (i = 0; i < spec->multi_ios; i++)
  3557. alc_set_multi_io(codec, i, i < ch);
  3558. spec->multiout.max_channels = max(spec->ext_channel_count,
  3559. spec->const_channel_count);
  3560. if (spec->need_dac_fix)
  3561. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  3562. return 1;
  3563. }
  3564. static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
  3565. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3566. .name = "Channel Mode",
  3567. .info = alc_auto_ch_mode_info,
  3568. .get = alc_auto_ch_mode_get,
  3569. .put = alc_auto_ch_mode_put,
  3570. };
  3571. static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
  3572. {
  3573. struct alc_spec *spec = codec->spec;
  3574. if (spec->multi_ios > 0) {
  3575. if (!alc_kcontrol_new(spec, "Channel Mode",
  3576. &alc_auto_channel_mode_enum))
  3577. return -ENOMEM;
  3578. }
  3579. return 0;
  3580. }
  3581. /* filter out invalid adc_nids (and capsrc_nids) that don't give all
  3582. * active input pins
  3583. */
  3584. static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
  3585. {
  3586. struct alc_spec *spec = codec->spec;
  3587. const struct hda_input_mux *imux;
  3588. hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  3589. hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  3590. int i, n, nums;
  3591. imux = spec->input_mux;
  3592. if (!imux)
  3593. return;
  3594. if (spec->dyn_adc_switch)
  3595. return;
  3596. again:
  3597. nums = 0;
  3598. for (n = 0; n < spec->num_adc_nids; n++) {
  3599. hda_nid_t cap = spec->private_capsrc_nids[n];
  3600. int num_conns = snd_hda_get_num_conns(codec, cap);
  3601. for (i = 0; i < imux->num_items; i++) {
  3602. hda_nid_t pin = spec->imux_pins[i];
  3603. if (pin) {
  3604. if (get_connection_index(codec, cap, pin) < 0)
  3605. break;
  3606. } else if (num_conns <= imux->items[i].index)
  3607. break;
  3608. }
  3609. if (i >= imux->num_items) {
  3610. adc_nids[nums] = spec->private_adc_nids[n];
  3611. capsrc_nids[nums++] = cap;
  3612. }
  3613. }
  3614. if (!nums) {
  3615. /* check whether ADC-switch is possible */
  3616. if (!alc_check_dyn_adc_switch(codec)) {
  3617. if (spec->shared_mic_hp) {
  3618. spec->shared_mic_hp = 0;
  3619. spec->private_imux[0].num_items = 1;
  3620. goto again;
  3621. }
  3622. printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
  3623. " using fallback 0x%x\n",
  3624. codec->chip_name, spec->private_adc_nids[0]);
  3625. spec->num_adc_nids = 1;
  3626. spec->auto_mic = 0;
  3627. return;
  3628. }
  3629. } else if (nums != spec->num_adc_nids) {
  3630. memcpy(spec->private_adc_nids, adc_nids,
  3631. nums * sizeof(hda_nid_t));
  3632. memcpy(spec->private_capsrc_nids, capsrc_nids,
  3633. nums * sizeof(hda_nid_t));
  3634. spec->num_adc_nids = nums;
  3635. }
  3636. if (spec->auto_mic)
  3637. alc_auto_mic_check_imux(codec); /* check auto-mic setups */
  3638. else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
  3639. spec->num_adc_nids = 1; /* reduce to a single ADC */
  3640. }
  3641. /*
  3642. * initialize ADC paths
  3643. */
  3644. static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
  3645. {
  3646. struct alc_spec *spec = codec->spec;
  3647. hda_nid_t nid;
  3648. nid = spec->adc_nids[adc_idx];
  3649. /* mute ADC */
  3650. if (nid_has_mute(codec, nid, HDA_INPUT)) {
  3651. snd_hda_codec_write(codec, nid, 0,
  3652. AC_VERB_SET_AMP_GAIN_MUTE,
  3653. AMP_IN_MUTE(0));
  3654. return;
  3655. }
  3656. if (!spec->capsrc_nids)
  3657. return;
  3658. nid = spec->capsrc_nids[adc_idx];
  3659. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  3660. snd_hda_codec_write(codec, nid, 0,
  3661. AC_VERB_SET_AMP_GAIN_MUTE,
  3662. AMP_OUT_MUTE);
  3663. }
  3664. static void alc_auto_init_input_src(struct hda_codec *codec)
  3665. {
  3666. struct alc_spec *spec = codec->spec;
  3667. int c, nums;
  3668. for (c = 0; c < spec->num_adc_nids; c++)
  3669. alc_auto_init_adc(codec, c);
  3670. if (spec->dyn_adc_switch)
  3671. nums = 1;
  3672. else
  3673. nums = spec->num_adc_nids;
  3674. for (c = 0; c < nums; c++)
  3675. alc_mux_select(codec, c, spec->cur_mux[c], true);
  3676. }
  3677. /* add mic boosts if needed */
  3678. static int alc_auto_add_mic_boost(struct hda_codec *codec)
  3679. {
  3680. struct alc_spec *spec = codec->spec;
  3681. struct auto_pin_cfg *cfg = &spec->autocfg;
  3682. int i, err;
  3683. int type_idx = 0;
  3684. hda_nid_t nid;
  3685. const char *prev_label = NULL;
  3686. for (i = 0; i < cfg->num_inputs; i++) {
  3687. if (cfg->inputs[i].type > AUTO_PIN_MIC)
  3688. break;
  3689. nid = cfg->inputs[i].pin;
  3690. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
  3691. const char *label;
  3692. char boost_label[32];
  3693. label = hda_get_autocfg_input_label(codec, cfg, i);
  3694. if (spec->shared_mic_hp && !strcmp(label, "Misc"))
  3695. label = "Headphone Mic";
  3696. if (prev_label && !strcmp(label, prev_label))
  3697. type_idx++;
  3698. else
  3699. type_idx = 0;
  3700. prev_label = label;
  3701. snprintf(boost_label, sizeof(boost_label),
  3702. "%s Boost Volume", label);
  3703. err = add_control(spec, ALC_CTL_WIDGET_VOL,
  3704. boost_label, type_idx,
  3705. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
  3706. if (err < 0)
  3707. return err;
  3708. }
  3709. }
  3710. return 0;
  3711. }
  3712. /* select or unmute the given capsrc route */
  3713. static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
  3714. int idx)
  3715. {
  3716. if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
  3717. snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
  3718. HDA_AMP_MUTE, 0);
  3719. } else if (snd_hda_get_num_conns(codec, cap) > 1) {
  3720. snd_hda_codec_write_cache(codec, cap, 0,
  3721. AC_VERB_SET_CONNECT_SEL, idx);
  3722. }
  3723. }
  3724. /* set the default connection to that pin */
  3725. static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
  3726. {
  3727. struct alc_spec *spec = codec->spec;
  3728. int i;
  3729. if (!pin)
  3730. return 0;
  3731. for (i = 0; i < spec->num_adc_nids; i++) {
  3732. hda_nid_t cap = get_capsrc(spec, i);
  3733. int idx;
  3734. idx = get_connection_index(codec, cap, pin);
  3735. if (idx < 0)
  3736. continue;
  3737. select_or_unmute_capsrc(codec, cap, idx);
  3738. return i; /* return the found index */
  3739. }
  3740. return -1; /* not found */
  3741. }
  3742. /* initialize some special cases for input sources */
  3743. static void alc_init_special_input_src(struct hda_codec *codec)
  3744. {
  3745. struct alc_spec *spec = codec->spec;
  3746. int i;
  3747. for (i = 0; i < spec->autocfg.num_inputs; i++)
  3748. init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
  3749. }
  3750. /* assign appropriate capture mixers */
  3751. static void set_capture_mixer(struct hda_codec *codec)
  3752. {
  3753. struct alc_spec *spec = codec->spec;
  3754. static const struct snd_kcontrol_new *caps[2][3] = {
  3755. { alc_capture_mixer_nosrc1,
  3756. alc_capture_mixer_nosrc2,
  3757. alc_capture_mixer_nosrc3 },
  3758. { alc_capture_mixer1,
  3759. alc_capture_mixer2,
  3760. alc_capture_mixer3 },
  3761. };
  3762. /* check whether either of ADC or MUX has a volume control */
  3763. if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
  3764. if (!spec->capsrc_nids)
  3765. return; /* no volume */
  3766. if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
  3767. return; /* no volume in capsrc, too */
  3768. spec->vol_in_capsrc = 1;
  3769. }
  3770. if (spec->num_adc_nids > 0) {
  3771. int mux = 0;
  3772. int num_adcs = 0;
  3773. if (spec->input_mux && spec->input_mux->num_items > 1)
  3774. mux = 1;
  3775. if (spec->auto_mic) {
  3776. num_adcs = 1;
  3777. mux = 0;
  3778. } else if (spec->dyn_adc_switch)
  3779. num_adcs = 1;
  3780. if (!num_adcs) {
  3781. if (spec->num_adc_nids > 3)
  3782. spec->num_adc_nids = 3;
  3783. else if (!spec->num_adc_nids)
  3784. return;
  3785. num_adcs = spec->num_adc_nids;
  3786. }
  3787. spec->cap_mixer = caps[mux][num_adcs - 1];
  3788. }
  3789. }
  3790. /*
  3791. * standard auto-parser initializations
  3792. */
  3793. static void alc_auto_init_std(struct hda_codec *codec)
  3794. {
  3795. alc_auto_init_multi_out(codec);
  3796. alc_auto_init_extra_out(codec);
  3797. alc_auto_init_analog_input(codec);
  3798. alc_auto_init_input_src(codec);
  3799. alc_auto_init_digital(codec);
  3800. alc_inithook(codec);
  3801. }
  3802. /*
  3803. * Digital-beep handlers
  3804. */
  3805. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3806. #define set_beep_amp(spec, nid, idx, dir) \
  3807. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
  3808. static const struct snd_pci_quirk beep_white_list[] = {
  3809. SND_PCI_QUIRK(0x1043, 0x103c, "ASUS", 1),
  3810. SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
  3811. SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
  3812. SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
  3813. SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
  3814. SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
  3815. SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
  3816. {}
  3817. };
  3818. static inline int has_cdefine_beep(struct hda_codec *codec)
  3819. {
  3820. struct alc_spec *spec = codec->spec;
  3821. const struct snd_pci_quirk *q;
  3822. q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
  3823. if (q)
  3824. return q->value;
  3825. return spec->cdefine.enable_pcbeep;
  3826. }
  3827. #else
  3828. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  3829. #define has_cdefine_beep(codec) 0
  3830. #endif
  3831. /* parse the BIOS configuration and set up the alc_spec */
  3832. /* return 1 if successful, 0 if the proper config is not found,
  3833. * or a negative error code
  3834. */
  3835. static int alc_parse_auto_config(struct hda_codec *codec,
  3836. const hda_nid_t *ignore_nids,
  3837. const hda_nid_t *ssid_nids)
  3838. {
  3839. struct alc_spec *spec = codec->spec;
  3840. struct auto_pin_cfg *cfg = &spec->autocfg;
  3841. int err;
  3842. err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
  3843. spec->parse_flags);
  3844. if (err < 0)
  3845. return err;
  3846. if (!cfg->line_outs) {
  3847. if (cfg->dig_outs || cfg->dig_in_pin) {
  3848. spec->multiout.max_channels = 2;
  3849. spec->no_analog = 1;
  3850. goto dig_only;
  3851. }
  3852. return 0; /* can't find valid BIOS pin config */
  3853. }
  3854. if (!spec->no_primary_hp &&
  3855. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
  3856. cfg->line_outs <= cfg->hp_outs) {
  3857. /* use HP as primary out */
  3858. cfg->speaker_outs = cfg->line_outs;
  3859. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  3860. sizeof(cfg->speaker_pins));
  3861. cfg->line_outs = cfg->hp_outs;
  3862. memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
  3863. cfg->hp_outs = 0;
  3864. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  3865. cfg->line_out_type = AUTO_PIN_HP_OUT;
  3866. }
  3867. err = alc_auto_fill_dac_nids(codec);
  3868. if (err < 0)
  3869. return err;
  3870. err = alc_auto_add_multi_channel_mode(codec);
  3871. if (err < 0)
  3872. return err;
  3873. err = alc_auto_create_multi_out_ctls(codec, cfg);
  3874. if (err < 0)
  3875. return err;
  3876. err = alc_auto_create_hp_out(codec);
  3877. if (err < 0)
  3878. return err;
  3879. err = alc_auto_create_speaker_out(codec);
  3880. if (err < 0)
  3881. return err;
  3882. err = alc_auto_create_shared_input(codec);
  3883. if (err < 0)
  3884. return err;
  3885. err = alc_auto_create_input_ctls(codec);
  3886. if (err < 0)
  3887. return err;
  3888. /* check the multiple speaker pins */
  3889. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
  3890. spec->const_channel_count = cfg->line_outs * 2;
  3891. else
  3892. spec->const_channel_count = cfg->speaker_outs * 2;
  3893. if (spec->multi_ios > 0)
  3894. spec->multiout.max_channels = max(spec->ext_channel_count,
  3895. spec->const_channel_count);
  3896. else
  3897. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3898. dig_only:
  3899. alc_auto_parse_digital(codec);
  3900. if (!spec->no_analog)
  3901. alc_remove_invalid_adc_nids(codec);
  3902. if (ssid_nids)
  3903. alc_ssid_check(codec, ssid_nids);
  3904. if (!spec->no_analog) {
  3905. err = alc_auto_check_switches(codec);
  3906. if (err < 0)
  3907. return err;
  3908. err = alc_auto_add_mic_boost(codec);
  3909. if (err < 0)
  3910. return err;
  3911. }
  3912. if (spec->kctls.list)
  3913. add_mixer(spec, spec->kctls.list);
  3914. if (!spec->no_analog && !spec->cap_mixer)
  3915. set_capture_mixer(codec);
  3916. return 1;
  3917. }
  3918. /* common preparation job for alc_spec */
  3919. static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
  3920. {
  3921. struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3922. int err;
  3923. if (!spec)
  3924. return -ENOMEM;
  3925. codec->spec = spec;
  3926. spec->mixer_nid = mixer_nid;
  3927. snd_hda_gen_init(&spec->gen);
  3928. snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
  3929. snd_array_init(&spec->bind_ctls, sizeof(struct hda_bind_ctls *), 8);
  3930. err = alc_codec_rename_from_preset(codec);
  3931. if (err < 0) {
  3932. kfree(spec);
  3933. return err;
  3934. }
  3935. return 0;
  3936. }
  3937. static int alc880_parse_auto_config(struct hda_codec *codec)
  3938. {
  3939. static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
  3940. static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3941. return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
  3942. }
  3943. /*
  3944. * ALC880 fix-ups
  3945. */
  3946. enum {
  3947. ALC880_FIXUP_GPIO1,
  3948. ALC880_FIXUP_GPIO2,
  3949. ALC880_FIXUP_MEDION_RIM,
  3950. ALC880_FIXUP_LG,
  3951. ALC880_FIXUP_W810,
  3952. ALC880_FIXUP_EAPD_COEF,
  3953. ALC880_FIXUP_TCL_S700,
  3954. ALC880_FIXUP_VOL_KNOB,
  3955. ALC880_FIXUP_FUJITSU,
  3956. ALC880_FIXUP_F1734,
  3957. ALC880_FIXUP_UNIWILL,
  3958. ALC880_FIXUP_UNIWILL_DIG,
  3959. ALC880_FIXUP_Z71V,
  3960. ALC880_FIXUP_3ST_BASE,
  3961. ALC880_FIXUP_3ST,
  3962. ALC880_FIXUP_3ST_DIG,
  3963. ALC880_FIXUP_5ST_BASE,
  3964. ALC880_FIXUP_5ST,
  3965. ALC880_FIXUP_5ST_DIG,
  3966. ALC880_FIXUP_6ST_BASE,
  3967. ALC880_FIXUP_6ST,
  3968. ALC880_FIXUP_6ST_DIG,
  3969. };
  3970. /* enable the volume-knob widget support on NID 0x21 */
  3971. static void alc880_fixup_vol_knob(struct hda_codec *codec,
  3972. const struct alc_fixup *fix, int action)
  3973. {
  3974. if (action == ALC_FIXUP_ACT_PROBE)
  3975. snd_hda_jack_detect_enable_callback(codec, 0x21, ALC_DCVOL_EVENT, alc_update_knob_master);
  3976. }
  3977. static const struct alc_fixup alc880_fixups[] = {
  3978. [ALC880_FIXUP_GPIO1] = {
  3979. .type = ALC_FIXUP_VERBS,
  3980. .v.verbs = alc_gpio1_init_verbs,
  3981. },
  3982. [ALC880_FIXUP_GPIO2] = {
  3983. .type = ALC_FIXUP_VERBS,
  3984. .v.verbs = alc_gpio2_init_verbs,
  3985. },
  3986. [ALC880_FIXUP_MEDION_RIM] = {
  3987. .type = ALC_FIXUP_VERBS,
  3988. .v.verbs = (const struct hda_verb[]) {
  3989. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  3990. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  3991. { }
  3992. },
  3993. .chained = true,
  3994. .chain_id = ALC880_FIXUP_GPIO2,
  3995. },
  3996. [ALC880_FIXUP_LG] = {
  3997. .type = ALC_FIXUP_PINS,
  3998. .v.pins = (const struct alc_pincfg[]) {
  3999. /* disable bogus unused pins */
  4000. { 0x16, 0x411111f0 },
  4001. { 0x18, 0x411111f0 },
  4002. { 0x1a, 0x411111f0 },
  4003. { }
  4004. }
  4005. },
  4006. [ALC880_FIXUP_W810] = {
  4007. .type = ALC_FIXUP_PINS,
  4008. .v.pins = (const struct alc_pincfg[]) {
  4009. /* disable bogus unused pins */
  4010. { 0x17, 0x411111f0 },
  4011. { }
  4012. },
  4013. .chained = true,
  4014. .chain_id = ALC880_FIXUP_GPIO2,
  4015. },
  4016. [ALC880_FIXUP_EAPD_COEF] = {
  4017. .type = ALC_FIXUP_VERBS,
  4018. .v.verbs = (const struct hda_verb[]) {
  4019. /* change to EAPD mode */
  4020. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4021. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  4022. {}
  4023. },
  4024. },
  4025. [ALC880_FIXUP_TCL_S700] = {
  4026. .type = ALC_FIXUP_VERBS,
  4027. .v.verbs = (const struct hda_verb[]) {
  4028. /* change to EAPD mode */
  4029. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4030. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  4031. {}
  4032. },
  4033. .chained = true,
  4034. .chain_id = ALC880_FIXUP_GPIO2,
  4035. },
  4036. [ALC880_FIXUP_VOL_KNOB] = {
  4037. .type = ALC_FIXUP_FUNC,
  4038. .v.func = alc880_fixup_vol_knob,
  4039. },
  4040. [ALC880_FIXUP_FUJITSU] = {
  4041. /* override all pins as BIOS on old Amilo is broken */
  4042. .type = ALC_FIXUP_PINS,
  4043. .v.pins = (const struct alc_pincfg[]) {
  4044. { 0x14, 0x0121411f }, /* HP */
  4045. { 0x15, 0x99030120 }, /* speaker */
  4046. { 0x16, 0x99030130 }, /* bass speaker */
  4047. { 0x17, 0x411111f0 }, /* N/A */
  4048. { 0x18, 0x411111f0 }, /* N/A */
  4049. { 0x19, 0x01a19950 }, /* mic-in */
  4050. { 0x1a, 0x411111f0 }, /* N/A */
  4051. { 0x1b, 0x411111f0 }, /* N/A */
  4052. { 0x1c, 0x411111f0 }, /* N/A */
  4053. { 0x1d, 0x411111f0 }, /* N/A */
  4054. { 0x1e, 0x01454140 }, /* SPDIF out */
  4055. { }
  4056. },
  4057. .chained = true,
  4058. .chain_id = ALC880_FIXUP_VOL_KNOB,
  4059. },
  4060. [ALC880_FIXUP_F1734] = {
  4061. /* almost compatible with FUJITSU, but no bass and SPDIF */
  4062. .type = ALC_FIXUP_PINS,
  4063. .v.pins = (const struct alc_pincfg[]) {
  4064. { 0x14, 0x0121411f }, /* HP */
  4065. { 0x15, 0x99030120 }, /* speaker */
  4066. { 0x16, 0x411111f0 }, /* N/A */
  4067. { 0x17, 0x411111f0 }, /* N/A */
  4068. { 0x18, 0x411111f0 }, /* N/A */
  4069. { 0x19, 0x01a19950 }, /* mic-in */
  4070. { 0x1a, 0x411111f0 }, /* N/A */
  4071. { 0x1b, 0x411111f0 }, /* N/A */
  4072. { 0x1c, 0x411111f0 }, /* N/A */
  4073. { 0x1d, 0x411111f0 }, /* N/A */
  4074. { 0x1e, 0x411111f0 }, /* N/A */
  4075. { }
  4076. },
  4077. .chained = true,
  4078. .chain_id = ALC880_FIXUP_VOL_KNOB,
  4079. },
  4080. [ALC880_FIXUP_UNIWILL] = {
  4081. /* need to fix HP and speaker pins to be parsed correctly */
  4082. .type = ALC_FIXUP_PINS,
  4083. .v.pins = (const struct alc_pincfg[]) {
  4084. { 0x14, 0x0121411f }, /* HP */
  4085. { 0x15, 0x99030120 }, /* speaker */
  4086. { 0x16, 0x99030130 }, /* bass speaker */
  4087. { }
  4088. },
  4089. },
  4090. [ALC880_FIXUP_UNIWILL_DIG] = {
  4091. .type = ALC_FIXUP_PINS,
  4092. .v.pins = (const struct alc_pincfg[]) {
  4093. /* disable bogus unused pins */
  4094. { 0x17, 0x411111f0 },
  4095. { 0x19, 0x411111f0 },
  4096. { 0x1b, 0x411111f0 },
  4097. { 0x1f, 0x411111f0 },
  4098. { }
  4099. }
  4100. },
  4101. [ALC880_FIXUP_Z71V] = {
  4102. .type = ALC_FIXUP_PINS,
  4103. .v.pins = (const struct alc_pincfg[]) {
  4104. /* set up the whole pins as BIOS is utterly broken */
  4105. { 0x14, 0x99030120 }, /* speaker */
  4106. { 0x15, 0x0121411f }, /* HP */
  4107. { 0x16, 0x411111f0 }, /* N/A */
  4108. { 0x17, 0x411111f0 }, /* N/A */
  4109. { 0x18, 0x01a19950 }, /* mic-in */
  4110. { 0x19, 0x411111f0 }, /* N/A */
  4111. { 0x1a, 0x01813031 }, /* line-in */
  4112. { 0x1b, 0x411111f0 }, /* N/A */
  4113. { 0x1c, 0x411111f0 }, /* N/A */
  4114. { 0x1d, 0x411111f0 }, /* N/A */
  4115. { 0x1e, 0x0144111e }, /* SPDIF */
  4116. { }
  4117. }
  4118. },
  4119. [ALC880_FIXUP_3ST_BASE] = {
  4120. .type = ALC_FIXUP_PINS,
  4121. .v.pins = (const struct alc_pincfg[]) {
  4122. { 0x14, 0x01014010 }, /* line-out */
  4123. { 0x15, 0x411111f0 }, /* N/A */
  4124. { 0x16, 0x411111f0 }, /* N/A */
  4125. { 0x17, 0x411111f0 }, /* N/A */
  4126. { 0x18, 0x01a19c30 }, /* mic-in */
  4127. { 0x19, 0x0121411f }, /* HP */
  4128. { 0x1a, 0x01813031 }, /* line-in */
  4129. { 0x1b, 0x02a19c40 }, /* front-mic */
  4130. { 0x1c, 0x411111f0 }, /* N/A */
  4131. { 0x1d, 0x411111f0 }, /* N/A */
  4132. /* 0x1e is filled in below */
  4133. { 0x1f, 0x411111f0 }, /* N/A */
  4134. { }
  4135. }
  4136. },
  4137. [ALC880_FIXUP_3ST] = {
  4138. .type = ALC_FIXUP_PINS,
  4139. .v.pins = (const struct alc_pincfg[]) {
  4140. { 0x1e, 0x411111f0 }, /* N/A */
  4141. { }
  4142. },
  4143. .chained = true,
  4144. .chain_id = ALC880_FIXUP_3ST_BASE,
  4145. },
  4146. [ALC880_FIXUP_3ST_DIG] = {
  4147. .type = ALC_FIXUP_PINS,
  4148. .v.pins = (const struct alc_pincfg[]) {
  4149. { 0x1e, 0x0144111e }, /* SPDIF */
  4150. { }
  4151. },
  4152. .chained = true,
  4153. .chain_id = ALC880_FIXUP_3ST_BASE,
  4154. },
  4155. [ALC880_FIXUP_5ST_BASE] = {
  4156. .type = ALC_FIXUP_PINS,
  4157. .v.pins = (const struct alc_pincfg[]) {
  4158. { 0x14, 0x01014010 }, /* front */
  4159. { 0x15, 0x411111f0 }, /* N/A */
  4160. { 0x16, 0x01011411 }, /* CLFE */
  4161. { 0x17, 0x01016412 }, /* surr */
  4162. { 0x18, 0x01a19c30 }, /* mic-in */
  4163. { 0x19, 0x0121411f }, /* HP */
  4164. { 0x1a, 0x01813031 }, /* line-in */
  4165. { 0x1b, 0x02a19c40 }, /* front-mic */
  4166. { 0x1c, 0x411111f0 }, /* N/A */
  4167. { 0x1d, 0x411111f0 }, /* N/A */
  4168. /* 0x1e is filled in below */
  4169. { 0x1f, 0x411111f0 }, /* N/A */
  4170. { }
  4171. }
  4172. },
  4173. [ALC880_FIXUP_5ST] = {
  4174. .type = ALC_FIXUP_PINS,
  4175. .v.pins = (const struct alc_pincfg[]) {
  4176. { 0x1e, 0x411111f0 }, /* N/A */
  4177. { }
  4178. },
  4179. .chained = true,
  4180. .chain_id = ALC880_FIXUP_5ST_BASE,
  4181. },
  4182. [ALC880_FIXUP_5ST_DIG] = {
  4183. .type = ALC_FIXUP_PINS,
  4184. .v.pins = (const struct alc_pincfg[]) {
  4185. { 0x1e, 0x0144111e }, /* SPDIF */
  4186. { }
  4187. },
  4188. .chained = true,
  4189. .chain_id = ALC880_FIXUP_5ST_BASE,
  4190. },
  4191. [ALC880_FIXUP_6ST_BASE] = {
  4192. .type = ALC_FIXUP_PINS,
  4193. .v.pins = (const struct alc_pincfg[]) {
  4194. { 0x14, 0x01014010 }, /* front */
  4195. { 0x15, 0x01016412 }, /* surr */
  4196. { 0x16, 0x01011411 }, /* CLFE */
  4197. { 0x17, 0x01012414 }, /* side */
  4198. { 0x18, 0x01a19c30 }, /* mic-in */
  4199. { 0x19, 0x02a19c40 }, /* front-mic */
  4200. { 0x1a, 0x01813031 }, /* line-in */
  4201. { 0x1b, 0x0121411f }, /* HP */
  4202. { 0x1c, 0x411111f0 }, /* N/A */
  4203. { 0x1d, 0x411111f0 }, /* N/A */
  4204. /* 0x1e is filled in below */
  4205. { 0x1f, 0x411111f0 }, /* N/A */
  4206. { }
  4207. }
  4208. },
  4209. [ALC880_FIXUP_6ST] = {
  4210. .type = ALC_FIXUP_PINS,
  4211. .v.pins = (const struct alc_pincfg[]) {
  4212. { 0x1e, 0x411111f0 }, /* N/A */
  4213. { }
  4214. },
  4215. .chained = true,
  4216. .chain_id = ALC880_FIXUP_6ST_BASE,
  4217. },
  4218. [ALC880_FIXUP_6ST_DIG] = {
  4219. .type = ALC_FIXUP_PINS,
  4220. .v.pins = (const struct alc_pincfg[]) {
  4221. { 0x1e, 0x0144111e }, /* SPDIF */
  4222. { }
  4223. },
  4224. .chained = true,
  4225. .chain_id = ALC880_FIXUP_6ST_BASE,
  4226. },
  4227. };
  4228. static const struct snd_pci_quirk alc880_fixup_tbl[] = {
  4229. SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
  4230. SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
  4231. SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
  4232. SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
  4233. SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
  4234. SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
  4235. SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
  4236. SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
  4237. SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
  4238. SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
  4239. SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
  4240. SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
  4241. SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
  4242. SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
  4243. SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
  4244. SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
  4245. SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
  4246. SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
  4247. SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
  4248. /* Below is the copied entries from alc880_quirks.c.
  4249. * It's not quite sure whether BIOS sets the correct pin-config table
  4250. * on these machines, thus they are kept to be compatible with
  4251. * the old static quirks. Once when it's confirmed to work without
  4252. * these overrides, it'd be better to remove.
  4253. */
  4254. SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
  4255. SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
  4256. SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
  4257. SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
  4258. SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
  4259. SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
  4260. SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
  4261. SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
  4262. SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
  4263. SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
  4264. SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
  4265. SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
  4266. SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
  4267. SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
  4268. SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
  4269. SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
  4270. SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
  4271. SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
  4272. SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
  4273. SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
  4274. SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
  4275. SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
  4276. SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
  4277. SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4278. SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4279. SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4280. SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4281. SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4282. SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4283. SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
  4284. SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4285. SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4286. SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
  4287. /* default Intel */
  4288. SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
  4289. SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
  4290. SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
  4291. {}
  4292. };
  4293. static const struct alc_model_fixup alc880_fixup_models[] = {
  4294. {.id = ALC880_FIXUP_3ST, .name = "3stack"},
  4295. {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
  4296. {.id = ALC880_FIXUP_5ST, .name = "5stack"},
  4297. {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
  4298. {.id = ALC880_FIXUP_6ST, .name = "6stack"},
  4299. {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
  4300. {}
  4301. };
  4302. /*
  4303. * OK, here we have finally the patch for ALC880
  4304. */
  4305. static int patch_alc880(struct hda_codec *codec)
  4306. {
  4307. struct alc_spec *spec;
  4308. int err;
  4309. err = alc_alloc_spec(codec, 0x0b);
  4310. if (err < 0)
  4311. return err;
  4312. spec = codec->spec;
  4313. spec->need_dac_fix = 1;
  4314. alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
  4315. alc880_fixups);
  4316. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4317. /* automatic parse from the BIOS config */
  4318. err = alc880_parse_auto_config(codec);
  4319. if (err < 0)
  4320. goto error;
  4321. if (!spec->no_analog) {
  4322. err = snd_hda_attach_beep_device(codec, 0x1);
  4323. if (err < 0)
  4324. goto error;
  4325. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4326. }
  4327. codec->patch_ops = alc_patch_ops;
  4328. codec->patch_ops.unsol_event = alc880_unsol_event;
  4329. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4330. return 0;
  4331. error:
  4332. alc_free(codec);
  4333. return err;
  4334. }
  4335. /*
  4336. * ALC260 support
  4337. */
  4338. static int alc260_parse_auto_config(struct hda_codec *codec)
  4339. {
  4340. static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
  4341. static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
  4342. return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
  4343. }
  4344. /*
  4345. * Pin config fixes
  4346. */
  4347. enum {
  4348. ALC260_FIXUP_HP_DC5750,
  4349. ALC260_FIXUP_HP_PIN_0F,
  4350. ALC260_FIXUP_COEF,
  4351. ALC260_FIXUP_GPIO1,
  4352. ALC260_FIXUP_GPIO1_TOGGLE,
  4353. ALC260_FIXUP_REPLACER,
  4354. ALC260_FIXUP_HP_B1900,
  4355. ALC260_FIXUP_KN1,
  4356. };
  4357. static void alc260_gpio1_automute(struct hda_codec *codec)
  4358. {
  4359. struct alc_spec *spec = codec->spec;
  4360. snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  4361. spec->hp_jack_present);
  4362. }
  4363. static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
  4364. const struct alc_fixup *fix, int action)
  4365. {
  4366. struct alc_spec *spec = codec->spec;
  4367. if (action == ALC_FIXUP_ACT_PROBE) {
  4368. /* although the machine has only one output pin, we need to
  4369. * toggle GPIO1 according to the jack state
  4370. */
  4371. spec->automute_hook = alc260_gpio1_automute;
  4372. spec->detect_hp = 1;
  4373. spec->automute_speaker = 1;
  4374. spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
  4375. snd_hda_jack_detect_enable_callback(codec, 0x0f, ALC_HP_EVENT,
  4376. alc_hp_automute);
  4377. snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
  4378. }
  4379. }
  4380. static void alc260_fixup_kn1(struct hda_codec *codec,
  4381. const struct alc_fixup *fix, int action)
  4382. {
  4383. struct alc_spec *spec = codec->spec;
  4384. static const struct alc_pincfg pincfgs[] = {
  4385. { 0x0f, 0x02214000 }, /* HP/speaker */
  4386. { 0x12, 0x90a60160 }, /* int mic */
  4387. { 0x13, 0x02a19000 }, /* ext mic */
  4388. { 0x18, 0x01446000 }, /* SPDIF out */
  4389. /* disable bogus I/O pins */
  4390. { 0x10, 0x411111f0 },
  4391. { 0x11, 0x411111f0 },
  4392. { 0x14, 0x411111f0 },
  4393. { 0x15, 0x411111f0 },
  4394. { 0x16, 0x411111f0 },
  4395. { 0x17, 0x411111f0 },
  4396. { 0x19, 0x411111f0 },
  4397. { }
  4398. };
  4399. switch (action) {
  4400. case ALC_FIXUP_ACT_PRE_PROBE:
  4401. alc_apply_pincfgs(codec, pincfgs);
  4402. break;
  4403. case ALC_FIXUP_ACT_PROBE:
  4404. spec->init_amp = ALC_INIT_NONE;
  4405. break;
  4406. }
  4407. }
  4408. static const struct alc_fixup alc260_fixups[] = {
  4409. [ALC260_FIXUP_HP_DC5750] = {
  4410. .type = ALC_FIXUP_PINS,
  4411. .v.pins = (const struct alc_pincfg[]) {
  4412. { 0x11, 0x90130110 }, /* speaker */
  4413. { }
  4414. }
  4415. },
  4416. [ALC260_FIXUP_HP_PIN_0F] = {
  4417. .type = ALC_FIXUP_PINS,
  4418. .v.pins = (const struct alc_pincfg[]) {
  4419. { 0x0f, 0x01214000 }, /* HP */
  4420. { }
  4421. }
  4422. },
  4423. [ALC260_FIXUP_COEF] = {
  4424. .type = ALC_FIXUP_VERBS,
  4425. .v.verbs = (const struct hda_verb[]) {
  4426. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4427. { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
  4428. { }
  4429. },
  4430. .chained = true,
  4431. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  4432. },
  4433. [ALC260_FIXUP_GPIO1] = {
  4434. .type = ALC_FIXUP_VERBS,
  4435. .v.verbs = alc_gpio1_init_verbs,
  4436. },
  4437. [ALC260_FIXUP_GPIO1_TOGGLE] = {
  4438. .type = ALC_FIXUP_FUNC,
  4439. .v.func = alc260_fixup_gpio1_toggle,
  4440. .chained = true,
  4441. .chain_id = ALC260_FIXUP_HP_PIN_0F,
  4442. },
  4443. [ALC260_FIXUP_REPLACER] = {
  4444. .type = ALC_FIXUP_VERBS,
  4445. .v.verbs = (const struct hda_verb[]) {
  4446. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4447. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4448. { }
  4449. },
  4450. .chained = true,
  4451. .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
  4452. },
  4453. [ALC260_FIXUP_HP_B1900] = {
  4454. .type = ALC_FIXUP_FUNC,
  4455. .v.func = alc260_fixup_gpio1_toggle,
  4456. .chained = true,
  4457. .chain_id = ALC260_FIXUP_COEF,
  4458. },
  4459. [ALC260_FIXUP_KN1] = {
  4460. .type = ALC_FIXUP_FUNC,
  4461. .v.func = alc260_fixup_kn1,
  4462. },
  4463. };
  4464. static const struct snd_pci_quirk alc260_fixup_tbl[] = {
  4465. SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
  4466. SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
  4467. SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
  4468. SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
  4469. SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
  4470. SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
  4471. SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
  4472. SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
  4473. SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
  4474. {}
  4475. };
  4476. /*
  4477. */
  4478. static int patch_alc260(struct hda_codec *codec)
  4479. {
  4480. struct alc_spec *spec;
  4481. int err;
  4482. err = alc_alloc_spec(codec, 0x07);
  4483. if (err < 0)
  4484. return err;
  4485. spec = codec->spec;
  4486. alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
  4487. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4488. /* automatic parse from the BIOS config */
  4489. err = alc260_parse_auto_config(codec);
  4490. if (err < 0)
  4491. goto error;
  4492. if (!spec->no_analog) {
  4493. err = snd_hda_attach_beep_device(codec, 0x1);
  4494. if (err < 0)
  4495. goto error;
  4496. set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
  4497. }
  4498. codec->patch_ops = alc_patch_ops;
  4499. spec->shutup = alc_eapd_shutup;
  4500. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4501. return 0;
  4502. error:
  4503. alc_free(codec);
  4504. return err;
  4505. }
  4506. /*
  4507. * ALC882/883/885/888/889 support
  4508. *
  4509. * ALC882 is almost identical with ALC880 but has cleaner and more flexible
  4510. * configuration. Each pin widget can choose any input DACs and a mixer.
  4511. * Each ADC is connected from a mixer of all inputs. This makes possible
  4512. * 6-channel independent captures.
  4513. *
  4514. * In addition, an independent DAC for the multi-playback (not used in this
  4515. * driver yet).
  4516. */
  4517. /*
  4518. * Pin config fixes
  4519. */
  4520. enum {
  4521. ALC882_FIXUP_ABIT_AW9D_MAX,
  4522. ALC882_FIXUP_LENOVO_Y530,
  4523. ALC882_FIXUP_PB_M5210,
  4524. ALC882_FIXUP_ACER_ASPIRE_7736,
  4525. ALC882_FIXUP_ASUS_W90V,
  4526. ALC889_FIXUP_CD,
  4527. ALC889_FIXUP_VAIO_TT,
  4528. ALC888_FIXUP_EEE1601,
  4529. ALC882_FIXUP_EAPD,
  4530. ALC883_FIXUP_EAPD,
  4531. ALC883_FIXUP_ACER_EAPD,
  4532. ALC882_FIXUP_GPIO1,
  4533. ALC882_FIXUP_GPIO2,
  4534. ALC882_FIXUP_GPIO3,
  4535. ALC889_FIXUP_COEF,
  4536. ALC882_FIXUP_ASUS_W2JC,
  4537. ALC882_FIXUP_ACER_ASPIRE_4930G,
  4538. ALC882_FIXUP_ACER_ASPIRE_8930G,
  4539. ALC882_FIXUP_ASPIRE_8930G_VERBS,
  4540. ALC885_FIXUP_MACPRO_GPIO,
  4541. ALC889_FIXUP_DAC_ROUTE,
  4542. ALC889_FIXUP_MBP_VREF,
  4543. ALC889_FIXUP_IMAC91_VREF,
  4544. ALC882_FIXUP_INV_DMIC,
  4545. ALC882_FIXUP_NO_PRIMARY_HP,
  4546. };
  4547. static void alc889_fixup_coef(struct hda_codec *codec,
  4548. const struct alc_fixup *fix, int action)
  4549. {
  4550. if (action != ALC_FIXUP_ACT_INIT)
  4551. return;
  4552. alc889_coef_init(codec);
  4553. }
  4554. /* toggle speaker-output according to the hp-jack state */
  4555. static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
  4556. {
  4557. unsigned int gpiostate, gpiomask, gpiodir;
  4558. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  4559. AC_VERB_GET_GPIO_DATA, 0);
  4560. if (!muted)
  4561. gpiostate |= (1 << pin);
  4562. else
  4563. gpiostate &= ~(1 << pin);
  4564. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  4565. AC_VERB_GET_GPIO_MASK, 0);
  4566. gpiomask |= (1 << pin);
  4567. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  4568. AC_VERB_GET_GPIO_DIRECTION, 0);
  4569. gpiodir |= (1 << pin);
  4570. snd_hda_codec_write(codec, codec->afg, 0,
  4571. AC_VERB_SET_GPIO_MASK, gpiomask);
  4572. snd_hda_codec_write(codec, codec->afg, 0,
  4573. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  4574. msleep(1);
  4575. snd_hda_codec_write(codec, codec->afg, 0,
  4576. AC_VERB_SET_GPIO_DATA, gpiostate);
  4577. }
  4578. /* set up GPIO at initialization */
  4579. static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
  4580. const struct alc_fixup *fix, int action)
  4581. {
  4582. if (action != ALC_FIXUP_ACT_INIT)
  4583. return;
  4584. alc882_gpio_mute(codec, 0, 0);
  4585. alc882_gpio_mute(codec, 1, 0);
  4586. }
  4587. /* Fix the connection of some pins for ALC889:
  4588. * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
  4589. * work correctly (bko#42740)
  4590. */
  4591. static void alc889_fixup_dac_route(struct hda_codec *codec,
  4592. const struct alc_fixup *fix, int action)
  4593. {
  4594. if (action == ALC_FIXUP_ACT_PRE_PROBE) {
  4595. /* fake the connections during parsing the tree */
  4596. hda_nid_t conn1[2] = { 0x0c, 0x0d };
  4597. hda_nid_t conn2[2] = { 0x0e, 0x0f };
  4598. snd_hda_override_conn_list(codec, 0x14, 2, conn1);
  4599. snd_hda_override_conn_list(codec, 0x15, 2, conn1);
  4600. snd_hda_override_conn_list(codec, 0x18, 2, conn2);
  4601. snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
  4602. } else if (action == ALC_FIXUP_ACT_PROBE) {
  4603. /* restore the connections */
  4604. hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
  4605. snd_hda_override_conn_list(codec, 0x14, 5, conn);
  4606. snd_hda_override_conn_list(codec, 0x15, 5, conn);
  4607. snd_hda_override_conn_list(codec, 0x18, 5, conn);
  4608. snd_hda_override_conn_list(codec, 0x1a, 5, conn);
  4609. }
  4610. }
  4611. /* Set VREF on HP pin */
  4612. static void alc889_fixup_mbp_vref(struct hda_codec *codec,
  4613. const struct alc_fixup *fix, int action)
  4614. {
  4615. struct alc_spec *spec = codec->spec;
  4616. static hda_nid_t nids[2] = { 0x14, 0x15 };
  4617. int i;
  4618. if (action != ALC_FIXUP_ACT_INIT)
  4619. return;
  4620. for (i = 0; i < ARRAY_SIZE(nids); i++) {
  4621. unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
  4622. if (get_defcfg_device(val) != AC_JACK_HP_OUT)
  4623. continue;
  4624. val = snd_hda_codec_read(codec, nids[i], 0,
  4625. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4626. val |= AC_PINCTL_VREF_80;
  4627. snd_hda_set_pin_ctl(codec, nids[i], val);
  4628. spec->keep_vref_in_automute = 1;
  4629. break;
  4630. }
  4631. }
  4632. /* Set VREF on speaker pins on imac91 */
  4633. static void alc889_fixup_imac91_vref(struct hda_codec *codec,
  4634. const struct alc_fixup *fix, int action)
  4635. {
  4636. struct alc_spec *spec = codec->spec;
  4637. static hda_nid_t nids[2] = { 0x18, 0x1a };
  4638. int i;
  4639. if (action != ALC_FIXUP_ACT_INIT)
  4640. return;
  4641. for (i = 0; i < ARRAY_SIZE(nids); i++) {
  4642. unsigned int val;
  4643. val = snd_hda_codec_read(codec, nids[i], 0,
  4644. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  4645. val |= AC_PINCTL_VREF_50;
  4646. snd_hda_set_pin_ctl(codec, nids[i], val);
  4647. }
  4648. spec->keep_vref_in_automute = 1;
  4649. }
  4650. /* Don't take HP output as primary
  4651. * strangely, the speaker output doesn't work on VAIO Z through DAC 0x05
  4652. */
  4653. static void alc882_fixup_no_primary_hp(struct hda_codec *codec,
  4654. const struct alc_fixup *fix, int action)
  4655. {
  4656. struct alc_spec *spec = codec->spec;
  4657. if (action == ALC_FIXUP_ACT_PRE_PROBE)
  4658. spec->no_primary_hp = 1;
  4659. }
  4660. static const struct alc_fixup alc882_fixups[] = {
  4661. [ALC882_FIXUP_ABIT_AW9D_MAX] = {
  4662. .type = ALC_FIXUP_PINS,
  4663. .v.pins = (const struct alc_pincfg[]) {
  4664. { 0x15, 0x01080104 }, /* side */
  4665. { 0x16, 0x01011012 }, /* rear */
  4666. { 0x17, 0x01016011 }, /* clfe */
  4667. { }
  4668. }
  4669. },
  4670. [ALC882_FIXUP_LENOVO_Y530] = {
  4671. .type = ALC_FIXUP_PINS,
  4672. .v.pins = (const struct alc_pincfg[]) {
  4673. { 0x15, 0x99130112 }, /* rear int speakers */
  4674. { 0x16, 0x99130111 }, /* subwoofer */
  4675. { }
  4676. }
  4677. },
  4678. [ALC882_FIXUP_PB_M5210] = {
  4679. .type = ALC_FIXUP_VERBS,
  4680. .v.verbs = (const struct hda_verb[]) {
  4681. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  4682. {}
  4683. }
  4684. },
  4685. [ALC882_FIXUP_ACER_ASPIRE_7736] = {
  4686. .type = ALC_FIXUP_FUNC,
  4687. .v.func = alc_fixup_sku_ignore,
  4688. },
  4689. [ALC882_FIXUP_ASUS_W90V] = {
  4690. .type = ALC_FIXUP_PINS,
  4691. .v.pins = (const struct alc_pincfg[]) {
  4692. { 0x16, 0x99130110 }, /* fix sequence for CLFE */
  4693. { }
  4694. }
  4695. },
  4696. [ALC889_FIXUP_CD] = {
  4697. .type = ALC_FIXUP_PINS,
  4698. .v.pins = (const struct alc_pincfg[]) {
  4699. { 0x1c, 0x993301f0 }, /* CD */
  4700. { }
  4701. }
  4702. },
  4703. [ALC889_FIXUP_VAIO_TT] = {
  4704. .type = ALC_FIXUP_PINS,
  4705. .v.pins = (const struct alc_pincfg[]) {
  4706. { 0x17, 0x90170111 }, /* hidden surround speaker */
  4707. { }
  4708. }
  4709. },
  4710. [ALC888_FIXUP_EEE1601] = {
  4711. .type = ALC_FIXUP_VERBS,
  4712. .v.verbs = (const struct hda_verb[]) {
  4713. { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
  4714. { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
  4715. { }
  4716. }
  4717. },
  4718. [ALC882_FIXUP_EAPD] = {
  4719. .type = ALC_FIXUP_VERBS,
  4720. .v.verbs = (const struct hda_verb[]) {
  4721. /* change to EAPD mode */
  4722. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4723. { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
  4724. { }
  4725. }
  4726. },
  4727. [ALC883_FIXUP_EAPD] = {
  4728. .type = ALC_FIXUP_VERBS,
  4729. .v.verbs = (const struct hda_verb[]) {
  4730. /* change to EAPD mode */
  4731. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4732. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  4733. { }
  4734. }
  4735. },
  4736. [ALC883_FIXUP_ACER_EAPD] = {
  4737. .type = ALC_FIXUP_VERBS,
  4738. .v.verbs = (const struct hda_verb[]) {
  4739. /* eanable EAPD on Acer laptops */
  4740. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4741. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4742. { }
  4743. }
  4744. },
  4745. [ALC882_FIXUP_GPIO1] = {
  4746. .type = ALC_FIXUP_VERBS,
  4747. .v.verbs = alc_gpio1_init_verbs,
  4748. },
  4749. [ALC882_FIXUP_GPIO2] = {
  4750. .type = ALC_FIXUP_VERBS,
  4751. .v.verbs = alc_gpio2_init_verbs,
  4752. },
  4753. [ALC882_FIXUP_GPIO3] = {
  4754. .type = ALC_FIXUP_VERBS,
  4755. .v.verbs = alc_gpio3_init_verbs,
  4756. },
  4757. [ALC882_FIXUP_ASUS_W2JC] = {
  4758. .type = ALC_FIXUP_VERBS,
  4759. .v.verbs = alc_gpio1_init_verbs,
  4760. .chained = true,
  4761. .chain_id = ALC882_FIXUP_EAPD,
  4762. },
  4763. [ALC889_FIXUP_COEF] = {
  4764. .type = ALC_FIXUP_FUNC,
  4765. .v.func = alc889_fixup_coef,
  4766. },
  4767. [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
  4768. .type = ALC_FIXUP_PINS,
  4769. .v.pins = (const struct alc_pincfg[]) {
  4770. { 0x16, 0x99130111 }, /* CLFE speaker */
  4771. { 0x17, 0x99130112 }, /* surround speaker */
  4772. { }
  4773. },
  4774. .chained = true,
  4775. .chain_id = ALC882_FIXUP_GPIO1,
  4776. },
  4777. [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
  4778. .type = ALC_FIXUP_PINS,
  4779. .v.pins = (const struct alc_pincfg[]) {
  4780. { 0x16, 0x99130111 }, /* CLFE speaker */
  4781. { 0x1b, 0x99130112 }, /* surround speaker */
  4782. { }
  4783. },
  4784. .chained = true,
  4785. .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
  4786. },
  4787. [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
  4788. /* additional init verbs for Acer Aspire 8930G */
  4789. .type = ALC_FIXUP_VERBS,
  4790. .v.verbs = (const struct hda_verb[]) {
  4791. /* Enable all DACs */
  4792. /* DAC DISABLE/MUTE 1? */
  4793. /* setting bits 1-5 disables DAC nids 0x02-0x06
  4794. * apparently. Init=0x38 */
  4795. { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
  4796. { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
  4797. /* DAC DISABLE/MUTE 2? */
  4798. /* some bit here disables the other DACs.
  4799. * Init=0x4900 */
  4800. { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
  4801. { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
  4802. /* DMIC fix
  4803. * This laptop has a stereo digital microphone.
  4804. * The mics are only 1cm apart which makes the stereo
  4805. * useless. However, either the mic or the ALC889
  4806. * makes the signal become a difference/sum signal
  4807. * instead of standard stereo, which is annoying.
  4808. * So instead we flip this bit which makes the
  4809. * codec replicate the sum signal to both channels,
  4810. * turning it into a normal mono mic.
  4811. */
  4812. /* DMIC_CONTROL? Init value = 0x0001 */
  4813. { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
  4814. { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
  4815. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  4816. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  4817. { }
  4818. },
  4819. .chained = true,
  4820. .chain_id = ALC882_FIXUP_GPIO1,
  4821. },
  4822. [ALC885_FIXUP_MACPRO_GPIO] = {
  4823. .type = ALC_FIXUP_FUNC,
  4824. .v.func = alc885_fixup_macpro_gpio,
  4825. },
  4826. [ALC889_FIXUP_DAC_ROUTE] = {
  4827. .type = ALC_FIXUP_FUNC,
  4828. .v.func = alc889_fixup_dac_route,
  4829. },
  4830. [ALC889_FIXUP_MBP_VREF] = {
  4831. .type = ALC_FIXUP_FUNC,
  4832. .v.func = alc889_fixup_mbp_vref,
  4833. .chained = true,
  4834. .chain_id = ALC882_FIXUP_GPIO1,
  4835. },
  4836. [ALC889_FIXUP_IMAC91_VREF] = {
  4837. .type = ALC_FIXUP_FUNC,
  4838. .v.func = alc889_fixup_imac91_vref,
  4839. .chained = true,
  4840. .chain_id = ALC882_FIXUP_GPIO1,
  4841. },
  4842. [ALC882_FIXUP_INV_DMIC] = {
  4843. .type = ALC_FIXUP_FUNC,
  4844. .v.func = alc_fixup_inv_dmic_0x12,
  4845. },
  4846. [ALC882_FIXUP_NO_PRIMARY_HP] = {
  4847. .type = ALC_FIXUP_FUNC,
  4848. .v.func = alc882_fixup_no_primary_hp,
  4849. },
  4850. };
  4851. static const struct snd_pci_quirk alc882_fixup_tbl[] = {
  4852. SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
  4853. SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
  4854. SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
  4855. SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
  4856. SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
  4857. SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
  4858. SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
  4859. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4860. SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
  4861. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4862. SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
  4863. ALC882_FIXUP_ACER_ASPIRE_8930G),
  4864. SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
  4865. ALC882_FIXUP_ACER_ASPIRE_8930G),
  4866. SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
  4867. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4868. SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
  4869. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4870. SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
  4871. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4872. SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
  4873. SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
  4874. ALC882_FIXUP_ACER_ASPIRE_4930G),
  4875. SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
  4876. SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
  4877. SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
  4878. SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
  4879. SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
  4880. SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
  4881. SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
  4882. SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
  4883. SND_PCI_QUIRK(0x104d, 0x905a, "Sony Vaio Z", ALC882_FIXUP_NO_PRIMARY_HP),
  4884. /* All Apple entries are in codec SSIDs */
  4885. SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
  4886. SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
  4887. SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
  4888. SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
  4889. SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
  4890. SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
  4891. SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
  4892. SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
  4893. SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
  4894. SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
  4895. SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
  4896. SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
  4897. SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
  4898. SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
  4899. SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
  4900. SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
  4901. SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
  4902. SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
  4903. SND_PCI_QUIRK(0x106b, 0x4300, "iMac 9,1", ALC889_FIXUP_IMAC91_VREF),
  4904. SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
  4905. SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
  4906. SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
  4907. SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
  4908. SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
  4909. SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
  4910. SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
  4911. SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
  4912. SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
  4913. SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
  4914. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
  4915. SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
  4916. {}
  4917. };
  4918. static const struct alc_model_fixup alc882_fixup_models[] = {
  4919. {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
  4920. {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
  4921. {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
  4922. {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
  4923. {.id = ALC882_FIXUP_NO_PRIMARY_HP, .name = "no-primary-hp"},
  4924. {}
  4925. };
  4926. /*
  4927. * BIOS auto configuration
  4928. */
  4929. /* almost identical with ALC880 parser... */
  4930. static int alc882_parse_auto_config(struct hda_codec *codec)
  4931. {
  4932. static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
  4933. static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4934. return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
  4935. }
  4936. /*
  4937. */
  4938. static int patch_alc882(struct hda_codec *codec)
  4939. {
  4940. struct alc_spec *spec;
  4941. int err;
  4942. err = alc_alloc_spec(codec, 0x0b);
  4943. if (err < 0)
  4944. return err;
  4945. spec = codec->spec;
  4946. switch (codec->vendor_id) {
  4947. case 0x10ec0882:
  4948. case 0x10ec0885:
  4949. break;
  4950. default:
  4951. /* ALC883 and variants */
  4952. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  4953. break;
  4954. }
  4955. alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
  4956. alc882_fixups);
  4957. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4958. alc_auto_parse_customize_define(codec);
  4959. /* automatic parse from the BIOS config */
  4960. err = alc882_parse_auto_config(codec);
  4961. if (err < 0)
  4962. goto error;
  4963. if (!spec->no_analog && has_cdefine_beep(codec)) {
  4964. err = snd_hda_attach_beep_device(codec, 0x1);
  4965. if (err < 0)
  4966. goto error;
  4967. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4968. }
  4969. codec->patch_ops = alc_patch_ops;
  4970. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4971. return 0;
  4972. error:
  4973. alc_free(codec);
  4974. return err;
  4975. }
  4976. /*
  4977. * ALC262 support
  4978. */
  4979. static int alc262_parse_auto_config(struct hda_codec *codec)
  4980. {
  4981. static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
  4982. static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4983. return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
  4984. }
  4985. /*
  4986. * Pin config fixes
  4987. */
  4988. enum {
  4989. ALC262_FIXUP_FSC_H270,
  4990. ALC262_FIXUP_HP_Z200,
  4991. ALC262_FIXUP_TYAN,
  4992. ALC262_FIXUP_LENOVO_3000,
  4993. ALC262_FIXUP_BENQ,
  4994. ALC262_FIXUP_BENQ_T31,
  4995. ALC262_FIXUP_INV_DMIC,
  4996. };
  4997. static const struct alc_fixup alc262_fixups[] = {
  4998. [ALC262_FIXUP_FSC_H270] = {
  4999. .type = ALC_FIXUP_PINS,
  5000. .v.pins = (const struct alc_pincfg[]) {
  5001. { 0x14, 0x99130110 }, /* speaker */
  5002. { 0x15, 0x0221142f }, /* front HP */
  5003. { 0x1b, 0x0121141f }, /* rear HP */
  5004. { }
  5005. }
  5006. },
  5007. [ALC262_FIXUP_HP_Z200] = {
  5008. .type = ALC_FIXUP_PINS,
  5009. .v.pins = (const struct alc_pincfg[]) {
  5010. { 0x16, 0x99130120 }, /* internal speaker */
  5011. { }
  5012. }
  5013. },
  5014. [ALC262_FIXUP_TYAN] = {
  5015. .type = ALC_FIXUP_PINS,
  5016. .v.pins = (const struct alc_pincfg[]) {
  5017. { 0x14, 0x1993e1f0 }, /* int AUX */
  5018. { }
  5019. }
  5020. },
  5021. [ALC262_FIXUP_LENOVO_3000] = {
  5022. .type = ALC_FIXUP_VERBS,
  5023. .v.verbs = (const struct hda_verb[]) {
  5024. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  5025. {}
  5026. },
  5027. .chained = true,
  5028. .chain_id = ALC262_FIXUP_BENQ,
  5029. },
  5030. [ALC262_FIXUP_BENQ] = {
  5031. .type = ALC_FIXUP_VERBS,
  5032. .v.verbs = (const struct hda_verb[]) {
  5033. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  5034. { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
  5035. {}
  5036. }
  5037. },
  5038. [ALC262_FIXUP_BENQ_T31] = {
  5039. .type = ALC_FIXUP_VERBS,
  5040. .v.verbs = (const struct hda_verb[]) {
  5041. { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
  5042. { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
  5043. {}
  5044. }
  5045. },
  5046. [ALC262_FIXUP_INV_DMIC] = {
  5047. .type = ALC_FIXUP_FUNC,
  5048. .v.func = alc_fixup_inv_dmic_0x12,
  5049. },
  5050. };
  5051. static const struct snd_pci_quirk alc262_fixup_tbl[] = {
  5052. SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
  5053. SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
  5054. SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
  5055. SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
  5056. SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
  5057. SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
  5058. SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
  5059. SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
  5060. {}
  5061. };
  5062. static const struct alc_model_fixup alc262_fixup_models[] = {
  5063. {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
  5064. {}
  5065. };
  5066. /*
  5067. */
  5068. static int patch_alc262(struct hda_codec *codec)
  5069. {
  5070. struct alc_spec *spec;
  5071. int err;
  5072. err = alc_alloc_spec(codec, 0x0b);
  5073. if (err < 0)
  5074. return err;
  5075. spec = codec->spec;
  5076. #if 0
  5077. /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
  5078. * under-run
  5079. */
  5080. {
  5081. int tmp;
  5082. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  5083. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  5084. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  5085. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
  5086. }
  5087. #endif
  5088. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  5089. alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
  5090. alc262_fixups);
  5091. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5092. alc_auto_parse_customize_define(codec);
  5093. /* automatic parse from the BIOS config */
  5094. err = alc262_parse_auto_config(codec);
  5095. if (err < 0)
  5096. goto error;
  5097. if (!spec->no_analog && has_cdefine_beep(codec)) {
  5098. err = snd_hda_attach_beep_device(codec, 0x1);
  5099. if (err < 0)
  5100. goto error;
  5101. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  5102. }
  5103. codec->patch_ops = alc_patch_ops;
  5104. spec->shutup = alc_eapd_shutup;
  5105. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5106. return 0;
  5107. error:
  5108. alc_free(codec);
  5109. return err;
  5110. }
  5111. /*
  5112. * ALC268
  5113. */
  5114. /* bind Beep switches of both NID 0x0f and 0x10 */
  5115. static const struct hda_bind_ctls alc268_bind_beep_sw = {
  5116. .ops = &snd_hda_bind_sw,
  5117. .values = {
  5118. HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
  5119. HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
  5120. 0
  5121. },
  5122. };
  5123. static const struct snd_kcontrol_new alc268_beep_mixer[] = {
  5124. HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
  5125. HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
  5126. { }
  5127. };
  5128. /* set PCBEEP vol = 0, mute connections */
  5129. static const struct hda_verb alc268_beep_init_verbs[] = {
  5130. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  5131. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  5132. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  5133. { }
  5134. };
  5135. enum {
  5136. ALC268_FIXUP_INV_DMIC,
  5137. ALC268_FIXUP_HP_EAPD,
  5138. };
  5139. static const struct alc_fixup alc268_fixups[] = {
  5140. [ALC268_FIXUP_INV_DMIC] = {
  5141. .type = ALC_FIXUP_FUNC,
  5142. .v.func = alc_fixup_inv_dmic_0x12,
  5143. },
  5144. [ALC268_FIXUP_HP_EAPD] = {
  5145. .type = ALC_FIXUP_VERBS,
  5146. .v.verbs = (const struct hda_verb[]) {
  5147. {0x15, AC_VERB_SET_EAPD_BTLENABLE, 0},
  5148. {}
  5149. }
  5150. },
  5151. };
  5152. static const struct alc_model_fixup alc268_fixup_models[] = {
  5153. {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
  5154. {.id = ALC268_FIXUP_HP_EAPD, .name = "hp-eapd"},
  5155. {}
  5156. };
  5157. static const struct snd_pci_quirk alc268_fixup_tbl[] = {
  5158. /* below is codec SSID since multiple Toshiba laptops have the
  5159. * same PCI SSID 1179:ff00
  5160. */
  5161. SND_PCI_QUIRK(0x1179, 0xff06, "Toshiba P200", ALC268_FIXUP_HP_EAPD),
  5162. {}
  5163. };
  5164. /*
  5165. * BIOS auto configuration
  5166. */
  5167. static int alc268_parse_auto_config(struct hda_codec *codec)
  5168. {
  5169. static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5170. struct alc_spec *spec = codec->spec;
  5171. int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
  5172. if (err > 0) {
  5173. if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
  5174. add_mixer(spec, alc268_beep_mixer);
  5175. snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
  5176. }
  5177. }
  5178. return err;
  5179. }
  5180. /*
  5181. */
  5182. static int patch_alc268(struct hda_codec *codec)
  5183. {
  5184. struct alc_spec *spec;
  5185. int i, has_beep, err;
  5186. /* ALC268 has no aa-loopback mixer */
  5187. err = alc_alloc_spec(codec, 0);
  5188. if (err < 0)
  5189. return err;
  5190. spec = codec->spec;
  5191. alc_pick_fixup(codec, alc268_fixup_models, alc268_fixup_tbl, alc268_fixups);
  5192. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5193. /* automatic parse from the BIOS config */
  5194. err = alc268_parse_auto_config(codec);
  5195. if (err < 0)
  5196. goto error;
  5197. has_beep = 0;
  5198. for (i = 0; i < spec->num_mixers; i++) {
  5199. if (spec->mixers[i] == alc268_beep_mixer) {
  5200. has_beep = 1;
  5201. break;
  5202. }
  5203. }
  5204. if (has_beep) {
  5205. err = snd_hda_attach_beep_device(codec, 0x1);
  5206. if (err < 0)
  5207. goto error;
  5208. if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
  5209. /* override the amp caps for beep generator */
  5210. snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
  5211. (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
  5212. (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
  5213. (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  5214. (0 << AC_AMPCAP_MUTE_SHIFT));
  5215. }
  5216. codec->patch_ops = alc_patch_ops;
  5217. spec->shutup = alc_eapd_shutup;
  5218. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5219. return 0;
  5220. error:
  5221. alc_free(codec);
  5222. return err;
  5223. }
  5224. /*
  5225. * ALC269
  5226. */
  5227. static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
  5228. .substreams = 1,
  5229. .channels_min = 2,
  5230. .channels_max = 8,
  5231. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  5232. /* NID is set in alc_build_pcms */
  5233. .ops = {
  5234. .open = alc_playback_pcm_open,
  5235. .prepare = alc_playback_pcm_prepare,
  5236. .cleanup = alc_playback_pcm_cleanup
  5237. },
  5238. };
  5239. static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
  5240. .substreams = 1,
  5241. .channels_min = 2,
  5242. .channels_max = 2,
  5243. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  5244. /* NID is set in alc_build_pcms */
  5245. };
  5246. /* different alc269-variants */
  5247. enum {
  5248. ALC269_TYPE_ALC269VA,
  5249. ALC269_TYPE_ALC269VB,
  5250. ALC269_TYPE_ALC269VC,
  5251. ALC269_TYPE_ALC269VD,
  5252. };
  5253. /*
  5254. * BIOS auto configuration
  5255. */
  5256. static int alc269_parse_auto_config(struct hda_codec *codec)
  5257. {
  5258. static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
  5259. static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
  5260. static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5261. struct alc_spec *spec = codec->spec;
  5262. const hda_nid_t *ssids;
  5263. switch (spec->codec_variant) {
  5264. case ALC269_TYPE_ALC269VA:
  5265. case ALC269_TYPE_ALC269VC:
  5266. ssids = alc269va_ssids;
  5267. break;
  5268. case ALC269_TYPE_ALC269VB:
  5269. case ALC269_TYPE_ALC269VD:
  5270. ssids = alc269_ssids;
  5271. break;
  5272. default:
  5273. ssids = alc269_ssids;
  5274. break;
  5275. }
  5276. return alc_parse_auto_config(codec, alc269_ignore, ssids);
  5277. }
  5278. static void alc269vb_toggle_power_output(struct hda_codec *codec, int power_up)
  5279. {
  5280. int val = alc_read_coef_idx(codec, 0x04);
  5281. if (power_up)
  5282. val |= 1 << 11;
  5283. else
  5284. val &= ~(1 << 11);
  5285. alc_write_coef_idx(codec, 0x04, val);
  5286. }
  5287. static void alc269_shutup(struct hda_codec *codec)
  5288. {
  5289. struct alc_spec *spec = codec->spec;
  5290. if (spec->codec_variant != ALC269_TYPE_ALC269VB)
  5291. return;
  5292. if (spec->codec_variant == ALC269_TYPE_ALC269VB)
  5293. alc269vb_toggle_power_output(codec, 0);
  5294. if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
  5295. (alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5296. msleep(150);
  5297. }
  5298. }
  5299. #ifdef CONFIG_PM
  5300. static int alc269_resume(struct hda_codec *codec)
  5301. {
  5302. struct alc_spec *spec = codec->spec;
  5303. if (spec->codec_variant == ALC269_TYPE_ALC269VB)
  5304. alc269vb_toggle_power_output(codec, 0);
  5305. if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
  5306. (alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5307. msleep(150);
  5308. }
  5309. codec->patch_ops.init(codec);
  5310. if (spec->codec_variant == ALC269_TYPE_ALC269VB)
  5311. alc269vb_toggle_power_output(codec, 1);
  5312. if (spec->codec_variant == ALC269_TYPE_ALC269VB &&
  5313. (alc_get_coef0(codec) & 0x00ff) == 0x017) {
  5314. msleep(200);
  5315. }
  5316. snd_hda_codec_resume_amp(codec);
  5317. snd_hda_codec_resume_cache(codec);
  5318. hda_call_check_power_status(codec, 0x01);
  5319. return 0;
  5320. }
  5321. #endif /* CONFIG_PM */
  5322. static void alc269_fixup_pincfg_no_hp_to_lineout(struct hda_codec *codec,
  5323. const struct alc_fixup *fix, int action)
  5324. {
  5325. struct alc_spec *spec = codec->spec;
  5326. if (action == ALC_FIXUP_ACT_PRE_PROBE)
  5327. spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
  5328. }
  5329. static void alc269_fixup_hweq(struct hda_codec *codec,
  5330. const struct alc_fixup *fix, int action)
  5331. {
  5332. int coef;
  5333. if (action != ALC_FIXUP_ACT_INIT)
  5334. return;
  5335. coef = alc_read_coef_idx(codec, 0x1e);
  5336. alc_write_coef_idx(codec, 0x1e, coef | 0x80);
  5337. }
  5338. static void alc271_fixup_dmic(struct hda_codec *codec,
  5339. const struct alc_fixup *fix, int action)
  5340. {
  5341. static const struct hda_verb verbs[] = {
  5342. {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
  5343. {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
  5344. {}
  5345. };
  5346. unsigned int cfg;
  5347. if (strcmp(codec->chip_name, "ALC271X"))
  5348. return;
  5349. cfg = snd_hda_codec_get_pincfg(codec, 0x12);
  5350. if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
  5351. snd_hda_sequence_write(codec, verbs);
  5352. }
  5353. static void alc269_fixup_pcm_44k(struct hda_codec *codec,
  5354. const struct alc_fixup *fix, int action)
  5355. {
  5356. struct alc_spec *spec = codec->spec;
  5357. if (action != ALC_FIXUP_ACT_PROBE)
  5358. return;
  5359. /* Due to a hardware problem on Lenovo Ideadpad, we need to
  5360. * fix the sample rate of analog I/O to 44.1kHz
  5361. */
  5362. spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
  5363. spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
  5364. }
  5365. static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
  5366. const struct alc_fixup *fix, int action)
  5367. {
  5368. int coef;
  5369. if (action != ALC_FIXUP_ACT_INIT)
  5370. return;
  5371. /* The digital-mic unit sends PDM (differential signal) instead of
  5372. * the standard PCM, thus you can't record a valid mono stream as is.
  5373. * Below is a workaround specific to ALC269 to control the dmic
  5374. * signal source as mono.
  5375. */
  5376. coef = alc_read_coef_idx(codec, 0x07);
  5377. alc_write_coef_idx(codec, 0x07, coef | 0x80);
  5378. }
  5379. static void alc269_quanta_automute(struct hda_codec *codec)
  5380. {
  5381. update_outputs(codec);
  5382. snd_hda_codec_write(codec, 0x20, 0,
  5383. AC_VERB_SET_COEF_INDEX, 0x0c);
  5384. snd_hda_codec_write(codec, 0x20, 0,
  5385. AC_VERB_SET_PROC_COEF, 0x680);
  5386. snd_hda_codec_write(codec, 0x20, 0,
  5387. AC_VERB_SET_COEF_INDEX, 0x0c);
  5388. snd_hda_codec_write(codec, 0x20, 0,
  5389. AC_VERB_SET_PROC_COEF, 0x480);
  5390. }
  5391. static void alc269_fixup_quanta_mute(struct hda_codec *codec,
  5392. const struct alc_fixup *fix, int action)
  5393. {
  5394. struct alc_spec *spec = codec->spec;
  5395. if (action != ALC_FIXUP_ACT_PROBE)
  5396. return;
  5397. spec->automute_hook = alc269_quanta_automute;
  5398. }
  5399. /* update mute-LED according to the speaker mute state via mic2 VREF pin */
  5400. static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
  5401. {
  5402. struct hda_codec *codec = private_data;
  5403. unsigned int pinval = enabled ? 0x20 : 0x24;
  5404. snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
  5405. }
  5406. static void alc269_fixup_mic2_mute(struct hda_codec *codec,
  5407. const struct alc_fixup *fix, int action)
  5408. {
  5409. struct alc_spec *spec = codec->spec;
  5410. switch (action) {
  5411. case ALC_FIXUP_ACT_BUILD:
  5412. spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
  5413. snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
  5414. /* fallthru */
  5415. case ALC_FIXUP_ACT_INIT:
  5416. snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
  5417. break;
  5418. }
  5419. }
  5420. static void alc271_hp_gate_mic_jack(struct hda_codec *codec,
  5421. const struct alc_fixup *fix,
  5422. int action)
  5423. {
  5424. struct alc_spec *spec = codec->spec;
  5425. if (action == ALC_FIXUP_ACT_PROBE)
  5426. snd_hda_jack_set_gating_jack(codec, spec->ext_mic_pin,
  5427. spec->autocfg.hp_pins[0]);
  5428. }
  5429. enum {
  5430. ALC269_FIXUP_SONY_VAIO,
  5431. ALC275_FIXUP_SONY_VAIO_GPIO2,
  5432. ALC269_FIXUP_DELL_M101Z,
  5433. ALC269_FIXUP_SKU_IGNORE,
  5434. ALC269_FIXUP_ASUS_G73JW,
  5435. ALC269_FIXUP_LENOVO_EAPD,
  5436. ALC275_FIXUP_SONY_HWEQ,
  5437. ALC271_FIXUP_DMIC,
  5438. ALC269_FIXUP_PCM_44K,
  5439. ALC269_FIXUP_STEREO_DMIC,
  5440. ALC269_FIXUP_QUANTA_MUTE,
  5441. ALC269_FIXUP_LIFEBOOK,
  5442. ALC269_FIXUP_AMIC,
  5443. ALC269_FIXUP_DMIC,
  5444. ALC269VB_FIXUP_AMIC,
  5445. ALC269VB_FIXUP_DMIC,
  5446. ALC269_FIXUP_MIC2_MUTE_LED,
  5447. ALC269_FIXUP_INV_DMIC,
  5448. ALC269_FIXUP_LENOVO_DOCK,
  5449. ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT,
  5450. ALC271_FIXUP_AMIC_MIC2,
  5451. ALC271_FIXUP_HP_GATE_MIC_JACK,
  5452. };
  5453. static const struct alc_fixup alc269_fixups[] = {
  5454. [ALC269_FIXUP_SONY_VAIO] = {
  5455. .type = ALC_FIXUP_VERBS,
  5456. .v.verbs = (const struct hda_verb[]) {
  5457. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
  5458. {}
  5459. }
  5460. },
  5461. [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
  5462. .type = ALC_FIXUP_VERBS,
  5463. .v.verbs = (const struct hda_verb[]) {
  5464. {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
  5465. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
  5466. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  5467. { }
  5468. },
  5469. .chained = true,
  5470. .chain_id = ALC269_FIXUP_SONY_VAIO
  5471. },
  5472. [ALC269_FIXUP_DELL_M101Z] = {
  5473. .type = ALC_FIXUP_VERBS,
  5474. .v.verbs = (const struct hda_verb[]) {
  5475. /* Enables internal speaker */
  5476. {0x20, AC_VERB_SET_COEF_INDEX, 13},
  5477. {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
  5478. {}
  5479. }
  5480. },
  5481. [ALC269_FIXUP_SKU_IGNORE] = {
  5482. .type = ALC_FIXUP_FUNC,
  5483. .v.func = alc_fixup_sku_ignore,
  5484. },
  5485. [ALC269_FIXUP_ASUS_G73JW] = {
  5486. .type = ALC_FIXUP_PINS,
  5487. .v.pins = (const struct alc_pincfg[]) {
  5488. { 0x17, 0x99130111 }, /* subwoofer */
  5489. { }
  5490. }
  5491. },
  5492. [ALC269_FIXUP_LENOVO_EAPD] = {
  5493. .type = ALC_FIXUP_VERBS,
  5494. .v.verbs = (const struct hda_verb[]) {
  5495. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  5496. {}
  5497. }
  5498. },
  5499. [ALC275_FIXUP_SONY_HWEQ] = {
  5500. .type = ALC_FIXUP_FUNC,
  5501. .v.func = alc269_fixup_hweq,
  5502. .chained = true,
  5503. .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
  5504. },
  5505. [ALC271_FIXUP_DMIC] = {
  5506. .type = ALC_FIXUP_FUNC,
  5507. .v.func = alc271_fixup_dmic,
  5508. },
  5509. [ALC269_FIXUP_PCM_44K] = {
  5510. .type = ALC_FIXUP_FUNC,
  5511. .v.func = alc269_fixup_pcm_44k,
  5512. .chained = true,
  5513. .chain_id = ALC269_FIXUP_QUANTA_MUTE
  5514. },
  5515. [ALC269_FIXUP_STEREO_DMIC] = {
  5516. .type = ALC_FIXUP_FUNC,
  5517. .v.func = alc269_fixup_stereo_dmic,
  5518. },
  5519. [ALC269_FIXUP_QUANTA_MUTE] = {
  5520. .type = ALC_FIXUP_FUNC,
  5521. .v.func = alc269_fixup_quanta_mute,
  5522. },
  5523. [ALC269_FIXUP_LIFEBOOK] = {
  5524. .type = ALC_FIXUP_PINS,
  5525. .v.pins = (const struct alc_pincfg[]) {
  5526. { 0x1a, 0x2101103f }, /* dock line-out */
  5527. { 0x1b, 0x23a11040 }, /* dock mic-in */
  5528. { }
  5529. },
  5530. .chained = true,
  5531. .chain_id = ALC269_FIXUP_QUANTA_MUTE
  5532. },
  5533. [ALC269_FIXUP_AMIC] = {
  5534. .type = ALC_FIXUP_PINS,
  5535. .v.pins = (const struct alc_pincfg[]) {
  5536. { 0x14, 0x99130110 }, /* speaker */
  5537. { 0x15, 0x0121401f }, /* HP out */
  5538. { 0x18, 0x01a19c20 }, /* mic */
  5539. { 0x19, 0x99a3092f }, /* int-mic */
  5540. { }
  5541. },
  5542. },
  5543. [ALC269_FIXUP_DMIC] = {
  5544. .type = ALC_FIXUP_PINS,
  5545. .v.pins = (const struct alc_pincfg[]) {
  5546. { 0x12, 0x99a3092f }, /* int-mic */
  5547. { 0x14, 0x99130110 }, /* speaker */
  5548. { 0x15, 0x0121401f }, /* HP out */
  5549. { 0x18, 0x01a19c20 }, /* mic */
  5550. { }
  5551. },
  5552. },
  5553. [ALC269VB_FIXUP_AMIC] = {
  5554. .type = ALC_FIXUP_PINS,
  5555. .v.pins = (const struct alc_pincfg[]) {
  5556. { 0x14, 0x99130110 }, /* speaker */
  5557. { 0x18, 0x01a19c20 }, /* mic */
  5558. { 0x19, 0x99a3092f }, /* int-mic */
  5559. { 0x21, 0x0121401f }, /* HP out */
  5560. { }
  5561. },
  5562. },
  5563. [ALC269VB_FIXUP_DMIC] = {
  5564. .type = ALC_FIXUP_PINS,
  5565. .v.pins = (const struct alc_pincfg[]) {
  5566. { 0x12, 0x99a3092f }, /* int-mic */
  5567. { 0x14, 0x99130110 }, /* speaker */
  5568. { 0x18, 0x01a19c20 }, /* mic */
  5569. { 0x21, 0x0121401f }, /* HP out */
  5570. { }
  5571. },
  5572. },
  5573. [ALC269_FIXUP_MIC2_MUTE_LED] = {
  5574. .type = ALC_FIXUP_FUNC,
  5575. .v.func = alc269_fixup_mic2_mute,
  5576. },
  5577. [ALC269_FIXUP_INV_DMIC] = {
  5578. .type = ALC_FIXUP_FUNC,
  5579. .v.func = alc_fixup_inv_dmic_0x12,
  5580. },
  5581. [ALC269_FIXUP_LENOVO_DOCK] = {
  5582. .type = ALC_FIXUP_PINS,
  5583. .v.pins = (const struct alc_pincfg[]) {
  5584. { 0x19, 0x23a11040 }, /* dock mic */
  5585. { 0x1b, 0x2121103f }, /* dock headphone */
  5586. { }
  5587. },
  5588. .chained = true,
  5589. .chain_id = ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT
  5590. },
  5591. [ALC269_FIXUP_PINCFG_NO_HP_TO_LINEOUT] = {
  5592. .type = ALC_FIXUP_FUNC,
  5593. .v.func = alc269_fixup_pincfg_no_hp_to_lineout,
  5594. },
  5595. [ALC271_FIXUP_AMIC_MIC2] = {
  5596. .type = ALC_FIXUP_PINS,
  5597. .v.pins = (const struct alc_pincfg[]) {
  5598. { 0x14, 0x99130110 }, /* speaker */
  5599. { 0x19, 0x01a19c20 }, /* mic */
  5600. { 0x1b, 0x99a7012f }, /* int-mic */
  5601. { 0x21, 0x0121401f }, /* HP out */
  5602. { }
  5603. },
  5604. },
  5605. [ALC271_FIXUP_HP_GATE_MIC_JACK] = {
  5606. .type = ALC_FIXUP_FUNC,
  5607. .v.func = alc271_hp_gate_mic_jack,
  5608. .chained = true,
  5609. .chain_id = ALC271_FIXUP_AMIC_MIC2,
  5610. },
  5611. };
  5612. static const struct snd_pci_quirk alc269_fixup_tbl[] = {
  5613. SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
  5614. SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
  5615. SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
  5616. SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
  5617. SND_PCI_QUIRK(0x1043, 0x1517, "Asus Zenbook UX31A", ALC269VB_FIXUP_DMIC),
  5618. SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
  5619. SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
  5620. SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
  5621. SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
  5622. SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
  5623. SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
  5624. SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
  5625. SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
  5626. SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  5627. SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  5628. SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
  5629. SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
  5630. SND_PCI_QUIRK(0x1025, 0x0742, "Acer AO756", ALC271_FIXUP_HP_GATE_MIC_JACK),
  5631. SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
  5632. SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
  5633. SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
  5634. SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
  5635. SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
  5636. SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
  5637. SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
  5638. SND_PCI_QUIRK(0x17aa, 0x21f6, "Thinkpad T530", ALC269_FIXUP_LENOVO_DOCK),
  5639. SND_PCI_QUIRK(0x17aa, 0x21fa, "Thinkpad X230", ALC269_FIXUP_LENOVO_DOCK),
  5640. SND_PCI_QUIRK(0x17aa, 0x21f3, "Thinkpad T430", ALC269_FIXUP_LENOVO_DOCK),
  5641. SND_PCI_QUIRK(0x17aa, 0x21fb, "Thinkpad T430s", ALC269_FIXUP_LENOVO_DOCK),
  5642. SND_PCI_QUIRK(0x17aa, 0x2203, "Thinkpad X230 Tablet", ALC269_FIXUP_LENOVO_DOCK),
  5643. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K),
  5644. SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
  5645. #if 0
  5646. /* Below is a quirk table taken from the old code.
  5647. * Basically the device should work as is without the fixup table.
  5648. * If BIOS doesn't give a proper info, enable the corresponding
  5649. * fixup entry.
  5650. */
  5651. SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
  5652. ALC269_FIXUP_AMIC),
  5653. SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
  5654. SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
  5655. SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
  5656. SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
  5657. SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
  5658. SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
  5659. SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
  5660. SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
  5661. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
  5662. SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
  5663. SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
  5664. SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
  5665. SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
  5666. SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
  5667. SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
  5668. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
  5669. SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
  5670. SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
  5671. SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
  5672. SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
  5673. SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
  5674. SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
  5675. SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
  5676. SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
  5677. SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
  5678. SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
  5679. SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
  5680. SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
  5681. SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
  5682. SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
  5683. SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
  5684. SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
  5685. SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
  5686. SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
  5687. SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
  5688. SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
  5689. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
  5690. SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
  5691. SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
  5692. #endif
  5693. {}
  5694. };
  5695. static const struct alc_model_fixup alc269_fixup_models[] = {
  5696. {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
  5697. {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
  5698. {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
  5699. {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
  5700. {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
  5701. {.id = ALC269_FIXUP_LENOVO_DOCK, .name = "lenovo-dock"},
  5702. {}
  5703. };
  5704. static void alc269_fill_coef(struct hda_codec *codec)
  5705. {
  5706. struct alc_spec *spec = codec->spec;
  5707. int val;
  5708. if (spec->codec_variant != ALC269_TYPE_ALC269VB)
  5709. return;
  5710. if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
  5711. alc_write_coef_idx(codec, 0xf, 0x960b);
  5712. alc_write_coef_idx(codec, 0xe, 0x8817);
  5713. }
  5714. if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
  5715. alc_write_coef_idx(codec, 0xf, 0x960b);
  5716. alc_write_coef_idx(codec, 0xe, 0x8814);
  5717. }
  5718. if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
  5719. val = alc_read_coef_idx(codec, 0x04);
  5720. /* Power up output pin */
  5721. alc_write_coef_idx(codec, 0x04, val | (1<<11));
  5722. }
  5723. if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
  5724. val = alc_read_coef_idx(codec, 0xd);
  5725. if ((val & 0x0c00) >> 10 != 0x1) {
  5726. /* Capless ramp up clock control */
  5727. alc_write_coef_idx(codec, 0xd, val | (1<<10));
  5728. }
  5729. val = alc_read_coef_idx(codec, 0x17);
  5730. if ((val & 0x01c0) >> 6 != 0x4) {
  5731. /* Class D power on reset */
  5732. alc_write_coef_idx(codec, 0x17, val | (1<<7));
  5733. }
  5734. }
  5735. val = alc_read_coef_idx(codec, 0xd); /* Class D */
  5736. alc_write_coef_idx(codec, 0xd, val | (1<<14));
  5737. val = alc_read_coef_idx(codec, 0x4); /* HP */
  5738. alc_write_coef_idx(codec, 0x4, val | (1<<11));
  5739. }
  5740. /*
  5741. */
  5742. static int patch_alc269(struct hda_codec *codec)
  5743. {
  5744. struct alc_spec *spec;
  5745. int err;
  5746. err = alc_alloc_spec(codec, 0x0b);
  5747. if (err < 0)
  5748. return err;
  5749. spec = codec->spec;
  5750. alc_pick_fixup(codec, alc269_fixup_models,
  5751. alc269_fixup_tbl, alc269_fixups);
  5752. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5753. alc_auto_parse_customize_define(codec);
  5754. if (codec->vendor_id == 0x10ec0269) {
  5755. spec->codec_variant = ALC269_TYPE_ALC269VA;
  5756. switch (alc_get_coef0(codec) & 0x00f0) {
  5757. case 0x0010:
  5758. if (codec->bus->pci->subsystem_vendor == 0x1025 &&
  5759. spec->cdefine.platform_type == 1)
  5760. err = alc_codec_rename(codec, "ALC271X");
  5761. spec->codec_variant = ALC269_TYPE_ALC269VB;
  5762. break;
  5763. case 0x0020:
  5764. if (codec->bus->pci->subsystem_vendor == 0x17aa &&
  5765. codec->bus->pci->subsystem_device == 0x21f3)
  5766. err = alc_codec_rename(codec, "ALC3202");
  5767. spec->codec_variant = ALC269_TYPE_ALC269VC;
  5768. break;
  5769. case 0x0030:
  5770. spec->codec_variant = ALC269_TYPE_ALC269VD;
  5771. break;
  5772. default:
  5773. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  5774. }
  5775. if (err < 0)
  5776. goto error;
  5777. spec->init_hook = alc269_fill_coef;
  5778. alc269_fill_coef(codec);
  5779. }
  5780. /* automatic parse from the BIOS config */
  5781. err = alc269_parse_auto_config(codec);
  5782. if (err < 0)
  5783. goto error;
  5784. if (!spec->no_analog && has_cdefine_beep(codec)) {
  5785. err = snd_hda_attach_beep_device(codec, 0x1);
  5786. if (err < 0)
  5787. goto error;
  5788. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  5789. }
  5790. codec->patch_ops = alc_patch_ops;
  5791. #ifdef CONFIG_PM
  5792. codec->patch_ops.resume = alc269_resume;
  5793. #endif
  5794. spec->shutup = alc269_shutup;
  5795. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5796. return 0;
  5797. error:
  5798. alc_free(codec);
  5799. return err;
  5800. }
  5801. /*
  5802. * ALC861
  5803. */
  5804. static int alc861_parse_auto_config(struct hda_codec *codec)
  5805. {
  5806. static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
  5807. static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
  5808. return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
  5809. }
  5810. /* Pin config fixes */
  5811. enum {
  5812. ALC861_FIXUP_FSC_AMILO_PI1505,
  5813. ALC861_FIXUP_AMP_VREF_0F,
  5814. ALC861_FIXUP_NO_JACK_DETECT,
  5815. ALC861_FIXUP_ASUS_A6RP,
  5816. };
  5817. /* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
  5818. static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
  5819. const struct alc_fixup *fix, int action)
  5820. {
  5821. struct alc_spec *spec = codec->spec;
  5822. unsigned int val;
  5823. if (action != ALC_FIXUP_ACT_INIT)
  5824. return;
  5825. val = snd_hda_codec_read(codec, 0x0f, 0,
  5826. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  5827. if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
  5828. val |= AC_PINCTL_IN_EN;
  5829. val |= AC_PINCTL_VREF_50;
  5830. snd_hda_set_pin_ctl(codec, 0x0f, val);
  5831. spec->keep_vref_in_automute = 1;
  5832. }
  5833. /* suppress the jack-detection */
  5834. static void alc_fixup_no_jack_detect(struct hda_codec *codec,
  5835. const struct alc_fixup *fix, int action)
  5836. {
  5837. if (action == ALC_FIXUP_ACT_PRE_PROBE)
  5838. codec->no_jack_detect = 1;
  5839. }
  5840. static const struct alc_fixup alc861_fixups[] = {
  5841. [ALC861_FIXUP_FSC_AMILO_PI1505] = {
  5842. .type = ALC_FIXUP_PINS,
  5843. .v.pins = (const struct alc_pincfg[]) {
  5844. { 0x0b, 0x0221101f }, /* HP */
  5845. { 0x0f, 0x90170310 }, /* speaker */
  5846. { }
  5847. }
  5848. },
  5849. [ALC861_FIXUP_AMP_VREF_0F] = {
  5850. .type = ALC_FIXUP_FUNC,
  5851. .v.func = alc861_fixup_asus_amp_vref_0f,
  5852. },
  5853. [ALC861_FIXUP_NO_JACK_DETECT] = {
  5854. .type = ALC_FIXUP_FUNC,
  5855. .v.func = alc_fixup_no_jack_detect,
  5856. },
  5857. [ALC861_FIXUP_ASUS_A6RP] = {
  5858. .type = ALC_FIXUP_FUNC,
  5859. .v.func = alc861_fixup_asus_amp_vref_0f,
  5860. .chained = true,
  5861. .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
  5862. }
  5863. };
  5864. static const struct snd_pci_quirk alc861_fixup_tbl[] = {
  5865. SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
  5866. SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
  5867. SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
  5868. SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
  5869. SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
  5870. SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
  5871. {}
  5872. };
  5873. /*
  5874. */
  5875. static int patch_alc861(struct hda_codec *codec)
  5876. {
  5877. struct alc_spec *spec;
  5878. int err;
  5879. err = alc_alloc_spec(codec, 0x15);
  5880. if (err < 0)
  5881. return err;
  5882. spec = codec->spec;
  5883. alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
  5884. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5885. /* automatic parse from the BIOS config */
  5886. err = alc861_parse_auto_config(codec);
  5887. if (err < 0)
  5888. goto error;
  5889. if (!spec->no_analog) {
  5890. err = snd_hda_attach_beep_device(codec, 0x23);
  5891. if (err < 0)
  5892. goto error;
  5893. set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
  5894. }
  5895. codec->patch_ops = alc_patch_ops;
  5896. #ifdef CONFIG_PM
  5897. spec->power_hook = alc_power_eapd;
  5898. #endif
  5899. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5900. return 0;
  5901. error:
  5902. alc_free(codec);
  5903. return err;
  5904. }
  5905. /*
  5906. * ALC861-VD support
  5907. *
  5908. * Based on ALC882
  5909. *
  5910. * In addition, an independent DAC
  5911. */
  5912. static int alc861vd_parse_auto_config(struct hda_codec *codec)
  5913. {
  5914. static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
  5915. static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  5916. return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
  5917. }
  5918. enum {
  5919. ALC660VD_FIX_ASUS_GPIO1,
  5920. ALC861VD_FIX_DALLAS,
  5921. };
  5922. /* exclude VREF80 */
  5923. static void alc861vd_fixup_dallas(struct hda_codec *codec,
  5924. const struct alc_fixup *fix, int action)
  5925. {
  5926. if (action == ALC_FIXUP_ACT_PRE_PROBE) {
  5927. snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
  5928. snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
  5929. }
  5930. }
  5931. static const struct alc_fixup alc861vd_fixups[] = {
  5932. [ALC660VD_FIX_ASUS_GPIO1] = {
  5933. .type = ALC_FIXUP_VERBS,
  5934. .v.verbs = (const struct hda_verb[]) {
  5935. /* reset GPIO1 */
  5936. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  5937. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  5938. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  5939. { }
  5940. }
  5941. },
  5942. [ALC861VD_FIX_DALLAS] = {
  5943. .type = ALC_FIXUP_FUNC,
  5944. .v.func = alc861vd_fixup_dallas,
  5945. },
  5946. };
  5947. static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
  5948. SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
  5949. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
  5950. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
  5951. {}
  5952. };
  5953. /*
  5954. */
  5955. static int patch_alc861vd(struct hda_codec *codec)
  5956. {
  5957. struct alc_spec *spec;
  5958. int err;
  5959. err = alc_alloc_spec(codec, 0x0b);
  5960. if (err < 0)
  5961. return err;
  5962. spec = codec->spec;
  5963. alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
  5964. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  5965. /* automatic parse from the BIOS config */
  5966. err = alc861vd_parse_auto_config(codec);
  5967. if (err < 0)
  5968. goto error;
  5969. if (!spec->no_analog) {
  5970. err = snd_hda_attach_beep_device(codec, 0x23);
  5971. if (err < 0)
  5972. goto error;
  5973. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  5974. }
  5975. codec->patch_ops = alc_patch_ops;
  5976. spec->shutup = alc_eapd_shutup;
  5977. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  5978. return 0;
  5979. error:
  5980. alc_free(codec);
  5981. return err;
  5982. }
  5983. /*
  5984. * ALC662 support
  5985. *
  5986. * ALC662 is almost identical with ALC880 but has cleaner and more flexible
  5987. * configuration. Each pin widget can choose any input DACs and a mixer.
  5988. * Each ADC is connected from a mixer of all inputs. This makes possible
  5989. * 6-channel independent captures.
  5990. *
  5991. * In addition, an independent DAC for the multi-playback (not used in this
  5992. * driver yet).
  5993. */
  5994. /*
  5995. * BIOS auto configuration
  5996. */
  5997. static int alc662_parse_auto_config(struct hda_codec *codec)
  5998. {
  5999. static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
  6000. static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
  6001. static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  6002. const hda_nid_t *ssids;
  6003. if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
  6004. codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
  6005. ssids = alc663_ssids;
  6006. else
  6007. ssids = alc662_ssids;
  6008. return alc_parse_auto_config(codec, alc662_ignore, ssids);
  6009. }
  6010. static void alc272_fixup_mario(struct hda_codec *codec,
  6011. const struct alc_fixup *fix, int action)
  6012. {
  6013. if (action != ALC_FIXUP_ACT_PROBE)
  6014. return;
  6015. if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
  6016. (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
  6017. (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
  6018. (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  6019. (0 << AC_AMPCAP_MUTE_SHIFT)))
  6020. printk(KERN_WARNING
  6021. "hda_codec: failed to override amp caps for NID 0x2\n");
  6022. }
  6023. enum {
  6024. ALC662_FIXUP_ASPIRE,
  6025. ALC662_FIXUP_IDEAPAD,
  6026. ALC272_FIXUP_MARIO,
  6027. ALC662_FIXUP_CZC_P10T,
  6028. ALC662_FIXUP_SKU_IGNORE,
  6029. ALC662_FIXUP_HP_RP5800,
  6030. ALC662_FIXUP_ASUS_MODE1,
  6031. ALC662_FIXUP_ASUS_MODE2,
  6032. ALC662_FIXUP_ASUS_MODE3,
  6033. ALC662_FIXUP_ASUS_MODE4,
  6034. ALC662_FIXUP_ASUS_MODE5,
  6035. ALC662_FIXUP_ASUS_MODE6,
  6036. ALC662_FIXUP_ASUS_MODE7,
  6037. ALC662_FIXUP_ASUS_MODE8,
  6038. ALC662_FIXUP_NO_JACK_DETECT,
  6039. ALC662_FIXUP_ZOTAC_Z68,
  6040. ALC662_FIXUP_INV_DMIC,
  6041. };
  6042. static const struct alc_fixup alc662_fixups[] = {
  6043. [ALC662_FIXUP_ASPIRE] = {
  6044. .type = ALC_FIXUP_PINS,
  6045. .v.pins = (const struct alc_pincfg[]) {
  6046. { 0x15, 0x99130112 }, /* subwoofer */
  6047. { }
  6048. }
  6049. },
  6050. [ALC662_FIXUP_IDEAPAD] = {
  6051. .type = ALC_FIXUP_PINS,
  6052. .v.pins = (const struct alc_pincfg[]) {
  6053. { 0x17, 0x99130112 }, /* subwoofer */
  6054. { }
  6055. }
  6056. },
  6057. [ALC272_FIXUP_MARIO] = {
  6058. .type = ALC_FIXUP_FUNC,
  6059. .v.func = alc272_fixup_mario,
  6060. },
  6061. [ALC662_FIXUP_CZC_P10T] = {
  6062. .type = ALC_FIXUP_VERBS,
  6063. .v.verbs = (const struct hda_verb[]) {
  6064. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  6065. {}
  6066. }
  6067. },
  6068. [ALC662_FIXUP_SKU_IGNORE] = {
  6069. .type = ALC_FIXUP_FUNC,
  6070. .v.func = alc_fixup_sku_ignore,
  6071. },
  6072. [ALC662_FIXUP_HP_RP5800] = {
  6073. .type = ALC_FIXUP_PINS,
  6074. .v.pins = (const struct alc_pincfg[]) {
  6075. { 0x14, 0x0221201f }, /* HP out */
  6076. { }
  6077. },
  6078. .chained = true,
  6079. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6080. },
  6081. [ALC662_FIXUP_ASUS_MODE1] = {
  6082. .type = ALC_FIXUP_PINS,
  6083. .v.pins = (const struct alc_pincfg[]) {
  6084. { 0x14, 0x99130110 }, /* speaker */
  6085. { 0x18, 0x01a19c20 }, /* mic */
  6086. { 0x19, 0x99a3092f }, /* int-mic */
  6087. { 0x21, 0x0121401f }, /* HP out */
  6088. { }
  6089. },
  6090. .chained = true,
  6091. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6092. },
  6093. [ALC662_FIXUP_ASUS_MODE2] = {
  6094. .type = ALC_FIXUP_PINS,
  6095. .v.pins = (const struct alc_pincfg[]) {
  6096. { 0x14, 0x99130110 }, /* speaker */
  6097. { 0x18, 0x01a19820 }, /* mic */
  6098. { 0x19, 0x99a3092f }, /* int-mic */
  6099. { 0x1b, 0x0121401f }, /* HP out */
  6100. { }
  6101. },
  6102. .chained = true,
  6103. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6104. },
  6105. [ALC662_FIXUP_ASUS_MODE3] = {
  6106. .type = ALC_FIXUP_PINS,
  6107. .v.pins = (const struct alc_pincfg[]) {
  6108. { 0x14, 0x99130110 }, /* speaker */
  6109. { 0x15, 0x0121441f }, /* HP */
  6110. { 0x18, 0x01a19840 }, /* mic */
  6111. { 0x19, 0x99a3094f }, /* int-mic */
  6112. { 0x21, 0x01211420 }, /* HP2 */
  6113. { }
  6114. },
  6115. .chained = true,
  6116. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6117. },
  6118. [ALC662_FIXUP_ASUS_MODE4] = {
  6119. .type = ALC_FIXUP_PINS,
  6120. .v.pins = (const struct alc_pincfg[]) {
  6121. { 0x14, 0x99130110 }, /* speaker */
  6122. { 0x16, 0x99130111 }, /* speaker */
  6123. { 0x18, 0x01a19840 }, /* mic */
  6124. { 0x19, 0x99a3094f }, /* int-mic */
  6125. { 0x21, 0x0121441f }, /* HP */
  6126. { }
  6127. },
  6128. .chained = true,
  6129. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6130. },
  6131. [ALC662_FIXUP_ASUS_MODE5] = {
  6132. .type = ALC_FIXUP_PINS,
  6133. .v.pins = (const struct alc_pincfg[]) {
  6134. { 0x14, 0x99130110 }, /* speaker */
  6135. { 0x15, 0x0121441f }, /* HP */
  6136. { 0x16, 0x99130111 }, /* speaker */
  6137. { 0x18, 0x01a19840 }, /* mic */
  6138. { 0x19, 0x99a3094f }, /* int-mic */
  6139. { }
  6140. },
  6141. .chained = true,
  6142. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6143. },
  6144. [ALC662_FIXUP_ASUS_MODE6] = {
  6145. .type = ALC_FIXUP_PINS,
  6146. .v.pins = (const struct alc_pincfg[]) {
  6147. { 0x14, 0x99130110 }, /* speaker */
  6148. { 0x15, 0x01211420 }, /* HP2 */
  6149. { 0x18, 0x01a19840 }, /* mic */
  6150. { 0x19, 0x99a3094f }, /* int-mic */
  6151. { 0x1b, 0x0121441f }, /* HP */
  6152. { }
  6153. },
  6154. .chained = true,
  6155. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6156. },
  6157. [ALC662_FIXUP_ASUS_MODE7] = {
  6158. .type = ALC_FIXUP_PINS,
  6159. .v.pins = (const struct alc_pincfg[]) {
  6160. { 0x14, 0x99130110 }, /* speaker */
  6161. { 0x17, 0x99130111 }, /* speaker */
  6162. { 0x18, 0x01a19840 }, /* mic */
  6163. { 0x19, 0x99a3094f }, /* int-mic */
  6164. { 0x1b, 0x01214020 }, /* HP */
  6165. { 0x21, 0x0121401f }, /* HP */
  6166. { }
  6167. },
  6168. .chained = true,
  6169. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6170. },
  6171. [ALC662_FIXUP_ASUS_MODE8] = {
  6172. .type = ALC_FIXUP_PINS,
  6173. .v.pins = (const struct alc_pincfg[]) {
  6174. { 0x14, 0x99130110 }, /* speaker */
  6175. { 0x12, 0x99a30970 }, /* int-mic */
  6176. { 0x15, 0x01214020 }, /* HP */
  6177. { 0x17, 0x99130111 }, /* speaker */
  6178. { 0x18, 0x01a19840 }, /* mic */
  6179. { 0x21, 0x0121401f }, /* HP */
  6180. { }
  6181. },
  6182. .chained = true,
  6183. .chain_id = ALC662_FIXUP_SKU_IGNORE
  6184. },
  6185. [ALC662_FIXUP_NO_JACK_DETECT] = {
  6186. .type = ALC_FIXUP_FUNC,
  6187. .v.func = alc_fixup_no_jack_detect,
  6188. },
  6189. [ALC662_FIXUP_ZOTAC_Z68] = {
  6190. .type = ALC_FIXUP_PINS,
  6191. .v.pins = (const struct alc_pincfg[]) {
  6192. { 0x1b, 0x02214020 }, /* Front HP */
  6193. { }
  6194. }
  6195. },
  6196. [ALC662_FIXUP_INV_DMIC] = {
  6197. .type = ALC_FIXUP_FUNC,
  6198. .v.func = alc_fixup_inv_dmic_0x12,
  6199. },
  6200. };
  6201. static const struct snd_pci_quirk alc662_fixup_tbl[] = {
  6202. SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
  6203. SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
  6204. SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
  6205. SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
  6206. SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
  6207. SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
  6208. SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
  6209. SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
  6210. SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
  6211. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
  6212. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
  6213. SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
  6214. SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
  6215. #if 0
  6216. /* Below is a quirk table taken from the old code.
  6217. * Basically the device should work as is without the fixup table.
  6218. * If BIOS doesn't give a proper info, enable the corresponding
  6219. * fixup entry.
  6220. */
  6221. SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
  6222. SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
  6223. SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
  6224. SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
  6225. SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6226. SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6227. SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6228. SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
  6229. SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
  6230. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6231. SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
  6232. SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
  6233. SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
  6234. SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
  6235. SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
  6236. SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6237. SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
  6238. SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
  6239. SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6240. SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  6241. SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  6242. SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6243. SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
  6244. SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
  6245. SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
  6246. SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6247. SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
  6248. SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
  6249. SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6250. SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
  6251. SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6252. SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6253. SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
  6254. SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
  6255. SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
  6256. SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
  6257. SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
  6258. SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
  6259. SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
  6260. SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
  6261. SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
  6262. SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
  6263. SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6264. SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
  6265. SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
  6266. SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
  6267. SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
  6268. SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
  6269. SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
  6270. SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
  6271. #endif
  6272. {}
  6273. };
  6274. static const struct alc_model_fixup alc662_fixup_models[] = {
  6275. {.id = ALC272_FIXUP_MARIO, .name = "mario"},
  6276. {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
  6277. {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
  6278. {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
  6279. {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
  6280. {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
  6281. {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
  6282. {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
  6283. {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
  6284. {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
  6285. {}
  6286. };
  6287. static void alc662_fill_coef(struct hda_codec *codec)
  6288. {
  6289. int val, coef;
  6290. coef = alc_get_coef0(codec);
  6291. switch (codec->vendor_id) {
  6292. case 0x10ec0662:
  6293. if ((coef & 0x00f0) == 0x0030) {
  6294. val = alc_read_coef_idx(codec, 0x4); /* EAPD Ctrl */
  6295. alc_write_coef_idx(codec, 0x4, val & ~(1<<10));
  6296. }
  6297. break;
  6298. case 0x10ec0272:
  6299. case 0x10ec0273:
  6300. case 0x10ec0663:
  6301. case 0x10ec0665:
  6302. case 0x10ec0670:
  6303. case 0x10ec0671:
  6304. case 0x10ec0672:
  6305. val = alc_read_coef_idx(codec, 0xd); /* EAPD Ctrl */
  6306. alc_write_coef_idx(codec, 0xd, val | (1<<14));
  6307. break;
  6308. }
  6309. }
  6310. /*
  6311. */
  6312. static int patch_alc662(struct hda_codec *codec)
  6313. {
  6314. struct alc_spec *spec;
  6315. int err;
  6316. err = alc_alloc_spec(codec, 0x0b);
  6317. if (err < 0)
  6318. return err;
  6319. spec = codec->spec;
  6320. /* handle multiple HPs as is */
  6321. spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
  6322. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  6323. spec->init_hook = alc662_fill_coef;
  6324. alc662_fill_coef(codec);
  6325. alc_pick_fixup(codec, alc662_fixup_models,
  6326. alc662_fixup_tbl, alc662_fixups);
  6327. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  6328. alc_auto_parse_customize_define(codec);
  6329. if ((alc_get_coef0(codec) & (1 << 14)) &&
  6330. codec->bus->pci->subsystem_vendor == 0x1025 &&
  6331. spec->cdefine.platform_type == 1) {
  6332. if (alc_codec_rename(codec, "ALC272X") < 0)
  6333. goto error;
  6334. }
  6335. /* automatic parse from the BIOS config */
  6336. err = alc662_parse_auto_config(codec);
  6337. if (err < 0)
  6338. goto error;
  6339. if (!spec->no_analog && has_cdefine_beep(codec)) {
  6340. err = snd_hda_attach_beep_device(codec, 0x1);
  6341. if (err < 0)
  6342. goto error;
  6343. switch (codec->vendor_id) {
  6344. case 0x10ec0662:
  6345. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  6346. break;
  6347. case 0x10ec0272:
  6348. case 0x10ec0663:
  6349. case 0x10ec0665:
  6350. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  6351. break;
  6352. case 0x10ec0273:
  6353. set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
  6354. break;
  6355. }
  6356. }
  6357. codec->patch_ops = alc_patch_ops;
  6358. spec->shutup = alc_eapd_shutup;
  6359. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  6360. return 0;
  6361. error:
  6362. alc_free(codec);
  6363. return err;
  6364. }
  6365. /*
  6366. * ALC680 support
  6367. */
  6368. static int alc680_parse_auto_config(struct hda_codec *codec)
  6369. {
  6370. return alc_parse_auto_config(codec, NULL, NULL);
  6371. }
  6372. /*
  6373. */
  6374. static int patch_alc680(struct hda_codec *codec)
  6375. {
  6376. int err;
  6377. /* ALC680 has no aa-loopback mixer */
  6378. err = alc_alloc_spec(codec, 0);
  6379. if (err < 0)
  6380. return err;
  6381. /* automatic parse from the BIOS config */
  6382. err = alc680_parse_auto_config(codec);
  6383. if (err < 0) {
  6384. alc_free(codec);
  6385. return err;
  6386. }
  6387. codec->patch_ops = alc_patch_ops;
  6388. return 0;
  6389. }
  6390. /*
  6391. * patch entries
  6392. */
  6393. static const struct hda_codec_preset snd_hda_preset_realtek[] = {
  6394. { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
  6395. { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
  6396. { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
  6397. { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
  6398. { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
  6399. { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
  6400. { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
  6401. { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
  6402. { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
  6403. { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
  6404. { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
  6405. { .id = 0x10ec0282, .name = "ALC282", .patch = patch_alc269 },
  6406. { .id = 0x10ec0283, .name = "ALC283", .patch = patch_alc269 },
  6407. { .id = 0x10ec0290, .name = "ALC290", .patch = patch_alc269 },
  6408. { .id = 0x10ec0292, .name = "ALC292", .patch = patch_alc269 },
  6409. { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
  6410. .patch = patch_alc861 },
  6411. { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
  6412. { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
  6413. { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
  6414. { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
  6415. .patch = patch_alc882 },
  6416. { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
  6417. .patch = patch_alc662 },
  6418. { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
  6419. .patch = patch_alc662 },
  6420. { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
  6421. { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
  6422. { .id = 0x10ec0668, .name = "ALC668", .patch = patch_alc662 },
  6423. { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
  6424. { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
  6425. { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
  6426. { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
  6427. { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
  6428. { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
  6429. .patch = patch_alc882 },
  6430. { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
  6431. .patch = patch_alc882 },
  6432. { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
  6433. { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
  6434. { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
  6435. .patch = patch_alc882 },
  6436. { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
  6437. { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
  6438. { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
  6439. { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
  6440. { .id = 0x10ec0900, .name = "ALC1150", .patch = patch_alc882 },
  6441. {} /* terminator */
  6442. };
  6443. MODULE_ALIAS("snd-hda-codec-id:10ec*");
  6444. MODULE_LICENSE("GPL");
  6445. MODULE_DESCRIPTION("Realtek HD-audio codec");
  6446. static struct hda_codec_preset_list realtek_list = {
  6447. .preset = snd_hda_preset_realtek,
  6448. .owner = THIS_MODULE,
  6449. };
  6450. static int __init patch_realtek_init(void)
  6451. {
  6452. return snd_hda_add_codec_preset(&realtek_list);
  6453. }
  6454. static void __exit patch_realtek_exit(void)
  6455. {
  6456. snd_hda_delete_codec_preset(&realtek_list);
  6457. }
  6458. module_init(patch_realtek_init)
  6459. module_exit(patch_realtek_exit)