patch_realtek.c 189 KB

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