patch_realtek.c 205 KB

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