patch_realtek.c 187 KB

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