patch_realtek.c 207 KB

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