patch_realtek.c 195 KB

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