patch_realtek.c 192 KB

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