patch_realtek.c 199 KB

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