patch_realtek.c 168 KB

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