patch_realtek.c 202 KB

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