patch_realtek.c 194 KB

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