patch_realtek.c 196 KB

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