patch_realtek.c 190 KB

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