patch_realtek.c 188 KB

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