patch_realtek.c 192 KB

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