patch_realtek.c 182 KB

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