patch_realtek.c 191 KB

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