patch_realtek.c 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426
  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 <sound/core.h>
  30. #include <sound/jack.h>
  31. #include "hda_codec.h"
  32. #include "hda_local.h"
  33. #include "hda_beep.h"
  34. /* unsol event tags */
  35. #define ALC_FRONT_EVENT 0x01
  36. #define ALC_DCVOL_EVENT 0x02
  37. #define ALC_HP_EVENT 0x04
  38. #define ALC_MIC_EVENT 0x08
  39. /* for GPIO Poll */
  40. #define GPIO_MASK 0x03
  41. /* extra amp-initialization sequence types */
  42. enum {
  43. ALC_INIT_NONE,
  44. ALC_INIT_DEFAULT,
  45. ALC_INIT_GPIO1,
  46. ALC_INIT_GPIO2,
  47. ALC_INIT_GPIO3,
  48. };
  49. struct alc_customize_define {
  50. unsigned int sku_cfg;
  51. unsigned char port_connectivity;
  52. unsigned char check_sum;
  53. unsigned char customization;
  54. unsigned char external_amp;
  55. unsigned int enable_pcbeep:1;
  56. unsigned int platform_type:1;
  57. unsigned int swap:1;
  58. unsigned int override:1;
  59. unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
  60. };
  61. struct alc_fixup;
  62. struct alc_multi_io {
  63. hda_nid_t pin; /* multi-io widget pin NID */
  64. hda_nid_t dac; /* DAC to be connected */
  65. unsigned int ctl_in; /* cached input-pin control value */
  66. };
  67. enum {
  68. ALC_AUTOMUTE_PIN, /* change the pin control */
  69. ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
  70. ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
  71. };
  72. struct alc_spec {
  73. /* codec parameterization */
  74. const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
  75. unsigned int num_mixers;
  76. const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
  77. unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
  78. const struct hda_verb *init_verbs[10]; /* initialization verbs
  79. * don't forget NULL
  80. * termination!
  81. */
  82. unsigned int num_init_verbs;
  83. char stream_name_analog[32]; /* analog PCM stream */
  84. const struct hda_pcm_stream *stream_analog_playback;
  85. const struct hda_pcm_stream *stream_analog_capture;
  86. const struct hda_pcm_stream *stream_analog_alt_playback;
  87. const struct hda_pcm_stream *stream_analog_alt_capture;
  88. char stream_name_digital[32]; /* digital PCM stream */
  89. const struct hda_pcm_stream *stream_digital_playback;
  90. const struct hda_pcm_stream *stream_digital_capture;
  91. /* playback */
  92. struct hda_multi_out multiout; /* playback set-up
  93. * max_channels, dacs must be set
  94. * dig_out_nid and hp_nid are optional
  95. */
  96. hda_nid_t alt_dac_nid;
  97. hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
  98. int dig_out_type;
  99. /* capture */
  100. unsigned int num_adc_nids;
  101. const hda_nid_t *adc_nids;
  102. const hda_nid_t *capsrc_nids;
  103. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  104. hda_nid_t mixer_nid; /* analog-mixer NID */
  105. /* capture setup for dynamic dual-adc switch */
  106. hda_nid_t cur_adc;
  107. unsigned int cur_adc_stream_tag;
  108. unsigned int cur_adc_format;
  109. /* capture source */
  110. unsigned int num_mux_defs;
  111. const struct hda_input_mux *input_mux;
  112. unsigned int cur_mux[3];
  113. hda_nid_t ext_mic_pin;
  114. hda_nid_t dock_mic_pin;
  115. hda_nid_t int_mic_pin;
  116. /* channel model */
  117. const struct hda_channel_mode *channel_mode;
  118. int num_channel_mode;
  119. int need_dac_fix;
  120. int const_channel_count;
  121. int ext_channel_count;
  122. /* PCM information */
  123. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  124. /* dynamic controls, init_verbs and input_mux */
  125. struct auto_pin_cfg autocfg;
  126. struct alc_customize_define cdefine;
  127. struct snd_array kctls;
  128. struct hda_input_mux private_imux[3];
  129. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  130. hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
  131. hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
  132. hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
  133. unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
  134. int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
  135. /* hooks */
  136. void (*init_hook)(struct hda_codec *codec);
  137. void (*unsol_event)(struct hda_codec *codec, unsigned int res);
  138. #ifdef CONFIG_SND_HDA_POWER_SAVE
  139. void (*power_hook)(struct hda_codec *codec);
  140. #endif
  141. void (*shutup)(struct hda_codec *codec);
  142. /* for pin sensing */
  143. unsigned int jack_present: 1;
  144. unsigned int line_jack_present:1;
  145. unsigned int master_mute:1;
  146. unsigned int auto_mic:1;
  147. unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
  148. unsigned int automute:1; /* HP automute enabled */
  149. unsigned int detect_line:1; /* Line-out detection enabled */
  150. unsigned int automute_lines:1; /* automute line-out as well */
  151. unsigned int automute_hp_lo:1; /* both HP and LO available */
  152. /* other flags */
  153. unsigned int no_analog :1; /* digital I/O only */
  154. unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
  155. unsigned int single_input_src:1;
  156. unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
  157. /* auto-mute control */
  158. int automute_mode;
  159. hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
  160. int init_amp;
  161. int codec_variant; /* flag for other variants */
  162. /* for virtual master */
  163. hda_nid_t vmaster_nid;
  164. #ifdef CONFIG_SND_HDA_POWER_SAVE
  165. struct hda_loopback_check loopback;
  166. #endif
  167. /* for PLL fix */
  168. hda_nid_t pll_nid;
  169. unsigned int pll_coef_idx, pll_coef_bit;
  170. /* fix-up list */
  171. int fixup_id;
  172. const struct alc_fixup *fixup_list;
  173. const char *fixup_name;
  174. /* multi-io */
  175. int multi_ios;
  176. struct alc_multi_io multi_io[4];
  177. };
  178. #define ALC_MODEL_AUTO 0 /* common for all chips */
  179. static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
  180. int dir, unsigned int bits)
  181. {
  182. if (!nid)
  183. return false;
  184. if (get_wcaps(codec, nid) & (1 << (dir + 1)))
  185. if (query_amp_caps(codec, nid, dir) & bits)
  186. return true;
  187. return false;
  188. }
  189. #define nid_has_mute(codec, nid, dir) \
  190. check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
  191. #define nid_has_volume(codec, nid, dir) \
  192. check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
  193. /*
  194. * input MUX handling
  195. */
  196. static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
  197. struct snd_ctl_elem_info *uinfo)
  198. {
  199. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  200. struct alc_spec *spec = codec->spec;
  201. unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
  202. if (mux_idx >= spec->num_mux_defs)
  203. mux_idx = 0;
  204. if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
  205. mux_idx = 0;
  206. return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
  207. }
  208. static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
  209. struct snd_ctl_elem_value *ucontrol)
  210. {
  211. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  212. struct alc_spec *spec = codec->spec;
  213. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  214. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  215. return 0;
  216. }
  217. static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
  218. {
  219. struct alc_spec *spec = codec->spec;
  220. hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
  221. if (spec->cur_adc && spec->cur_adc != new_adc) {
  222. /* stream is running, let's swap the current ADC */
  223. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  224. spec->cur_adc = new_adc;
  225. snd_hda_codec_setup_stream(codec, new_adc,
  226. spec->cur_adc_stream_tag, 0,
  227. spec->cur_adc_format);
  228. return true;
  229. }
  230. return false;
  231. }
  232. /* select the given imux item; either unmute exclusively or select the route */
  233. static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
  234. unsigned int idx, bool force)
  235. {
  236. struct alc_spec *spec = codec->spec;
  237. const struct hda_input_mux *imux;
  238. unsigned int mux_idx;
  239. int i, type;
  240. hda_nid_t nid;
  241. mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
  242. imux = &spec->input_mux[mux_idx];
  243. if (!imux->num_items && mux_idx > 0)
  244. imux = &spec->input_mux[0];
  245. if (idx >= imux->num_items)
  246. idx = imux->num_items - 1;
  247. if (spec->cur_mux[adc_idx] == idx && !force)
  248. return 0;
  249. spec->cur_mux[adc_idx] = idx;
  250. if (spec->dyn_adc_switch) {
  251. alc_dyn_adc_pcm_resetup(codec, idx);
  252. adc_idx = spec->dyn_adc_idx[idx];
  253. }
  254. nid = spec->capsrc_nids ?
  255. spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
  256. /* no selection? */
  257. if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
  258. return 1;
  259. type = get_wcaps_type(get_wcaps(codec, nid));
  260. if (type == AC_WID_AUD_MIX) {
  261. /* Matrix-mixer style (e.g. ALC882) */
  262. for (i = 0; i < imux->num_items; i++) {
  263. unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
  264. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
  265. imux->items[i].index,
  266. HDA_AMP_MUTE, v);
  267. }
  268. } else {
  269. /* MUX style (e.g. ALC880) */
  270. snd_hda_codec_write_cache(codec, nid, 0,
  271. AC_VERB_SET_CONNECT_SEL,
  272. imux->items[idx].index);
  273. }
  274. return 1;
  275. }
  276. static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
  277. struct snd_ctl_elem_value *ucontrol)
  278. {
  279. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  280. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  281. return alc_mux_select(codec, adc_idx,
  282. ucontrol->value.enumerated.item[0], false);
  283. }
  284. /*
  285. * set up the input pin config (depending on the given auto-pin type)
  286. */
  287. static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
  288. int auto_pin_type)
  289. {
  290. unsigned int val = PIN_IN;
  291. if (auto_pin_type == AUTO_PIN_MIC) {
  292. unsigned int pincap;
  293. unsigned int oldval;
  294. oldval = snd_hda_codec_read(codec, nid, 0,
  295. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  296. pincap = snd_hda_query_pin_caps(codec, nid);
  297. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  298. /* if the default pin setup is vref50, we give it priority */
  299. if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
  300. val = PIN_VREF80;
  301. else if (pincap & AC_PINCAP_VREF_50)
  302. val = PIN_VREF50;
  303. else if (pincap & AC_PINCAP_VREF_100)
  304. val = PIN_VREF100;
  305. else if (pincap & AC_PINCAP_VREF_GRD)
  306. val = PIN_VREFGRD;
  307. }
  308. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
  309. }
  310. /*
  311. * Append the given mixer and verb elements for the later use
  312. * The mixer array is referred in build_controls(), and init_verbs are
  313. * called in init().
  314. */
  315. static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
  316. {
  317. if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
  318. return;
  319. spec->mixers[spec->num_mixers++] = mix;
  320. }
  321. static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
  322. {
  323. if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
  324. return;
  325. spec->init_verbs[spec->num_init_verbs++] = verb;
  326. }
  327. /*
  328. * GPIO setup tables, used in initialization
  329. */
  330. /* Enable GPIO mask and set output */
  331. static const struct hda_verb alc_gpio1_init_verbs[] = {
  332. {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
  333. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  334. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  335. { }
  336. };
  337. static const struct hda_verb alc_gpio2_init_verbs[] = {
  338. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  339. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  340. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  341. { }
  342. };
  343. static const struct hda_verb alc_gpio3_init_verbs[] = {
  344. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  345. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
  346. {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
  347. { }
  348. };
  349. /*
  350. * Fix hardware PLL issue
  351. * On some codecs, the analog PLL gating control must be off while
  352. * the default value is 1.
  353. */
  354. static void alc_fix_pll(struct hda_codec *codec)
  355. {
  356. struct alc_spec *spec = codec->spec;
  357. unsigned int val;
  358. if (!spec->pll_nid)
  359. return;
  360. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
  361. spec->pll_coef_idx);
  362. val = snd_hda_codec_read(codec, spec->pll_nid, 0,
  363. AC_VERB_GET_PROC_COEF, 0);
  364. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
  365. spec->pll_coef_idx);
  366. snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
  367. val & ~(1 << spec->pll_coef_bit));
  368. }
  369. static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
  370. unsigned int coef_idx, unsigned int coef_bit)
  371. {
  372. struct alc_spec *spec = codec->spec;
  373. spec->pll_nid = nid;
  374. spec->pll_coef_idx = coef_idx;
  375. spec->pll_coef_bit = coef_bit;
  376. alc_fix_pll(codec);
  377. }
  378. /*
  379. * Jack-reporting via input-jack layer
  380. */
  381. /* initialization of jacks; currently checks only a few known pins */
  382. static int alc_init_jacks(struct hda_codec *codec)
  383. {
  384. #ifdef CONFIG_SND_HDA_INPUT_JACK
  385. struct alc_spec *spec = codec->spec;
  386. int err;
  387. unsigned int hp_nid = spec->autocfg.hp_pins[0];
  388. unsigned int mic_nid = spec->ext_mic_pin;
  389. unsigned int dock_nid = spec->dock_mic_pin;
  390. if (hp_nid) {
  391. err = snd_hda_input_jack_add(codec, hp_nid,
  392. SND_JACK_HEADPHONE, NULL);
  393. if (err < 0)
  394. return err;
  395. snd_hda_input_jack_report(codec, hp_nid);
  396. }
  397. if (mic_nid) {
  398. err = snd_hda_input_jack_add(codec, mic_nid,
  399. SND_JACK_MICROPHONE, NULL);
  400. if (err < 0)
  401. return err;
  402. snd_hda_input_jack_report(codec, mic_nid);
  403. }
  404. if (dock_nid) {
  405. err = snd_hda_input_jack_add(codec, dock_nid,
  406. SND_JACK_MICROPHONE, NULL);
  407. if (err < 0)
  408. return err;
  409. snd_hda_input_jack_report(codec, dock_nid);
  410. }
  411. #endif /* CONFIG_SND_HDA_INPUT_JACK */
  412. return 0;
  413. }
  414. /*
  415. * Jack detections for HP auto-mute and mic-switch
  416. */
  417. /* check each pin in the given array; returns true if any of them is plugged */
  418. static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  419. {
  420. int i, present = 0;
  421. for (i = 0; i < num_pins; i++) {
  422. hda_nid_t nid = pins[i];
  423. if (!nid)
  424. break;
  425. snd_hda_input_jack_report(codec, nid);
  426. present |= snd_hda_jack_detect(codec, nid);
  427. }
  428. return present;
  429. }
  430. /* standard HP/line-out auto-mute helper */
  431. static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
  432. bool mute, bool hp_out)
  433. {
  434. struct alc_spec *spec = codec->spec;
  435. unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
  436. unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
  437. int i;
  438. for (i = 0; i < num_pins; i++) {
  439. hda_nid_t nid = pins[i];
  440. if (!nid)
  441. break;
  442. switch (spec->automute_mode) {
  443. case ALC_AUTOMUTE_PIN:
  444. snd_hda_codec_write(codec, nid, 0,
  445. AC_VERB_SET_PIN_WIDGET_CONTROL,
  446. pin_bits);
  447. break;
  448. case ALC_AUTOMUTE_AMP:
  449. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  450. HDA_AMP_MUTE, mute_bits);
  451. break;
  452. case ALC_AUTOMUTE_MIXER:
  453. nid = spec->automute_mixer_nid[i];
  454. if (!nid)
  455. break;
  456. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
  457. HDA_AMP_MUTE, mute_bits);
  458. snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
  459. HDA_AMP_MUTE, mute_bits);
  460. break;
  461. }
  462. }
  463. }
  464. /* Toggle internal speakers muting */
  465. static void update_speakers(struct hda_codec *codec)
  466. {
  467. struct alc_spec *spec = codec->spec;
  468. int on;
  469. /* Control HP pins/amps depending on master_mute state;
  470. * in general, HP pins/amps control should be enabled in all cases,
  471. * but currently set only for master_mute, just to be safe
  472. */
  473. do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
  474. spec->autocfg.hp_pins, spec->master_mute, true);
  475. if (!spec->automute)
  476. on = 0;
  477. else
  478. on = spec->jack_present | spec->line_jack_present;
  479. on |= spec->master_mute;
  480. do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
  481. spec->autocfg.speaker_pins, on, false);
  482. /* toggle line-out mutes if needed, too */
  483. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  484. if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
  485. spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
  486. return;
  487. if (!spec->automute_lines || !spec->automute)
  488. on = 0;
  489. else
  490. on = spec->jack_present;
  491. on |= spec->master_mute;
  492. do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
  493. spec->autocfg.line_out_pins, on, false);
  494. }
  495. /* standard HP-automute helper */
  496. static void alc_hp_automute(struct hda_codec *codec)
  497. {
  498. struct alc_spec *spec = codec->spec;
  499. if (!spec->automute)
  500. return;
  501. spec->jack_present =
  502. detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
  503. spec->autocfg.hp_pins);
  504. update_speakers(codec);
  505. }
  506. /* standard line-out-automute helper */
  507. static void alc_line_automute(struct hda_codec *codec)
  508. {
  509. struct alc_spec *spec = codec->spec;
  510. if (!spec->automute || !spec->detect_line)
  511. return;
  512. spec->line_jack_present =
  513. detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
  514. spec->autocfg.line_out_pins);
  515. update_speakers(codec);
  516. }
  517. #define get_connection_index(codec, mux, nid) \
  518. snd_hda_get_conn_index(codec, mux, nid, 0)
  519. /* standard mic auto-switch helper */
  520. static void alc_mic_automute(struct hda_codec *codec)
  521. {
  522. struct alc_spec *spec = codec->spec;
  523. hda_nid_t *pins = spec->imux_pins;
  524. if (!spec->auto_mic || !spec->auto_mic_valid_imux)
  525. return;
  526. if (snd_BUG_ON(!spec->adc_nids))
  527. return;
  528. if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
  529. return;
  530. if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
  531. alc_mux_select(codec, 0, spec->ext_mic_idx, false);
  532. else if (spec->dock_mic_idx >= 0 &&
  533. snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
  534. alc_mux_select(codec, 0, spec->dock_mic_idx, false);
  535. else
  536. alc_mux_select(codec, 0, spec->int_mic_idx, false);
  537. snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
  538. if (spec->dock_mic_idx >= 0)
  539. snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
  540. }
  541. /* unsolicited event for HP jack sensing */
  542. static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
  543. {
  544. if (codec->vendor_id == 0x10ec0880)
  545. res >>= 28;
  546. else
  547. res >>= 26;
  548. switch (res) {
  549. case ALC_HP_EVENT:
  550. alc_hp_automute(codec);
  551. break;
  552. case ALC_FRONT_EVENT:
  553. alc_line_automute(codec);
  554. break;
  555. case ALC_MIC_EVENT:
  556. alc_mic_automute(codec);
  557. break;
  558. }
  559. }
  560. /* call init functions of standard auto-mute helpers */
  561. static void alc_inithook(struct hda_codec *codec)
  562. {
  563. alc_hp_automute(codec);
  564. alc_line_automute(codec);
  565. alc_mic_automute(codec);
  566. }
  567. /* additional initialization for ALC888 variants */
  568. static void alc888_coef_init(struct hda_codec *codec)
  569. {
  570. unsigned int tmp;
  571. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
  572. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  573. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  574. if ((tmp & 0xf0) == 0x20)
  575. /* alc888S-VC */
  576. snd_hda_codec_read(codec, 0x20, 0,
  577. AC_VERB_SET_PROC_COEF, 0x830);
  578. else
  579. /* alc888-VB */
  580. snd_hda_codec_read(codec, 0x20, 0,
  581. AC_VERB_SET_PROC_COEF, 0x3030);
  582. }
  583. /* additional initialization for ALC889 variants */
  584. static void alc889_coef_init(struct hda_codec *codec)
  585. {
  586. unsigned int tmp;
  587. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  588. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  589. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
  590. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
  591. }
  592. /* turn on/off EAPD control (only if available) */
  593. static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
  594. {
  595. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  596. return;
  597. if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
  598. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  599. on ? 2 : 0);
  600. }
  601. /* turn on/off EAPD controls of the codec */
  602. static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
  603. {
  604. /* We currently only handle front, HP */
  605. static hda_nid_t pins[] = {
  606. 0x0f, 0x10, 0x14, 0x15, 0
  607. };
  608. hda_nid_t *p;
  609. for (p = pins; *p; p++)
  610. set_eapd(codec, *p, on);
  611. }
  612. /* generic shutup callback;
  613. * just turning off EPAD and a little pause for avoiding pop-noise
  614. */
  615. static void alc_eapd_shutup(struct hda_codec *codec)
  616. {
  617. alc_auto_setup_eapd(codec, false);
  618. msleep(200);
  619. }
  620. /* generic EAPD initialization */
  621. static void alc_auto_init_amp(struct hda_codec *codec, int type)
  622. {
  623. unsigned int tmp;
  624. alc_auto_setup_eapd(codec, true);
  625. switch (type) {
  626. case ALC_INIT_GPIO1:
  627. snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
  628. break;
  629. case ALC_INIT_GPIO2:
  630. snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
  631. break;
  632. case ALC_INIT_GPIO3:
  633. snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
  634. break;
  635. case ALC_INIT_DEFAULT:
  636. switch (codec->vendor_id) {
  637. case 0x10ec0260:
  638. snd_hda_codec_write(codec, 0x1a, 0,
  639. AC_VERB_SET_COEF_INDEX, 7);
  640. tmp = snd_hda_codec_read(codec, 0x1a, 0,
  641. AC_VERB_GET_PROC_COEF, 0);
  642. snd_hda_codec_write(codec, 0x1a, 0,
  643. AC_VERB_SET_COEF_INDEX, 7);
  644. snd_hda_codec_write(codec, 0x1a, 0,
  645. AC_VERB_SET_PROC_COEF,
  646. tmp | 0x2010);
  647. break;
  648. case 0x10ec0262:
  649. case 0x10ec0880:
  650. case 0x10ec0882:
  651. case 0x10ec0883:
  652. case 0x10ec0885:
  653. case 0x10ec0887:
  654. /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
  655. alc889_coef_init(codec);
  656. break;
  657. case 0x10ec0888:
  658. alc888_coef_init(codec);
  659. break;
  660. #if 0 /* XXX: This may cause the silent output on speaker on some machines */
  661. case 0x10ec0267:
  662. case 0x10ec0268:
  663. snd_hda_codec_write(codec, 0x20, 0,
  664. AC_VERB_SET_COEF_INDEX, 7);
  665. tmp = snd_hda_codec_read(codec, 0x20, 0,
  666. AC_VERB_GET_PROC_COEF, 0);
  667. snd_hda_codec_write(codec, 0x20, 0,
  668. AC_VERB_SET_COEF_INDEX, 7);
  669. snd_hda_codec_write(codec, 0x20, 0,
  670. AC_VERB_SET_PROC_COEF,
  671. tmp | 0x3000);
  672. break;
  673. #endif /* XXX */
  674. }
  675. break;
  676. }
  677. }
  678. /*
  679. * Auto-Mute mode mixer enum support
  680. */
  681. static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
  682. struct snd_ctl_elem_info *uinfo)
  683. {
  684. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  685. struct alc_spec *spec = codec->spec;
  686. static const char * const texts2[] = {
  687. "Disabled", "Enabled"
  688. };
  689. static const char * const texts3[] = {
  690. "Disabled", "Speaker Only", "Line-Out+Speaker"
  691. };
  692. const char * const *texts;
  693. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  694. uinfo->count = 1;
  695. if (spec->automute_hp_lo) {
  696. uinfo->value.enumerated.items = 3;
  697. texts = texts3;
  698. } else {
  699. uinfo->value.enumerated.items = 2;
  700. texts = texts2;
  701. }
  702. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  703. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  704. strcpy(uinfo->value.enumerated.name,
  705. texts[uinfo->value.enumerated.item]);
  706. return 0;
  707. }
  708. static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
  709. struct snd_ctl_elem_value *ucontrol)
  710. {
  711. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  712. struct alc_spec *spec = codec->spec;
  713. unsigned int val;
  714. if (!spec->automute)
  715. val = 0;
  716. else if (!spec->automute_lines)
  717. val = 1;
  718. else
  719. val = 2;
  720. ucontrol->value.enumerated.item[0] = val;
  721. return 0;
  722. }
  723. static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
  724. struct snd_ctl_elem_value *ucontrol)
  725. {
  726. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  727. struct alc_spec *spec = codec->spec;
  728. switch (ucontrol->value.enumerated.item[0]) {
  729. case 0:
  730. if (!spec->automute)
  731. return 0;
  732. spec->automute = 0;
  733. break;
  734. case 1:
  735. if (spec->automute && !spec->automute_lines)
  736. return 0;
  737. spec->automute = 1;
  738. spec->automute_lines = 0;
  739. break;
  740. case 2:
  741. if (!spec->automute_hp_lo)
  742. return -EINVAL;
  743. if (spec->automute && spec->automute_lines)
  744. return 0;
  745. spec->automute = 1;
  746. spec->automute_lines = 1;
  747. break;
  748. default:
  749. return -EINVAL;
  750. }
  751. update_speakers(codec);
  752. return 1;
  753. }
  754. static const struct snd_kcontrol_new alc_automute_mode_enum = {
  755. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  756. .name = "Auto-Mute Mode",
  757. .info = alc_automute_mode_info,
  758. .get = alc_automute_mode_get,
  759. .put = alc_automute_mode_put,
  760. };
  761. static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
  762. {
  763. snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
  764. return snd_array_new(&spec->kctls);
  765. }
  766. static int alc_add_automute_mode_enum(struct hda_codec *codec)
  767. {
  768. struct alc_spec *spec = codec->spec;
  769. struct snd_kcontrol_new *knew;
  770. knew = alc_kcontrol_new(spec);
  771. if (!knew)
  772. return -ENOMEM;
  773. *knew = alc_automute_mode_enum;
  774. knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
  775. if (!knew->name)
  776. return -ENOMEM;
  777. return 0;
  778. }
  779. /*
  780. * Check the availability of HP/line-out auto-mute;
  781. * Set up appropriately if really supported
  782. */
  783. static void alc_init_auto_hp(struct hda_codec *codec)
  784. {
  785. struct alc_spec *spec = codec->spec;
  786. struct auto_pin_cfg *cfg = &spec->autocfg;
  787. int present = 0;
  788. int i;
  789. if (cfg->hp_pins[0])
  790. present++;
  791. if (cfg->line_out_pins[0])
  792. present++;
  793. if (cfg->speaker_pins[0])
  794. present++;
  795. if (present < 2) /* need two different output types */
  796. return;
  797. if (present == 3)
  798. spec->automute_hp_lo = 1; /* both HP and LO automute */
  799. if (!cfg->speaker_pins[0] &&
  800. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
  801. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  802. sizeof(cfg->speaker_pins));
  803. cfg->speaker_outs = cfg->line_outs;
  804. }
  805. if (!cfg->hp_pins[0] &&
  806. cfg->line_out_type == AUTO_PIN_HP_OUT) {
  807. memcpy(cfg->hp_pins, cfg->line_out_pins,
  808. sizeof(cfg->hp_pins));
  809. cfg->hp_outs = cfg->line_outs;
  810. }
  811. for (i = 0; i < cfg->hp_outs; i++) {
  812. hda_nid_t nid = cfg->hp_pins[i];
  813. if (!is_jack_detectable(codec, nid))
  814. continue;
  815. snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
  816. nid);
  817. snd_hda_codec_write_cache(codec, nid, 0,
  818. AC_VERB_SET_UNSOLICITED_ENABLE,
  819. AC_USRSP_EN | ALC_HP_EVENT);
  820. spec->automute = 1;
  821. spec->automute_mode = ALC_AUTOMUTE_PIN;
  822. }
  823. if (spec->automute && cfg->line_out_pins[0] &&
  824. cfg->speaker_pins[0] &&
  825. cfg->line_out_pins[0] != cfg->hp_pins[0] &&
  826. cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
  827. for (i = 0; i < cfg->line_outs; i++) {
  828. hda_nid_t nid = cfg->line_out_pins[i];
  829. if (!is_jack_detectable(codec, nid))
  830. continue;
  831. snd_printdd("realtek: Enable Line-Out auto-muting "
  832. "on NID 0x%x\n", nid);
  833. snd_hda_codec_write_cache(codec, nid, 0,
  834. AC_VERB_SET_UNSOLICITED_ENABLE,
  835. AC_USRSP_EN | ALC_FRONT_EVENT);
  836. spec->detect_line = 1;
  837. }
  838. spec->automute_lines = spec->detect_line;
  839. }
  840. if (spec->automute) {
  841. /* create a control for automute mode */
  842. alc_add_automute_mode_enum(codec);
  843. spec->unsol_event = alc_sku_unsol_event;
  844. }
  845. }
  846. /* return the position of NID in the list, or -1 if not found */
  847. static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  848. {
  849. int i;
  850. for (i = 0; i < nums; i++)
  851. if (list[i] == nid)
  852. return i;
  853. return -1;
  854. }
  855. /* check whether dynamic ADC-switching is available */
  856. static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
  857. {
  858. struct alc_spec *spec = codec->spec;
  859. struct hda_input_mux *imux = &spec->private_imux[0];
  860. int i, n, idx;
  861. hda_nid_t cap, pin;
  862. if (imux != spec->input_mux) /* no dynamic imux? */
  863. return false;
  864. for (n = 0; n < spec->num_adc_nids; n++) {
  865. cap = spec->private_capsrc_nids[n];
  866. for (i = 0; i < imux->num_items; i++) {
  867. pin = spec->imux_pins[i];
  868. if (!pin)
  869. return false;
  870. if (get_connection_index(codec, cap, pin) < 0)
  871. break;
  872. }
  873. if (i >= imux->num_items)
  874. return true; /* no ADC-switch is needed */
  875. }
  876. for (i = 0; i < imux->num_items; i++) {
  877. pin = spec->imux_pins[i];
  878. for (n = 0; n < spec->num_adc_nids; n++) {
  879. cap = spec->private_capsrc_nids[n];
  880. idx = get_connection_index(codec, cap, pin);
  881. if (idx >= 0) {
  882. imux->items[i].index = idx;
  883. spec->dyn_adc_idx[i] = n;
  884. break;
  885. }
  886. }
  887. }
  888. snd_printdd("realtek: enabling ADC switching\n");
  889. spec->dyn_adc_switch = 1;
  890. return true;
  891. }
  892. /* rebuild imux for matching with the given auto-mic pins (if not yet) */
  893. static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
  894. {
  895. struct alc_spec *spec = codec->spec;
  896. struct hda_input_mux *imux;
  897. static char * const texts[3] = {
  898. "Mic", "Internal Mic", "Dock Mic"
  899. };
  900. int i;
  901. if (!spec->auto_mic)
  902. return false;
  903. imux = &spec->private_imux[0];
  904. if (spec->input_mux == imux)
  905. return true;
  906. spec->imux_pins[0] = spec->ext_mic_pin;
  907. spec->imux_pins[1] = spec->int_mic_pin;
  908. spec->imux_pins[2] = spec->dock_mic_pin;
  909. for (i = 0; i < 3; i++) {
  910. strcpy(imux->items[i].label, texts[i]);
  911. if (spec->imux_pins[i])
  912. imux->num_items = i + 1;
  913. }
  914. spec->num_mux_defs = 1;
  915. spec->input_mux = imux;
  916. return true;
  917. }
  918. /* check whether all auto-mic pins are valid; setup indices if OK */
  919. static bool alc_auto_mic_check_imux(struct hda_codec *codec)
  920. {
  921. struct alc_spec *spec = codec->spec;
  922. const struct hda_input_mux *imux;
  923. if (!spec->auto_mic)
  924. return false;
  925. if (spec->auto_mic_valid_imux)
  926. return true; /* already checked */
  927. /* fill up imux indices */
  928. if (!alc_check_dyn_adc_switch(codec)) {
  929. spec->auto_mic = 0;
  930. return false;
  931. }
  932. imux = spec->input_mux;
  933. spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
  934. spec->imux_pins, imux->num_items);
  935. spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
  936. spec->imux_pins, imux->num_items);
  937. spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
  938. spec->imux_pins, imux->num_items);
  939. if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
  940. spec->auto_mic = 0;
  941. return false; /* no corresponding imux */
  942. }
  943. snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
  944. AC_VERB_SET_UNSOLICITED_ENABLE,
  945. AC_USRSP_EN | ALC_MIC_EVENT);
  946. if (spec->dock_mic_pin)
  947. snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
  948. AC_VERB_SET_UNSOLICITED_ENABLE,
  949. AC_USRSP_EN | ALC_MIC_EVENT);
  950. spec->auto_mic_valid_imux = 1;
  951. spec->auto_mic = 1;
  952. return true;
  953. }
  954. /*
  955. * Check the availability of auto-mic switch;
  956. * Set up if really supported
  957. */
  958. static void alc_init_auto_mic(struct hda_codec *codec)
  959. {
  960. struct alc_spec *spec = codec->spec;
  961. struct auto_pin_cfg *cfg = &spec->autocfg;
  962. hda_nid_t fixed, ext, dock;
  963. int i;
  964. spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
  965. fixed = ext = dock = 0;
  966. for (i = 0; i < cfg->num_inputs; i++) {
  967. hda_nid_t nid = cfg->inputs[i].pin;
  968. unsigned int defcfg;
  969. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  970. switch (snd_hda_get_input_pin_attr(defcfg)) {
  971. case INPUT_PIN_ATTR_INT:
  972. if (fixed)
  973. return; /* already occupied */
  974. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  975. return; /* invalid type */
  976. fixed = nid;
  977. break;
  978. case INPUT_PIN_ATTR_UNUSED:
  979. return; /* invalid entry */
  980. case INPUT_PIN_ATTR_DOCK:
  981. if (dock)
  982. return; /* already occupied */
  983. if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
  984. return; /* invalid type */
  985. dock = nid;
  986. break;
  987. default:
  988. if (ext)
  989. return; /* already occupied */
  990. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  991. return; /* invalid type */
  992. ext = nid;
  993. break;
  994. }
  995. }
  996. if (!ext && dock) {
  997. ext = dock;
  998. dock = 0;
  999. }
  1000. if (!ext || !fixed)
  1001. return;
  1002. if (!is_jack_detectable(codec, ext))
  1003. return; /* no unsol support */
  1004. if (dock && !is_jack_detectable(codec, dock))
  1005. return; /* no unsol support */
  1006. /* check imux indices */
  1007. spec->ext_mic_pin = ext;
  1008. spec->int_mic_pin = fixed;
  1009. spec->dock_mic_pin = dock;
  1010. spec->auto_mic = 1;
  1011. if (!alc_auto_mic_check_imux(codec))
  1012. return;
  1013. snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
  1014. ext, fixed, dock);
  1015. spec->unsol_event = alc_sku_unsol_event;
  1016. }
  1017. /* check the availabilities of auto-mute and auto-mic switches */
  1018. static void alc_auto_check_switches(struct hda_codec *codec)
  1019. {
  1020. alc_init_auto_hp(codec);
  1021. alc_init_auto_mic(codec);
  1022. }
  1023. /*
  1024. * Realtek SSID verification
  1025. */
  1026. /* Could be any non-zero and even value. When used as fixup, tells
  1027. * the driver to ignore any present sku defines.
  1028. */
  1029. #define ALC_FIXUP_SKU_IGNORE (2)
  1030. static int alc_auto_parse_customize_define(struct hda_codec *codec)
  1031. {
  1032. unsigned int ass, tmp, i;
  1033. unsigned nid = 0;
  1034. struct alc_spec *spec = codec->spec;
  1035. spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
  1036. if (spec->cdefine.fixup) {
  1037. ass = spec->cdefine.sku_cfg;
  1038. if (ass == ALC_FIXUP_SKU_IGNORE)
  1039. return -1;
  1040. goto do_sku;
  1041. }
  1042. ass = codec->subsystem_id & 0xffff;
  1043. if (ass != codec->bus->pci->subsystem_device && (ass & 1))
  1044. goto do_sku;
  1045. nid = 0x1d;
  1046. if (codec->vendor_id == 0x10ec0260)
  1047. nid = 0x17;
  1048. ass = snd_hda_codec_get_pincfg(codec, nid);
  1049. if (!(ass & 1)) {
  1050. printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
  1051. codec->chip_name, ass);
  1052. return -1;
  1053. }
  1054. /* check sum */
  1055. tmp = 0;
  1056. for (i = 1; i < 16; i++) {
  1057. if ((ass >> i) & 1)
  1058. tmp++;
  1059. }
  1060. if (((ass >> 16) & 0xf) != tmp)
  1061. return -1;
  1062. spec->cdefine.port_connectivity = ass >> 30;
  1063. spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
  1064. spec->cdefine.check_sum = (ass >> 16) & 0xf;
  1065. spec->cdefine.customization = ass >> 8;
  1066. do_sku:
  1067. spec->cdefine.sku_cfg = ass;
  1068. spec->cdefine.external_amp = (ass & 0x38) >> 3;
  1069. spec->cdefine.platform_type = (ass & 0x4) >> 2;
  1070. spec->cdefine.swap = (ass & 0x2) >> 1;
  1071. spec->cdefine.override = ass & 0x1;
  1072. snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
  1073. nid, spec->cdefine.sku_cfg);
  1074. snd_printd("SKU: port_connectivity=0x%x\n",
  1075. spec->cdefine.port_connectivity);
  1076. snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
  1077. snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
  1078. snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
  1079. snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
  1080. snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
  1081. snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
  1082. snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
  1083. return 0;
  1084. }
  1085. /* return true if the given NID is found in the list */
  1086. static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  1087. {
  1088. return find_idx_in_nid_list(nid, list, nums) >= 0;
  1089. }
  1090. /* check subsystem ID and set up device-specific initialization;
  1091. * return 1 if initialized, 0 if invalid SSID
  1092. */
  1093. /* 32-bit subsystem ID for BIOS loading in HD Audio codec.
  1094. * 31 ~ 16 : Manufacture ID
  1095. * 15 ~ 8 : SKU ID
  1096. * 7 ~ 0 : Assembly ID
  1097. * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
  1098. */
  1099. static int alc_subsystem_id(struct hda_codec *codec,
  1100. hda_nid_t porta, hda_nid_t porte,
  1101. hda_nid_t portd, hda_nid_t porti)
  1102. {
  1103. unsigned int ass, tmp, i;
  1104. unsigned nid;
  1105. struct alc_spec *spec = codec->spec;
  1106. if (spec->cdefine.fixup) {
  1107. ass = spec->cdefine.sku_cfg;
  1108. if (ass == ALC_FIXUP_SKU_IGNORE)
  1109. return 0;
  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. /* invalid SSID, check the special NID pin defcfg instead */
  1116. /*
  1117. * 31~30 : port connectivity
  1118. * 29~21 : reserve
  1119. * 20 : PCBEEP input
  1120. * 19~16 : Check sum (15:1)
  1121. * 15~1 : Custom
  1122. * 0 : override
  1123. */
  1124. nid = 0x1d;
  1125. if (codec->vendor_id == 0x10ec0260)
  1126. nid = 0x17;
  1127. ass = snd_hda_codec_get_pincfg(codec, nid);
  1128. snd_printd("realtek: No valid SSID, "
  1129. "checking pincfg 0x%08x for NID 0x%x\n",
  1130. ass, nid);
  1131. if (!(ass & 1))
  1132. return 0;
  1133. if ((ass >> 30) != 1) /* no physical connection */
  1134. return 0;
  1135. /* check sum */
  1136. tmp = 0;
  1137. for (i = 1; i < 16; i++) {
  1138. if ((ass >> i) & 1)
  1139. tmp++;
  1140. }
  1141. if (((ass >> 16) & 0xf) != tmp)
  1142. return 0;
  1143. do_sku:
  1144. snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
  1145. ass & 0xffff, codec->vendor_id);
  1146. /*
  1147. * 0 : override
  1148. * 1 : Swap Jack
  1149. * 2 : 0 --> Desktop, 1 --> Laptop
  1150. * 3~5 : External Amplifier control
  1151. * 7~6 : Reserved
  1152. */
  1153. tmp = (ass & 0x38) >> 3; /* external Amp control */
  1154. switch (tmp) {
  1155. case 1:
  1156. spec->init_amp = ALC_INIT_GPIO1;
  1157. break;
  1158. case 3:
  1159. spec->init_amp = ALC_INIT_GPIO2;
  1160. break;
  1161. case 7:
  1162. spec->init_amp = ALC_INIT_GPIO3;
  1163. break;
  1164. case 5:
  1165. default:
  1166. spec->init_amp = ALC_INIT_DEFAULT;
  1167. break;
  1168. }
  1169. /* is laptop or Desktop and enable the function "Mute internal speaker
  1170. * when the external headphone out jack is plugged"
  1171. */
  1172. if (!(ass & 0x8000))
  1173. return 1;
  1174. /*
  1175. * 10~8 : Jack location
  1176. * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
  1177. * 14~13: Resvered
  1178. * 15 : 1 --> enable the function "Mute internal speaker
  1179. * when the external headphone out jack is plugged"
  1180. */
  1181. if (!spec->autocfg.hp_pins[0]) {
  1182. hda_nid_t nid;
  1183. tmp = (ass >> 11) & 0x3; /* HP to chassis */
  1184. if (tmp == 0)
  1185. nid = porta;
  1186. else if (tmp == 1)
  1187. nid = porte;
  1188. else if (tmp == 2)
  1189. nid = portd;
  1190. else if (tmp == 3)
  1191. nid = porti;
  1192. else
  1193. return 1;
  1194. if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
  1195. spec->autocfg.line_outs))
  1196. return 1;
  1197. spec->autocfg.hp_pins[0] = nid;
  1198. }
  1199. return 1;
  1200. }
  1201. /* Check the validity of ALC subsystem-id
  1202. * ports contains an array of 4 pin NIDs for port-A, E, D and I */
  1203. static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
  1204. {
  1205. if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
  1206. struct alc_spec *spec = codec->spec;
  1207. snd_printd("realtek: "
  1208. "Enable default setup for auto mode as fallback\n");
  1209. spec->init_amp = ALC_INIT_DEFAULT;
  1210. }
  1211. }
  1212. /*
  1213. * Fix-up pin default configurations and add default verbs
  1214. */
  1215. struct alc_pincfg {
  1216. hda_nid_t nid;
  1217. u32 val;
  1218. };
  1219. struct alc_model_fixup {
  1220. const int id;
  1221. const char *name;
  1222. };
  1223. struct alc_fixup {
  1224. int type;
  1225. bool chained;
  1226. int chain_id;
  1227. union {
  1228. unsigned int sku;
  1229. const struct alc_pincfg *pins;
  1230. const struct hda_verb *verbs;
  1231. void (*func)(struct hda_codec *codec,
  1232. const struct alc_fixup *fix,
  1233. int action);
  1234. } v;
  1235. };
  1236. enum {
  1237. ALC_FIXUP_INVALID,
  1238. ALC_FIXUP_SKU,
  1239. ALC_FIXUP_PINS,
  1240. ALC_FIXUP_VERBS,
  1241. ALC_FIXUP_FUNC,
  1242. };
  1243. enum {
  1244. ALC_FIXUP_ACT_PRE_PROBE,
  1245. ALC_FIXUP_ACT_PROBE,
  1246. ALC_FIXUP_ACT_INIT,
  1247. };
  1248. static void alc_apply_fixup(struct hda_codec *codec, int action)
  1249. {
  1250. struct alc_spec *spec = codec->spec;
  1251. int id = spec->fixup_id;
  1252. #ifdef CONFIG_SND_DEBUG_VERBOSE
  1253. const char *modelname = spec->fixup_name;
  1254. #endif
  1255. int depth = 0;
  1256. if (!spec->fixup_list)
  1257. return;
  1258. while (id >= 0) {
  1259. const struct alc_fixup *fix = spec->fixup_list + id;
  1260. const struct alc_pincfg *cfg;
  1261. switch (fix->type) {
  1262. case ALC_FIXUP_SKU:
  1263. if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
  1264. break;;
  1265. snd_printdd(KERN_INFO "hda_codec: %s: "
  1266. "Apply sku override for %s\n",
  1267. codec->chip_name, modelname);
  1268. spec->cdefine.sku_cfg = fix->v.sku;
  1269. spec->cdefine.fixup = 1;
  1270. break;
  1271. case ALC_FIXUP_PINS:
  1272. cfg = fix->v.pins;
  1273. if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
  1274. break;
  1275. snd_printdd(KERN_INFO "hda_codec: %s: "
  1276. "Apply pincfg for %s\n",
  1277. codec->chip_name, modelname);
  1278. for (; cfg->nid; cfg++)
  1279. snd_hda_codec_set_pincfg(codec, cfg->nid,
  1280. cfg->val);
  1281. break;
  1282. case ALC_FIXUP_VERBS:
  1283. if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
  1284. break;
  1285. snd_printdd(KERN_INFO "hda_codec: %s: "
  1286. "Apply fix-verbs for %s\n",
  1287. codec->chip_name, modelname);
  1288. add_verb(codec->spec, fix->v.verbs);
  1289. break;
  1290. case ALC_FIXUP_FUNC:
  1291. if (!fix->v.func)
  1292. break;
  1293. snd_printdd(KERN_INFO "hda_codec: %s: "
  1294. "Apply fix-func for %s\n",
  1295. codec->chip_name, modelname);
  1296. fix->v.func(codec, fix, action);
  1297. break;
  1298. default:
  1299. snd_printk(KERN_ERR "hda_codec: %s: "
  1300. "Invalid fixup type %d\n",
  1301. codec->chip_name, fix->type);
  1302. break;
  1303. }
  1304. if (!fix->chained)
  1305. break;
  1306. if (++depth > 10)
  1307. break;
  1308. id = fix->chain_id;
  1309. }
  1310. }
  1311. static void alc_pick_fixup(struct hda_codec *codec,
  1312. const struct alc_model_fixup *models,
  1313. const struct snd_pci_quirk *quirk,
  1314. const struct alc_fixup *fixlist)
  1315. {
  1316. struct alc_spec *spec = codec->spec;
  1317. int id = -1;
  1318. const char *name = NULL;
  1319. if (codec->modelname && models) {
  1320. while (models->name) {
  1321. if (!strcmp(codec->modelname, models->name)) {
  1322. id = models->id;
  1323. name = models->name;
  1324. break;
  1325. }
  1326. models++;
  1327. }
  1328. }
  1329. if (id < 0) {
  1330. quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
  1331. if (quirk) {
  1332. id = quirk->value;
  1333. #ifdef CONFIG_SND_DEBUG_VERBOSE
  1334. name = quirk->name;
  1335. #endif
  1336. }
  1337. }
  1338. spec->fixup_id = id;
  1339. if (id >= 0) {
  1340. spec->fixup_list = fixlist;
  1341. spec->fixup_name = name;
  1342. }
  1343. }
  1344. /*
  1345. * COEF access helper functions
  1346. */
  1347. static int alc_read_coef_idx(struct hda_codec *codec,
  1348. unsigned int coef_idx)
  1349. {
  1350. unsigned int val;
  1351. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
  1352. coef_idx);
  1353. val = snd_hda_codec_read(codec, 0x20, 0,
  1354. AC_VERB_GET_PROC_COEF, 0);
  1355. return val;
  1356. }
  1357. static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
  1358. unsigned int coef_val)
  1359. {
  1360. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
  1361. coef_idx);
  1362. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
  1363. coef_val);
  1364. }
  1365. /*
  1366. * Digital I/O handling
  1367. */
  1368. /* set right pin controls for digital I/O */
  1369. static void alc_auto_init_digital(struct hda_codec *codec)
  1370. {
  1371. struct alc_spec *spec = codec->spec;
  1372. int i;
  1373. hda_nid_t pin, dac;
  1374. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  1375. pin = spec->autocfg.dig_out_pins[i];
  1376. if (!pin)
  1377. continue;
  1378. snd_hda_codec_write(codec, pin, 0,
  1379. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  1380. if (!i)
  1381. dac = spec->multiout.dig_out_nid;
  1382. else
  1383. dac = spec->slave_dig_outs[i - 1];
  1384. if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
  1385. continue;
  1386. snd_hda_codec_write(codec, dac, 0,
  1387. AC_VERB_SET_AMP_GAIN_MUTE,
  1388. AMP_OUT_UNMUTE);
  1389. }
  1390. pin = spec->autocfg.dig_in_pin;
  1391. if (pin)
  1392. snd_hda_codec_write(codec, pin, 0,
  1393. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1394. PIN_IN);
  1395. }
  1396. /* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
  1397. static void alc_auto_parse_digital(struct hda_codec *codec)
  1398. {
  1399. struct alc_spec *spec = codec->spec;
  1400. int i, err;
  1401. hda_nid_t dig_nid;
  1402. /* support multiple SPDIFs; the secondary is set up as a slave */
  1403. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  1404. hda_nid_t conn[4];
  1405. err = snd_hda_get_connections(codec,
  1406. spec->autocfg.dig_out_pins[i],
  1407. conn, ARRAY_SIZE(conn));
  1408. if (err < 0)
  1409. continue;
  1410. dig_nid = conn[0]; /* assume the first element is audio-out */
  1411. if (!i) {
  1412. spec->multiout.dig_out_nid = dig_nid;
  1413. spec->dig_out_type = spec->autocfg.dig_out_type[0];
  1414. } else {
  1415. spec->multiout.slave_dig_outs = spec->slave_dig_outs;
  1416. if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
  1417. break;
  1418. spec->slave_dig_outs[i - 1] = dig_nid;
  1419. }
  1420. }
  1421. if (spec->autocfg.dig_in_pin) {
  1422. dig_nid = codec->start_nid;
  1423. for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
  1424. unsigned int wcaps = get_wcaps(codec, dig_nid);
  1425. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  1426. continue;
  1427. if (!(wcaps & AC_WCAP_DIGITAL))
  1428. continue;
  1429. if (!(wcaps & AC_WCAP_CONN_LIST))
  1430. continue;
  1431. err = get_connection_index(codec, dig_nid,
  1432. spec->autocfg.dig_in_pin);
  1433. if (err >= 0) {
  1434. spec->dig_in_nid = dig_nid;
  1435. break;
  1436. }
  1437. }
  1438. }
  1439. }
  1440. /*
  1441. * capture mixer elements
  1442. */
  1443. static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
  1444. struct snd_ctl_elem_info *uinfo)
  1445. {
  1446. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1447. struct alc_spec *spec = codec->spec;
  1448. unsigned long val;
  1449. int err;
  1450. mutex_lock(&codec->control_mutex);
  1451. if (spec->vol_in_capsrc)
  1452. val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
  1453. else
  1454. val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
  1455. kcontrol->private_value = val;
  1456. err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
  1457. mutex_unlock(&codec->control_mutex);
  1458. return err;
  1459. }
  1460. static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  1461. unsigned int size, unsigned int __user *tlv)
  1462. {
  1463. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1464. struct alc_spec *spec = codec->spec;
  1465. unsigned long val;
  1466. int err;
  1467. mutex_lock(&codec->control_mutex);
  1468. if (spec->vol_in_capsrc)
  1469. val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
  1470. else
  1471. val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
  1472. kcontrol->private_value = val;
  1473. err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
  1474. mutex_unlock(&codec->control_mutex);
  1475. return err;
  1476. }
  1477. typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
  1478. struct snd_ctl_elem_value *ucontrol);
  1479. static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
  1480. struct snd_ctl_elem_value *ucontrol,
  1481. getput_call_t func, bool check_adc_switch)
  1482. {
  1483. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1484. struct alc_spec *spec = codec->spec;
  1485. int i, err = 0;
  1486. mutex_lock(&codec->control_mutex);
  1487. if (check_adc_switch && spec->dyn_adc_switch) {
  1488. for (i = 0; i < spec->num_adc_nids; i++) {
  1489. kcontrol->private_value =
  1490. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
  1491. 3, 0, HDA_INPUT);
  1492. err = func(kcontrol, ucontrol);
  1493. if (err < 0)
  1494. goto error;
  1495. }
  1496. } else {
  1497. i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1498. if (spec->vol_in_capsrc)
  1499. kcontrol->private_value =
  1500. HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
  1501. 3, 0, HDA_OUTPUT);
  1502. else
  1503. kcontrol->private_value =
  1504. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
  1505. 3, 0, HDA_INPUT);
  1506. err = func(kcontrol, ucontrol);
  1507. }
  1508. error:
  1509. mutex_unlock(&codec->control_mutex);
  1510. return err;
  1511. }
  1512. static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
  1513. struct snd_ctl_elem_value *ucontrol)
  1514. {
  1515. return alc_cap_getput_caller(kcontrol, ucontrol,
  1516. snd_hda_mixer_amp_volume_get, false);
  1517. }
  1518. static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
  1519. struct snd_ctl_elem_value *ucontrol)
  1520. {
  1521. return alc_cap_getput_caller(kcontrol, ucontrol,
  1522. snd_hda_mixer_amp_volume_put, true);
  1523. }
  1524. /* capture mixer elements */
  1525. #define alc_cap_sw_info snd_ctl_boolean_stereo_info
  1526. static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
  1527. struct snd_ctl_elem_value *ucontrol)
  1528. {
  1529. return alc_cap_getput_caller(kcontrol, ucontrol,
  1530. snd_hda_mixer_amp_switch_get, false);
  1531. }
  1532. static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
  1533. struct snd_ctl_elem_value *ucontrol)
  1534. {
  1535. return alc_cap_getput_caller(kcontrol, ucontrol,
  1536. snd_hda_mixer_amp_switch_put, true);
  1537. }
  1538. #define _DEFINE_CAPMIX(num) \
  1539. { \
  1540. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1541. .name = "Capture Switch", \
  1542. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  1543. .count = num, \
  1544. .info = alc_cap_sw_info, \
  1545. .get = alc_cap_sw_get, \
  1546. .put = alc_cap_sw_put, \
  1547. }, \
  1548. { \
  1549. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1550. .name = "Capture Volume", \
  1551. .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  1552. SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  1553. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
  1554. .count = num, \
  1555. .info = alc_cap_vol_info, \
  1556. .get = alc_cap_vol_get, \
  1557. .put = alc_cap_vol_put, \
  1558. .tlv = { .c = alc_cap_vol_tlv }, \
  1559. }
  1560. #define _DEFINE_CAPSRC(num) \
  1561. { \
  1562. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1563. /* .name = "Capture Source", */ \
  1564. .name = "Input Source", \
  1565. .count = num, \
  1566. .info = alc_mux_enum_info, \
  1567. .get = alc_mux_enum_get, \
  1568. .put = alc_mux_enum_put, \
  1569. }
  1570. #define DEFINE_CAPMIX(num) \
  1571. static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
  1572. _DEFINE_CAPMIX(num), \
  1573. _DEFINE_CAPSRC(num), \
  1574. { } /* end */ \
  1575. }
  1576. #define DEFINE_CAPMIX_NOSRC(num) \
  1577. static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
  1578. _DEFINE_CAPMIX(num), \
  1579. { } /* end */ \
  1580. }
  1581. /* up to three ADCs */
  1582. DEFINE_CAPMIX(1);
  1583. DEFINE_CAPMIX(2);
  1584. DEFINE_CAPMIX(3);
  1585. DEFINE_CAPMIX_NOSRC(1);
  1586. DEFINE_CAPMIX_NOSRC(2);
  1587. DEFINE_CAPMIX_NOSRC(3);
  1588. /*
  1589. * virtual master controls
  1590. */
  1591. /*
  1592. * slave controls for virtual master
  1593. */
  1594. static const char * const alc_slave_vols[] = {
  1595. "Front Playback Volume",
  1596. "Surround Playback Volume",
  1597. "Center Playback Volume",
  1598. "LFE Playback Volume",
  1599. "Side Playback Volume",
  1600. "Headphone Playback Volume",
  1601. "Speaker Playback Volume",
  1602. "Mono Playback Volume",
  1603. "Line-Out Playback Volume",
  1604. NULL,
  1605. };
  1606. static const char * const alc_slave_sws[] = {
  1607. "Front Playback Switch",
  1608. "Surround Playback Switch",
  1609. "Center Playback Switch",
  1610. "LFE Playback Switch",
  1611. "Side Playback Switch",
  1612. "Headphone Playback Switch",
  1613. "Speaker Playback Switch",
  1614. "Mono Playback Switch",
  1615. "IEC958 Playback Switch",
  1616. "Line-Out Playback Switch",
  1617. NULL,
  1618. };
  1619. /*
  1620. * build control elements
  1621. */
  1622. #define NID_MAPPING (-1)
  1623. #define SUBDEV_SPEAKER_ (0 << 6)
  1624. #define SUBDEV_HP_ (1 << 6)
  1625. #define SUBDEV_LINE_ (2 << 6)
  1626. #define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
  1627. #define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
  1628. #define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
  1629. static void alc_free_kctls(struct hda_codec *codec);
  1630. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1631. /* additional beep mixers; the actual parameters are overwritten at build */
  1632. static const struct snd_kcontrol_new alc_beep_mixer[] = {
  1633. HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
  1634. HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
  1635. { } /* end */
  1636. };
  1637. #endif
  1638. static int alc_build_controls(struct hda_codec *codec)
  1639. {
  1640. struct alc_spec *spec = codec->spec;
  1641. struct snd_kcontrol *kctl = NULL;
  1642. const struct snd_kcontrol_new *knew;
  1643. int i, j, err;
  1644. unsigned int u;
  1645. hda_nid_t nid;
  1646. for (i = 0; i < spec->num_mixers; i++) {
  1647. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1648. if (err < 0)
  1649. return err;
  1650. }
  1651. if (spec->cap_mixer) {
  1652. err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
  1653. if (err < 0)
  1654. return err;
  1655. }
  1656. if (spec->multiout.dig_out_nid) {
  1657. err = snd_hda_create_spdif_out_ctls(codec,
  1658. spec->multiout.dig_out_nid,
  1659. spec->multiout.dig_out_nid);
  1660. if (err < 0)
  1661. return err;
  1662. if (!spec->no_analog) {
  1663. err = snd_hda_create_spdif_share_sw(codec,
  1664. &spec->multiout);
  1665. if (err < 0)
  1666. return err;
  1667. spec->multiout.share_spdif = 1;
  1668. }
  1669. }
  1670. if (spec->dig_in_nid) {
  1671. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1672. if (err < 0)
  1673. return err;
  1674. }
  1675. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  1676. /* create beep controls if needed */
  1677. if (spec->beep_amp) {
  1678. const struct snd_kcontrol_new *knew;
  1679. for (knew = alc_beep_mixer; knew->name; knew++) {
  1680. struct snd_kcontrol *kctl;
  1681. kctl = snd_ctl_new1(knew, codec);
  1682. if (!kctl)
  1683. return -ENOMEM;
  1684. kctl->private_value = spec->beep_amp;
  1685. err = snd_hda_ctl_add(codec, 0, kctl);
  1686. if (err < 0)
  1687. return err;
  1688. }
  1689. }
  1690. #endif
  1691. /* if we have no master control, let's create it */
  1692. if (!spec->no_analog &&
  1693. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  1694. unsigned int vmaster_tlv[4];
  1695. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  1696. HDA_OUTPUT, vmaster_tlv);
  1697. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  1698. vmaster_tlv, alc_slave_vols);
  1699. if (err < 0)
  1700. return err;
  1701. }
  1702. if (!spec->no_analog &&
  1703. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  1704. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  1705. NULL, alc_slave_sws);
  1706. if (err < 0)
  1707. return err;
  1708. }
  1709. /* assign Capture Source enums to NID */
  1710. if (spec->capsrc_nids || spec->adc_nids) {
  1711. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  1712. if (!kctl)
  1713. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  1714. for (i = 0; kctl && i < kctl->count; i++) {
  1715. const hda_nid_t *nids = spec->capsrc_nids;
  1716. if (!nids)
  1717. nids = spec->adc_nids;
  1718. err = snd_hda_add_nid(codec, kctl, i, nids[i]);
  1719. if (err < 0)
  1720. return err;
  1721. }
  1722. }
  1723. if (spec->cap_mixer && spec->adc_nids) {
  1724. const char *kname = kctl ? kctl->id.name : NULL;
  1725. for (knew = spec->cap_mixer; knew->name; knew++) {
  1726. if (kname && strcmp(knew->name, kname) == 0)
  1727. continue;
  1728. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1729. for (i = 0; kctl && i < kctl->count; i++) {
  1730. err = snd_hda_add_nid(codec, kctl, i,
  1731. spec->adc_nids[i]);
  1732. if (err < 0)
  1733. return err;
  1734. }
  1735. }
  1736. }
  1737. /* other nid->control mapping */
  1738. for (i = 0; i < spec->num_mixers; i++) {
  1739. for (knew = spec->mixers[i]; knew->name; knew++) {
  1740. if (knew->iface != NID_MAPPING)
  1741. continue;
  1742. kctl = snd_hda_find_mixer_ctl(codec, knew->name);
  1743. if (kctl == NULL)
  1744. continue;
  1745. u = knew->subdevice;
  1746. for (j = 0; j < 4; j++, u >>= 8) {
  1747. nid = u & 0x3f;
  1748. if (nid == 0)
  1749. continue;
  1750. switch (u & 0xc0) {
  1751. case SUBDEV_SPEAKER_:
  1752. nid = spec->autocfg.speaker_pins[nid];
  1753. break;
  1754. case SUBDEV_LINE_:
  1755. nid = spec->autocfg.line_out_pins[nid];
  1756. break;
  1757. case SUBDEV_HP_:
  1758. nid = spec->autocfg.hp_pins[nid];
  1759. break;
  1760. default:
  1761. continue;
  1762. }
  1763. err = snd_hda_add_nid(codec, kctl, 0, nid);
  1764. if (err < 0)
  1765. return err;
  1766. }
  1767. u = knew->private_value;
  1768. for (j = 0; j < 4; j++, u >>= 8) {
  1769. nid = u & 0xff;
  1770. if (nid == 0)
  1771. continue;
  1772. err = snd_hda_add_nid(codec, kctl, 0, nid);
  1773. if (err < 0)
  1774. return err;
  1775. }
  1776. }
  1777. }
  1778. alc_free_kctls(codec); /* no longer needed */
  1779. return 0;
  1780. }
  1781. /*
  1782. * Common callbacks
  1783. */
  1784. static void alc_init_special_input_src(struct hda_codec *codec);
  1785. static int alc_init(struct hda_codec *codec)
  1786. {
  1787. struct alc_spec *spec = codec->spec;
  1788. unsigned int i;
  1789. alc_fix_pll(codec);
  1790. alc_auto_init_amp(codec, spec->init_amp);
  1791. for (i = 0; i < spec->num_init_verbs; i++)
  1792. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  1793. alc_init_special_input_src(codec);
  1794. if (spec->init_hook)
  1795. spec->init_hook(codec);
  1796. alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
  1797. hda_call_check_power_status(codec, 0x01);
  1798. return 0;
  1799. }
  1800. static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
  1801. {
  1802. struct alc_spec *spec = codec->spec;
  1803. if (spec->unsol_event)
  1804. spec->unsol_event(codec, res);
  1805. }
  1806. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1807. static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1808. {
  1809. struct alc_spec *spec = codec->spec;
  1810. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1811. }
  1812. #endif
  1813. /*
  1814. * Analog playback callbacks
  1815. */
  1816. static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1817. struct hda_codec *codec,
  1818. struct snd_pcm_substream *substream)
  1819. {
  1820. struct alc_spec *spec = codec->spec;
  1821. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  1822. hinfo);
  1823. }
  1824. static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1825. struct hda_codec *codec,
  1826. unsigned int stream_tag,
  1827. unsigned int format,
  1828. struct snd_pcm_substream *substream)
  1829. {
  1830. struct alc_spec *spec = codec->spec;
  1831. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  1832. stream_tag, format, substream);
  1833. }
  1834. static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1835. struct hda_codec *codec,
  1836. struct snd_pcm_substream *substream)
  1837. {
  1838. struct alc_spec *spec = codec->spec;
  1839. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1840. }
  1841. /*
  1842. * Digital out
  1843. */
  1844. static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1845. struct hda_codec *codec,
  1846. struct snd_pcm_substream *substream)
  1847. {
  1848. struct alc_spec *spec = codec->spec;
  1849. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1850. }
  1851. static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1852. struct hda_codec *codec,
  1853. unsigned int stream_tag,
  1854. unsigned int format,
  1855. struct snd_pcm_substream *substream)
  1856. {
  1857. struct alc_spec *spec = codec->spec;
  1858. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1859. stream_tag, format, substream);
  1860. }
  1861. static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1862. struct hda_codec *codec,
  1863. struct snd_pcm_substream *substream)
  1864. {
  1865. struct alc_spec *spec = codec->spec;
  1866. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1867. }
  1868. static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1869. struct hda_codec *codec,
  1870. struct snd_pcm_substream *substream)
  1871. {
  1872. struct alc_spec *spec = codec->spec;
  1873. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1874. }
  1875. /*
  1876. * Analog capture
  1877. */
  1878. static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1879. struct hda_codec *codec,
  1880. unsigned int stream_tag,
  1881. unsigned int format,
  1882. struct snd_pcm_substream *substream)
  1883. {
  1884. struct alc_spec *spec = codec->spec;
  1885. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
  1886. stream_tag, 0, format);
  1887. return 0;
  1888. }
  1889. static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1890. struct hda_codec *codec,
  1891. struct snd_pcm_substream *substream)
  1892. {
  1893. struct alc_spec *spec = codec->spec;
  1894. snd_hda_codec_cleanup_stream(codec,
  1895. spec->adc_nids[substream->number + 1]);
  1896. return 0;
  1897. }
  1898. /* analog capture with dynamic dual-adc changes */
  1899. static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1900. struct hda_codec *codec,
  1901. unsigned int stream_tag,
  1902. unsigned int format,
  1903. struct snd_pcm_substream *substream)
  1904. {
  1905. struct alc_spec *spec = codec->spec;
  1906. spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
  1907. spec->cur_adc_stream_tag = stream_tag;
  1908. spec->cur_adc_format = format;
  1909. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  1910. return 0;
  1911. }
  1912. static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1913. struct hda_codec *codec,
  1914. struct snd_pcm_substream *substream)
  1915. {
  1916. struct alc_spec *spec = codec->spec;
  1917. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1918. spec->cur_adc = 0;
  1919. return 0;
  1920. }
  1921. static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
  1922. .substreams = 1,
  1923. .channels_min = 2,
  1924. .channels_max = 2,
  1925. .nid = 0, /* fill later */
  1926. .ops = {
  1927. .prepare = dyn_adc_capture_pcm_prepare,
  1928. .cleanup = dyn_adc_capture_pcm_cleanup
  1929. },
  1930. };
  1931. /*
  1932. */
  1933. static const struct hda_pcm_stream alc_pcm_analog_playback = {
  1934. .substreams = 1,
  1935. .channels_min = 2,
  1936. .channels_max = 8,
  1937. /* NID is set in alc_build_pcms */
  1938. .ops = {
  1939. .open = alc_playback_pcm_open,
  1940. .prepare = alc_playback_pcm_prepare,
  1941. .cleanup = alc_playback_pcm_cleanup
  1942. },
  1943. };
  1944. static const struct hda_pcm_stream alc_pcm_analog_capture = {
  1945. .substreams = 1,
  1946. .channels_min = 2,
  1947. .channels_max = 2,
  1948. /* NID is set in alc_build_pcms */
  1949. };
  1950. static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
  1951. .substreams = 1,
  1952. .channels_min = 2,
  1953. .channels_max = 2,
  1954. /* NID is set in alc_build_pcms */
  1955. };
  1956. static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
  1957. .substreams = 2, /* can be overridden */
  1958. .channels_min = 2,
  1959. .channels_max = 2,
  1960. /* NID is set in alc_build_pcms */
  1961. .ops = {
  1962. .prepare = alc_alt_capture_pcm_prepare,
  1963. .cleanup = alc_alt_capture_pcm_cleanup
  1964. },
  1965. };
  1966. static const struct hda_pcm_stream alc_pcm_digital_playback = {
  1967. .substreams = 1,
  1968. .channels_min = 2,
  1969. .channels_max = 2,
  1970. /* NID is set in alc_build_pcms */
  1971. .ops = {
  1972. .open = alc_dig_playback_pcm_open,
  1973. .close = alc_dig_playback_pcm_close,
  1974. .prepare = alc_dig_playback_pcm_prepare,
  1975. .cleanup = alc_dig_playback_pcm_cleanup
  1976. },
  1977. };
  1978. static const struct hda_pcm_stream alc_pcm_digital_capture = {
  1979. .substreams = 1,
  1980. .channels_min = 2,
  1981. .channels_max = 2,
  1982. /* NID is set in alc_build_pcms */
  1983. };
  1984. /* Used by alc_build_pcms to flag that a PCM has no playback stream */
  1985. static const struct hda_pcm_stream alc_pcm_null_stream = {
  1986. .substreams = 0,
  1987. .channels_min = 0,
  1988. .channels_max = 0,
  1989. };
  1990. static int alc_build_pcms(struct hda_codec *codec)
  1991. {
  1992. struct alc_spec *spec = codec->spec;
  1993. struct hda_pcm *info = spec->pcm_rec;
  1994. const struct hda_pcm_stream *p;
  1995. int i;
  1996. codec->num_pcms = 1;
  1997. codec->pcm_info = info;
  1998. if (spec->no_analog)
  1999. goto skip_analog;
  2000. snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
  2001. "%s Analog", codec->chip_name);
  2002. info->name = spec->stream_name_analog;
  2003. if (spec->multiout.dac_nids > 0) {
  2004. p = spec->stream_analog_playback;
  2005. if (!p)
  2006. p = &alc_pcm_analog_playback;
  2007. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2008. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  2009. }
  2010. if (spec->adc_nids) {
  2011. p = spec->stream_analog_capture;
  2012. if (!p) {
  2013. if (spec->dyn_adc_switch)
  2014. p = &dyn_adc_pcm_analog_capture;
  2015. else
  2016. p = &alc_pcm_analog_capture;
  2017. }
  2018. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2019. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  2020. }
  2021. if (spec->channel_mode) {
  2022. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
  2023. for (i = 0; i < spec->num_channel_mode; i++) {
  2024. if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
  2025. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
  2026. }
  2027. }
  2028. }
  2029. skip_analog:
  2030. /* SPDIF for stream index #1 */
  2031. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  2032. snprintf(spec->stream_name_digital,
  2033. sizeof(spec->stream_name_digital),
  2034. "%s Digital", codec->chip_name);
  2035. codec->num_pcms = 2;
  2036. codec->slave_dig_outs = spec->multiout.slave_dig_outs;
  2037. info = spec->pcm_rec + 1;
  2038. info->name = spec->stream_name_digital;
  2039. if (spec->dig_out_type)
  2040. info->pcm_type = spec->dig_out_type;
  2041. else
  2042. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  2043. if (spec->multiout.dig_out_nid) {
  2044. p = spec->stream_digital_playback;
  2045. if (!p)
  2046. p = &alc_pcm_digital_playback;
  2047. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2048. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  2049. }
  2050. if (spec->dig_in_nid) {
  2051. p = spec->stream_digital_capture;
  2052. if (!p)
  2053. p = &alc_pcm_digital_capture;
  2054. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2055. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  2056. }
  2057. /* FIXME: do we need this for all Realtek codec models? */
  2058. codec->spdif_status_reset = 1;
  2059. }
  2060. if (spec->no_analog)
  2061. return 0;
  2062. /* If the use of more than one ADC is requested for the current
  2063. * model, configure a second analog capture-only PCM.
  2064. */
  2065. /* Additional Analaog capture for index #2 */
  2066. if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
  2067. codec->num_pcms = 3;
  2068. info = spec->pcm_rec + 2;
  2069. info->name = spec->stream_name_analog;
  2070. if (spec->alt_dac_nid) {
  2071. p = spec->stream_analog_alt_playback;
  2072. if (!p)
  2073. p = &alc_pcm_analog_alt_playback;
  2074. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
  2075. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  2076. spec->alt_dac_nid;
  2077. } else {
  2078. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  2079. alc_pcm_null_stream;
  2080. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
  2081. }
  2082. if (spec->num_adc_nids > 1) {
  2083. p = spec->stream_analog_alt_capture;
  2084. if (!p)
  2085. p = &alc_pcm_analog_alt_capture;
  2086. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
  2087. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  2088. spec->adc_nids[1];
  2089. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  2090. spec->num_adc_nids - 1;
  2091. } else {
  2092. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  2093. alc_pcm_null_stream;
  2094. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
  2095. }
  2096. }
  2097. return 0;
  2098. }
  2099. static inline void alc_shutup(struct hda_codec *codec)
  2100. {
  2101. struct alc_spec *spec = codec->spec;
  2102. if (spec && spec->shutup)
  2103. spec->shutup(codec);
  2104. snd_hda_shutup_pins(codec);
  2105. }
  2106. static void alc_free_kctls(struct hda_codec *codec)
  2107. {
  2108. struct alc_spec *spec = codec->spec;
  2109. if (spec->kctls.list) {
  2110. struct snd_kcontrol_new *kctl = spec->kctls.list;
  2111. int i;
  2112. for (i = 0; i < spec->kctls.used; i++)
  2113. kfree(kctl[i].name);
  2114. }
  2115. snd_array_free(&spec->kctls);
  2116. }
  2117. static void alc_free(struct hda_codec *codec)
  2118. {
  2119. struct alc_spec *spec = codec->spec;
  2120. if (!spec)
  2121. return;
  2122. alc_shutup(codec);
  2123. snd_hda_input_jack_free(codec);
  2124. alc_free_kctls(codec);
  2125. kfree(spec);
  2126. snd_hda_detach_beep_device(codec);
  2127. }
  2128. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2129. static void alc_power_eapd(struct hda_codec *codec)
  2130. {
  2131. alc_auto_setup_eapd(codec, false);
  2132. }
  2133. static int alc_suspend(struct hda_codec *codec, pm_message_t state)
  2134. {
  2135. struct alc_spec *spec = codec->spec;
  2136. alc_shutup(codec);
  2137. if (spec && spec->power_hook)
  2138. spec->power_hook(codec);
  2139. return 0;
  2140. }
  2141. #endif
  2142. #ifdef CONFIG_PM
  2143. static int alc_resume(struct hda_codec *codec)
  2144. {
  2145. msleep(150); /* to avoid pop noise */
  2146. codec->patch_ops.init(codec);
  2147. snd_hda_codec_resume_amp(codec);
  2148. snd_hda_codec_resume_cache(codec);
  2149. hda_call_check_power_status(codec, 0x01);
  2150. return 0;
  2151. }
  2152. #endif
  2153. /*
  2154. */
  2155. static const struct hda_codec_ops alc_patch_ops = {
  2156. .build_controls = alc_build_controls,
  2157. .build_pcms = alc_build_pcms,
  2158. .init = alc_init,
  2159. .free = alc_free,
  2160. .unsol_event = alc_unsol_event,
  2161. #ifdef CONFIG_PM
  2162. .resume = alc_resume,
  2163. #endif
  2164. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2165. .suspend = alc_suspend,
  2166. .check_power_status = alc_check_power_status,
  2167. #endif
  2168. .reboot_notify = alc_shutup,
  2169. };
  2170. /* replace the codec chip_name with the given string */
  2171. static int alc_codec_rename(struct hda_codec *codec, const char *name)
  2172. {
  2173. kfree(codec->chip_name);
  2174. codec->chip_name = kstrdup(name, GFP_KERNEL);
  2175. if (!codec->chip_name) {
  2176. alc_free(codec);
  2177. return -ENOMEM;
  2178. }
  2179. return 0;
  2180. }
  2181. /*
  2182. * Automatic parse of I/O pins from the BIOS configuration
  2183. */
  2184. enum {
  2185. ALC_CTL_WIDGET_VOL,
  2186. ALC_CTL_WIDGET_MUTE,
  2187. ALC_CTL_BIND_MUTE,
  2188. };
  2189. static const struct snd_kcontrol_new alc_control_templates[] = {
  2190. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2191. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2192. HDA_BIND_MUTE(NULL, 0, 0, 0),
  2193. };
  2194. /* add dynamic controls */
  2195. static int add_control(struct alc_spec *spec, int type, const char *name,
  2196. int cidx, unsigned long val)
  2197. {
  2198. struct snd_kcontrol_new *knew;
  2199. knew = alc_kcontrol_new(spec);
  2200. if (!knew)
  2201. return -ENOMEM;
  2202. *knew = alc_control_templates[type];
  2203. knew->name = kstrdup(name, GFP_KERNEL);
  2204. if (!knew->name)
  2205. return -ENOMEM;
  2206. knew->index = cidx;
  2207. if (get_amp_nid_(val))
  2208. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  2209. knew->private_value = val;
  2210. return 0;
  2211. }
  2212. static int add_control_with_pfx(struct alc_spec *spec, int type,
  2213. const char *pfx, const char *dir,
  2214. const char *sfx, int cidx, unsigned long val)
  2215. {
  2216. char name[32];
  2217. snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
  2218. return add_control(spec, type, name, cidx, val);
  2219. }
  2220. #define add_pb_vol_ctrl(spec, type, pfx, val) \
  2221. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
  2222. #define add_pb_sw_ctrl(spec, type, pfx, val) \
  2223. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
  2224. #define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
  2225. add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
  2226. #define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
  2227. add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
  2228. static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
  2229. bool can_be_master, int *index)
  2230. {
  2231. struct auto_pin_cfg *cfg = &spec->autocfg;
  2232. static const char * const chname[4] = {
  2233. "Front", "Surround", NULL /*CLFE*/, "Side"
  2234. };
  2235. *index = 0;
  2236. if (cfg->line_outs == 1 && !spec->multi_ios &&
  2237. !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
  2238. return "Master";
  2239. switch (cfg->line_out_type) {
  2240. case AUTO_PIN_SPEAKER_OUT:
  2241. if (cfg->line_outs == 1)
  2242. return "Speaker";
  2243. break;
  2244. case AUTO_PIN_HP_OUT:
  2245. /* for multi-io case, only the primary out */
  2246. if (ch && spec->multi_ios)
  2247. break;
  2248. *index = ch;
  2249. return "Headphone";
  2250. default:
  2251. if (cfg->line_outs == 1 && !spec->multi_ios)
  2252. return "PCM";
  2253. break;
  2254. }
  2255. return chname[ch];
  2256. }
  2257. /* create input playback/capture controls for the given pin */
  2258. static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
  2259. const char *ctlname, int ctlidx,
  2260. int idx, hda_nid_t mix_nid)
  2261. {
  2262. int err;
  2263. err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
  2264. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2265. if (err < 0)
  2266. return err;
  2267. err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
  2268. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  2269. if (err < 0)
  2270. return err;
  2271. return 0;
  2272. }
  2273. static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
  2274. {
  2275. unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
  2276. return (pincap & AC_PINCAP_IN) != 0;
  2277. }
  2278. /* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
  2279. static int alc_auto_fill_adc_caps(struct hda_codec *codec)
  2280. {
  2281. struct alc_spec *spec = codec->spec;
  2282. hda_nid_t nid;
  2283. hda_nid_t *adc_nids = spec->private_adc_nids;
  2284. hda_nid_t *cap_nids = spec->private_capsrc_nids;
  2285. int max_nums = ARRAY_SIZE(spec->private_adc_nids);
  2286. bool indep_capsrc = false;
  2287. int i, nums = 0;
  2288. nid = codec->start_nid;
  2289. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2290. hda_nid_t src;
  2291. const hda_nid_t *list;
  2292. unsigned int caps = get_wcaps(codec, nid);
  2293. int type = get_wcaps_type(caps);
  2294. if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
  2295. continue;
  2296. adc_nids[nums] = nid;
  2297. cap_nids[nums] = nid;
  2298. src = nid;
  2299. for (;;) {
  2300. int n;
  2301. type = get_wcaps_type(get_wcaps(codec, src));
  2302. if (type == AC_WID_PIN)
  2303. break;
  2304. if (type == AC_WID_AUD_SEL) {
  2305. cap_nids[nums] = src;
  2306. indep_capsrc = true;
  2307. break;
  2308. }
  2309. n = snd_hda_get_conn_list(codec, src, &list);
  2310. if (n > 1) {
  2311. cap_nids[nums] = src;
  2312. indep_capsrc = true;
  2313. break;
  2314. } else if (n != 1)
  2315. break;
  2316. src = *list;
  2317. }
  2318. if (++nums >= max_nums)
  2319. break;
  2320. }
  2321. spec->adc_nids = spec->private_adc_nids;
  2322. spec->capsrc_nids = spec->private_capsrc_nids;
  2323. spec->num_adc_nids = nums;
  2324. return nums;
  2325. }
  2326. /* create playback/capture controls for input pins */
  2327. static int alc_auto_create_input_ctls(struct hda_codec *codec)
  2328. {
  2329. struct alc_spec *spec = codec->spec;
  2330. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2331. hda_nid_t mixer = spec->mixer_nid;
  2332. struct hda_input_mux *imux = &spec->private_imux[0];
  2333. int num_adcs;
  2334. int i, c, err, idx, type_idx = 0;
  2335. const char *prev_label = NULL;
  2336. num_adcs = alc_auto_fill_adc_caps(codec);
  2337. if (num_adcs < 0)
  2338. return 0;
  2339. for (i = 0; i < cfg->num_inputs; i++) {
  2340. hda_nid_t pin;
  2341. const char *label;
  2342. pin = cfg->inputs[i].pin;
  2343. if (!alc_is_input_pin(codec, pin))
  2344. continue;
  2345. label = hda_get_autocfg_input_label(codec, cfg, i);
  2346. if (prev_label && !strcmp(label, prev_label))
  2347. type_idx++;
  2348. else
  2349. type_idx = 0;
  2350. prev_label = label;
  2351. if (mixer) {
  2352. idx = get_connection_index(codec, mixer, pin);
  2353. if (idx >= 0) {
  2354. err = new_analog_input(spec, pin,
  2355. label, type_idx,
  2356. idx, mixer);
  2357. if (err < 0)
  2358. return err;
  2359. }
  2360. }
  2361. for (c = 0; c < num_adcs; c++) {
  2362. hda_nid_t cap = spec->capsrc_nids ?
  2363. spec->capsrc_nids[c] : spec->adc_nids[c];
  2364. idx = get_connection_index(codec, cap, pin);
  2365. if (idx >= 0) {
  2366. spec->imux_pins[imux->num_items] = pin;
  2367. snd_hda_add_imux_item(imux, label, idx, NULL);
  2368. break;
  2369. }
  2370. }
  2371. }
  2372. spec->num_mux_defs = 1;
  2373. spec->input_mux = imux;
  2374. return 0;
  2375. }
  2376. static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
  2377. unsigned int pin_type)
  2378. {
  2379. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  2380. pin_type);
  2381. /* unmute pin */
  2382. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  2383. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2384. AMP_OUT_UNMUTE);
  2385. }
  2386. static int get_pin_type(int line_out_type)
  2387. {
  2388. if (line_out_type == AUTO_PIN_HP_OUT)
  2389. return PIN_HP;
  2390. else
  2391. return PIN_OUT;
  2392. }
  2393. static void alc_auto_init_analog_input(struct hda_codec *codec)
  2394. {
  2395. struct alc_spec *spec = codec->spec;
  2396. struct auto_pin_cfg *cfg = &spec->autocfg;
  2397. int i;
  2398. for (i = 0; i < cfg->num_inputs; i++) {
  2399. hda_nid_t nid = cfg->inputs[i].pin;
  2400. if (alc_is_input_pin(codec, nid)) {
  2401. alc_set_input_pin(codec, nid, cfg->inputs[i].type);
  2402. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  2403. snd_hda_codec_write(codec, nid, 0,
  2404. AC_VERB_SET_AMP_GAIN_MUTE,
  2405. AMP_OUT_MUTE);
  2406. }
  2407. }
  2408. /* mute all loopback inputs */
  2409. if (spec->mixer_nid) {
  2410. int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
  2411. for (i = 0; i < nums; i++)
  2412. snd_hda_codec_write(codec, spec->mixer_nid, 0,
  2413. AC_VERB_SET_AMP_GAIN_MUTE,
  2414. AMP_IN_MUTE(i));
  2415. }
  2416. }
  2417. /* convert from MIX nid to DAC */
  2418. static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
  2419. {
  2420. hda_nid_t list[5];
  2421. int i, num;
  2422. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
  2423. return nid;
  2424. num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
  2425. for (i = 0; i < num; i++) {
  2426. if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
  2427. return list[i];
  2428. }
  2429. return 0;
  2430. }
  2431. /* go down to the selector widget before the mixer */
  2432. static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
  2433. {
  2434. hda_nid_t srcs[5];
  2435. int num = snd_hda_get_connections(codec, pin, srcs,
  2436. ARRAY_SIZE(srcs));
  2437. if (num != 1 ||
  2438. get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
  2439. return pin;
  2440. return srcs[0];
  2441. }
  2442. /* get MIX nid connected to the given pin targeted to DAC */
  2443. static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
  2444. hda_nid_t dac)
  2445. {
  2446. hda_nid_t mix[5];
  2447. int i, num;
  2448. pin = alc_go_down_to_selector(codec, pin);
  2449. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2450. for (i = 0; i < num; i++) {
  2451. if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
  2452. return mix[i];
  2453. }
  2454. return 0;
  2455. }
  2456. /* select the connection from pin to DAC if needed */
  2457. static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
  2458. hda_nid_t dac)
  2459. {
  2460. hda_nid_t mix[5];
  2461. int i, num;
  2462. pin = alc_go_down_to_selector(codec, pin);
  2463. num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
  2464. if (num < 2)
  2465. return 0;
  2466. for (i = 0; i < num; i++) {
  2467. if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
  2468. snd_hda_codec_update_cache(codec, pin, 0,
  2469. AC_VERB_SET_CONNECT_SEL, i);
  2470. return 0;
  2471. }
  2472. }
  2473. return 0;
  2474. }
  2475. /* look for an empty DAC slot */
  2476. static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
  2477. {
  2478. struct alc_spec *spec = codec->spec;
  2479. hda_nid_t srcs[5];
  2480. int i, num;
  2481. pin = alc_go_down_to_selector(codec, pin);
  2482. num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
  2483. for (i = 0; i < num; i++) {
  2484. hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
  2485. if (!nid)
  2486. continue;
  2487. if (found_in_nid_list(nid, spec->multiout.dac_nids,
  2488. spec->multiout.num_dacs))
  2489. continue;
  2490. if (spec->multiout.hp_nid == nid)
  2491. continue;
  2492. if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
  2493. ARRAY_SIZE(spec->multiout.extra_out_nid)))
  2494. continue;
  2495. return nid;
  2496. }
  2497. return 0;
  2498. }
  2499. static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
  2500. {
  2501. hda_nid_t sel = alc_go_down_to_selector(codec, pin);
  2502. if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
  2503. return alc_auto_look_for_dac(codec, pin);
  2504. return 0;
  2505. }
  2506. /* fill in the dac_nids table from the parsed pin configuration */
  2507. static int alc_auto_fill_dac_nids(struct hda_codec *codec)
  2508. {
  2509. struct alc_spec *spec = codec->spec;
  2510. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2511. bool redone = false;
  2512. int i;
  2513. again:
  2514. /* set num_dacs once to full for alc_auto_look_for_dac() */
  2515. spec->multiout.num_dacs = cfg->line_outs;
  2516. spec->multiout.hp_nid = 0;
  2517. spec->multiout.extra_out_nid[0] = 0;
  2518. memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
  2519. spec->multiout.dac_nids = spec->private_dac_nids;
  2520. /* fill hard-wired DACs first */
  2521. if (!redone) {
  2522. for (i = 0; i < cfg->line_outs; i++)
  2523. spec->private_dac_nids[i] =
  2524. get_dac_if_single(codec, cfg->line_out_pins[i]);
  2525. if (cfg->hp_outs)
  2526. spec->multiout.hp_nid =
  2527. get_dac_if_single(codec, cfg->hp_pins[0]);
  2528. if (cfg->speaker_outs)
  2529. spec->multiout.extra_out_nid[0] =
  2530. get_dac_if_single(codec, cfg->speaker_pins[0]);
  2531. }
  2532. for (i = 0; i < cfg->line_outs; i++) {
  2533. hda_nid_t pin = cfg->line_out_pins[i];
  2534. if (spec->private_dac_nids[i])
  2535. continue;
  2536. spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
  2537. if (!spec->private_dac_nids[i] && !redone) {
  2538. /* if we can't find primary DACs, re-probe without
  2539. * checking the hard-wired DACs
  2540. */
  2541. redone = true;
  2542. goto again;
  2543. }
  2544. }
  2545. /* re-count num_dacs and squash invalid entries */
  2546. spec->multiout.num_dacs = 0;
  2547. for (i = 0; i < cfg->line_outs; i++) {
  2548. if (spec->private_dac_nids[i])
  2549. spec->multiout.num_dacs++;
  2550. else
  2551. memmove(spec->private_dac_nids + i,
  2552. spec->private_dac_nids + i + 1,
  2553. sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
  2554. }
  2555. if (cfg->hp_outs && !spec->multiout.hp_nid)
  2556. spec->multiout.hp_nid =
  2557. alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
  2558. if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
  2559. spec->multiout.extra_out_nid[0] =
  2560. alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
  2561. return 0;
  2562. }
  2563. static int alc_auto_add_vol_ctl(struct hda_codec *codec,
  2564. const char *pfx, int cidx,
  2565. hda_nid_t nid, unsigned int chs)
  2566. {
  2567. if (!nid)
  2568. return 0;
  2569. return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
  2570. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  2571. }
  2572. #define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
  2573. alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
  2574. /* create a mute-switch for the given mixer widget;
  2575. * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
  2576. */
  2577. static int alc_auto_add_sw_ctl(struct hda_codec *codec,
  2578. const char *pfx, int cidx,
  2579. hda_nid_t nid, unsigned int chs)
  2580. {
  2581. int wid_type;
  2582. int type;
  2583. unsigned long val;
  2584. if (!nid)
  2585. return 0;
  2586. wid_type = get_wcaps_type(get_wcaps(codec, nid));
  2587. if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
  2588. type = ALC_CTL_WIDGET_MUTE;
  2589. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
  2590. } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
  2591. type = ALC_CTL_WIDGET_MUTE;
  2592. val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
  2593. } else {
  2594. type = ALC_CTL_BIND_MUTE;
  2595. val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
  2596. }
  2597. return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
  2598. }
  2599. #define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
  2600. alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
  2601. static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
  2602. hda_nid_t pin, hda_nid_t dac)
  2603. {
  2604. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  2605. if (nid_has_mute(codec, pin, HDA_OUTPUT))
  2606. return pin;
  2607. else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
  2608. return mix;
  2609. else if (nid_has_mute(codec, dac, HDA_OUTPUT))
  2610. return dac;
  2611. return 0;
  2612. }
  2613. static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
  2614. hda_nid_t pin, hda_nid_t dac)
  2615. {
  2616. hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
  2617. if (nid_has_volume(codec, dac, HDA_OUTPUT))
  2618. return dac;
  2619. else if (nid_has_volume(codec, mix, HDA_OUTPUT))
  2620. return mix;
  2621. else if (nid_has_volume(codec, pin, HDA_OUTPUT))
  2622. return pin;
  2623. return 0;
  2624. }
  2625. /* add playback controls from the parsed DAC table */
  2626. static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
  2627. const struct auto_pin_cfg *cfg)
  2628. {
  2629. struct alc_spec *spec = codec->spec;
  2630. int i, err, noutputs;
  2631. noutputs = cfg->line_outs;
  2632. if (spec->multi_ios > 0)
  2633. noutputs += spec->multi_ios;
  2634. for (i = 0; i < noutputs; i++) {
  2635. const char *name;
  2636. int index;
  2637. hda_nid_t dac, pin;
  2638. hda_nid_t sw, vol;
  2639. dac = spec->multiout.dac_nids[i];
  2640. if (!dac)
  2641. continue;
  2642. if (i >= cfg->line_outs)
  2643. pin = spec->multi_io[i - 1].pin;
  2644. else
  2645. pin = cfg->line_out_pins[i];
  2646. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  2647. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  2648. name = alc_get_line_out_pfx(spec, i, true, &index);
  2649. if (!name) {
  2650. /* Center/LFE */
  2651. err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
  2652. if (err < 0)
  2653. return err;
  2654. err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
  2655. if (err < 0)
  2656. return err;
  2657. err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
  2658. if (err < 0)
  2659. return err;
  2660. err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
  2661. if (err < 0)
  2662. return err;
  2663. } else {
  2664. err = alc_auto_add_stereo_vol(codec, name, index, vol);
  2665. if (err < 0)
  2666. return err;
  2667. err = alc_auto_add_stereo_sw(codec, name, index, sw);
  2668. if (err < 0)
  2669. return err;
  2670. }
  2671. }
  2672. return 0;
  2673. }
  2674. /* add playback controls for speaker and HP outputs */
  2675. static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  2676. hda_nid_t dac, const char *pfx)
  2677. {
  2678. struct alc_spec *spec = codec->spec;
  2679. hda_nid_t sw, vol;
  2680. int err;
  2681. if (!pin)
  2682. return 0;
  2683. if (!dac) {
  2684. /* the corresponding DAC is already occupied */
  2685. if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
  2686. return 0; /* no way */
  2687. /* create a switch only */
  2688. return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
  2689. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2690. }
  2691. sw = alc_look_for_out_mute_nid(codec, pin, dac);
  2692. vol = alc_look_for_out_vol_nid(codec, pin, dac);
  2693. err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
  2694. if (err < 0)
  2695. return err;
  2696. err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
  2697. if (err < 0)
  2698. return err;
  2699. return 0;
  2700. }
  2701. static int alc_auto_create_hp_out(struct hda_codec *codec)
  2702. {
  2703. struct alc_spec *spec = codec->spec;
  2704. return alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
  2705. spec->multiout.hp_nid,
  2706. "Headphone");
  2707. }
  2708. static int alc_auto_create_speaker_out(struct hda_codec *codec)
  2709. {
  2710. struct alc_spec *spec = codec->spec;
  2711. return alc_auto_create_extra_out(codec, spec->autocfg.speaker_pins[0],
  2712. spec->multiout.extra_out_nid[0],
  2713. "Speaker");
  2714. }
  2715. static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
  2716. hda_nid_t pin, int pin_type,
  2717. hda_nid_t dac)
  2718. {
  2719. int i, num;
  2720. hda_nid_t nid, mix = 0;
  2721. hda_nid_t srcs[HDA_MAX_CONNECTIONS];
  2722. alc_set_pin_output(codec, pin, pin_type);
  2723. nid = alc_go_down_to_selector(codec, pin);
  2724. num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
  2725. for (i = 0; i < num; i++) {
  2726. if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
  2727. continue;
  2728. mix = srcs[i];
  2729. break;
  2730. }
  2731. if (!mix)
  2732. return;
  2733. /* need the manual connection? */
  2734. if (num > 1)
  2735. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
  2736. /* unmute mixer widget inputs */
  2737. if (nid_has_mute(codec, mix, HDA_INPUT)) {
  2738. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2739. AMP_IN_UNMUTE(0));
  2740. snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2741. AMP_IN_UNMUTE(1));
  2742. }
  2743. /* initialize volume */
  2744. nid = alc_look_for_out_vol_nid(codec, pin, dac);
  2745. if (nid)
  2746. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2747. AMP_OUT_ZERO);
  2748. }
  2749. static void alc_auto_init_multi_out(struct hda_codec *codec)
  2750. {
  2751. struct alc_spec *spec = codec->spec;
  2752. int pin_type = get_pin_type(spec->autocfg.line_out_type);
  2753. int i;
  2754. for (i = 0; i <= HDA_SIDE; i++) {
  2755. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  2756. if (nid)
  2757. alc_auto_set_output_and_unmute(codec, nid, pin_type,
  2758. spec->multiout.dac_nids[i]);
  2759. }
  2760. }
  2761. static void alc_auto_init_extra_out(struct hda_codec *codec)
  2762. {
  2763. struct alc_spec *spec = codec->spec;
  2764. hda_nid_t pin;
  2765. pin = spec->autocfg.hp_pins[0];
  2766. if (pin)
  2767. alc_auto_set_output_and_unmute(codec, pin, PIN_HP,
  2768. spec->multiout.hp_nid);
  2769. pin = spec->autocfg.speaker_pins[0];
  2770. if (pin)
  2771. alc_auto_set_output_and_unmute(codec, pin, PIN_OUT,
  2772. spec->multiout.extra_out_nid[0]);
  2773. }
  2774. /*
  2775. * multi-io helper
  2776. */
  2777. static int alc_auto_fill_multi_ios(struct hda_codec *codec,
  2778. unsigned int location)
  2779. {
  2780. struct alc_spec *spec = codec->spec;
  2781. struct auto_pin_cfg *cfg = &spec->autocfg;
  2782. int type, i, num_pins = 0;
  2783. for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
  2784. for (i = 0; i < cfg->num_inputs; i++) {
  2785. hda_nid_t nid = cfg->inputs[i].pin;
  2786. hda_nid_t dac;
  2787. unsigned int defcfg, caps;
  2788. if (cfg->inputs[i].type != type)
  2789. continue;
  2790. defcfg = snd_hda_codec_get_pincfg(codec, nid);
  2791. if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
  2792. continue;
  2793. if (location && get_defcfg_location(defcfg) != location)
  2794. continue;
  2795. caps = snd_hda_query_pin_caps(codec, nid);
  2796. if (!(caps & AC_PINCAP_OUT))
  2797. continue;
  2798. dac = alc_auto_look_for_dac(codec, nid);
  2799. if (!dac)
  2800. continue;
  2801. spec->multi_io[num_pins].pin = nid;
  2802. spec->multi_io[num_pins].dac = dac;
  2803. num_pins++;
  2804. spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
  2805. }
  2806. }
  2807. spec->multiout.num_dacs = 1;
  2808. if (num_pins < 2)
  2809. return 0;
  2810. return num_pins;
  2811. }
  2812. static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
  2813. struct snd_ctl_elem_info *uinfo)
  2814. {
  2815. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2816. struct alc_spec *spec = codec->spec;
  2817. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2818. uinfo->count = 1;
  2819. uinfo->value.enumerated.items = spec->multi_ios + 1;
  2820. if (uinfo->value.enumerated.item > spec->multi_ios)
  2821. uinfo->value.enumerated.item = spec->multi_ios;
  2822. sprintf(uinfo->value.enumerated.name, "%dch",
  2823. (uinfo->value.enumerated.item + 1) * 2);
  2824. return 0;
  2825. }
  2826. static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
  2827. struct snd_ctl_elem_value *ucontrol)
  2828. {
  2829. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2830. struct alc_spec *spec = codec->spec;
  2831. ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
  2832. return 0;
  2833. }
  2834. static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
  2835. {
  2836. struct alc_spec *spec = codec->spec;
  2837. hda_nid_t nid = spec->multi_io[idx].pin;
  2838. if (!spec->multi_io[idx].ctl_in)
  2839. spec->multi_io[idx].ctl_in =
  2840. snd_hda_codec_read(codec, nid, 0,
  2841. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  2842. if (output) {
  2843. snd_hda_codec_update_cache(codec, nid, 0,
  2844. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2845. PIN_OUT);
  2846. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  2847. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  2848. HDA_AMP_MUTE, 0);
  2849. alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
  2850. } else {
  2851. if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
  2852. snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
  2853. HDA_AMP_MUTE, HDA_AMP_MUTE);
  2854. snd_hda_codec_update_cache(codec, nid, 0,
  2855. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2856. spec->multi_io[idx].ctl_in);
  2857. }
  2858. return 0;
  2859. }
  2860. static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
  2861. struct snd_ctl_elem_value *ucontrol)
  2862. {
  2863. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2864. struct alc_spec *spec = codec->spec;
  2865. int i, ch;
  2866. ch = ucontrol->value.enumerated.item[0];
  2867. if (ch < 0 || ch > spec->multi_ios)
  2868. return -EINVAL;
  2869. if (ch == (spec->ext_channel_count - 1) / 2)
  2870. return 0;
  2871. spec->ext_channel_count = (ch + 1) * 2;
  2872. for (i = 0; i < spec->multi_ios; i++)
  2873. alc_set_multi_io(codec, i, i < ch);
  2874. spec->multiout.max_channels = spec->ext_channel_count;
  2875. if (spec->need_dac_fix && !spec->const_channel_count)
  2876. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  2877. return 1;
  2878. }
  2879. static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
  2880. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2881. .name = "Channel Mode",
  2882. .info = alc_auto_ch_mode_info,
  2883. .get = alc_auto_ch_mode_get,
  2884. .put = alc_auto_ch_mode_put,
  2885. };
  2886. static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
  2887. int (*fill_dac)(struct hda_codec *))
  2888. {
  2889. struct alc_spec *spec = codec->spec;
  2890. struct auto_pin_cfg *cfg = &spec->autocfg;
  2891. unsigned int location, defcfg;
  2892. int num_pins;
  2893. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
  2894. /* use HP as primary out */
  2895. cfg->speaker_outs = cfg->line_outs;
  2896. memcpy(cfg->speaker_pins, cfg->line_out_pins,
  2897. sizeof(cfg->speaker_pins));
  2898. cfg->line_outs = cfg->hp_outs;
  2899. memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
  2900. cfg->hp_outs = 0;
  2901. memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
  2902. cfg->line_out_type = AUTO_PIN_HP_OUT;
  2903. if (fill_dac)
  2904. fill_dac(codec);
  2905. }
  2906. if (cfg->line_outs != 1 ||
  2907. cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
  2908. return 0;
  2909. defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
  2910. location = get_defcfg_location(defcfg);
  2911. num_pins = alc_auto_fill_multi_ios(codec, location);
  2912. if (num_pins > 0) {
  2913. struct snd_kcontrol_new *knew;
  2914. knew = alc_kcontrol_new(spec);
  2915. if (!knew)
  2916. return -ENOMEM;
  2917. *knew = alc_auto_channel_mode_enum;
  2918. knew->name = kstrdup("Channel Mode", GFP_KERNEL);
  2919. if (!knew->name)
  2920. return -ENOMEM;
  2921. spec->multi_ios = num_pins;
  2922. spec->ext_channel_count = 2;
  2923. spec->multiout.num_dacs = num_pins + 1;
  2924. }
  2925. return 0;
  2926. }
  2927. /* filter out invalid adc_nids (and capsrc_nids) that don't give all
  2928. * active input pins
  2929. */
  2930. static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
  2931. {
  2932. struct alc_spec *spec = codec->spec;
  2933. const struct hda_input_mux *imux;
  2934. hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  2935. hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
  2936. int i, n, nums;
  2937. imux = spec->input_mux;
  2938. if (!imux)
  2939. return;
  2940. if (spec->dyn_adc_switch)
  2941. return;
  2942. nums = 0;
  2943. for (n = 0; n < spec->num_adc_nids; n++) {
  2944. hda_nid_t cap = spec->private_capsrc_nids[n];
  2945. int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
  2946. for (i = 0; i < imux->num_items; i++) {
  2947. hda_nid_t pin = spec->imux_pins[i];
  2948. if (pin) {
  2949. if (get_connection_index(codec, cap, pin) < 0)
  2950. break;
  2951. } else if (num_conns <= imux->items[i].index)
  2952. break;
  2953. }
  2954. if (i >= imux->num_items) {
  2955. adc_nids[nums] = spec->private_adc_nids[n];
  2956. capsrc_nids[nums++] = cap;
  2957. }
  2958. }
  2959. if (!nums) {
  2960. /* check whether ADC-switch is possible */
  2961. if (!alc_check_dyn_adc_switch(codec)) {
  2962. printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
  2963. " using fallback 0x%x\n",
  2964. codec->chip_name, spec->private_adc_nids[0]);
  2965. spec->num_adc_nids = 1;
  2966. spec->auto_mic = 0;
  2967. return;
  2968. }
  2969. } else if (nums != spec->num_adc_nids) {
  2970. memcpy(spec->private_adc_nids, adc_nids,
  2971. nums * sizeof(hda_nid_t));
  2972. memcpy(spec->private_capsrc_nids, capsrc_nids,
  2973. nums * sizeof(hda_nid_t));
  2974. spec->num_adc_nids = nums;
  2975. }
  2976. if (spec->auto_mic)
  2977. alc_auto_mic_check_imux(codec); /* check auto-mic setups */
  2978. else if (spec->input_mux->num_items == 1)
  2979. spec->num_adc_nids = 1; /* reduce to a single ADC */
  2980. }
  2981. /*
  2982. * initialize ADC paths
  2983. */
  2984. static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
  2985. {
  2986. struct alc_spec *spec = codec->spec;
  2987. hda_nid_t nid;
  2988. nid = spec->adc_nids[adc_idx];
  2989. /* mute ADC */
  2990. if (nid_has_mute(codec, nid, HDA_INPUT)) {
  2991. snd_hda_codec_write(codec, nid, 0,
  2992. AC_VERB_SET_AMP_GAIN_MUTE,
  2993. AMP_IN_MUTE(0));
  2994. return;
  2995. }
  2996. if (!spec->capsrc_nids)
  2997. return;
  2998. nid = spec->capsrc_nids[adc_idx];
  2999. if (nid_has_mute(codec, nid, HDA_OUTPUT))
  3000. snd_hda_codec_write(codec, nid, 0,
  3001. AC_VERB_SET_AMP_GAIN_MUTE,
  3002. AMP_OUT_MUTE);
  3003. }
  3004. static void alc_auto_init_input_src(struct hda_codec *codec)
  3005. {
  3006. struct alc_spec *spec = codec->spec;
  3007. int c, nums;
  3008. for (c = 0; c < spec->num_adc_nids; c++)
  3009. alc_auto_init_adc(codec, c);
  3010. if (spec->dyn_adc_switch)
  3011. nums = 1;
  3012. else
  3013. nums = spec->num_adc_nids;
  3014. for (c = 0; c < nums; c++)
  3015. alc_mux_select(codec, 0, spec->cur_mux[c], true);
  3016. }
  3017. /* add mic boosts if needed */
  3018. static int alc_auto_add_mic_boost(struct hda_codec *codec)
  3019. {
  3020. struct alc_spec *spec = codec->spec;
  3021. struct auto_pin_cfg *cfg = &spec->autocfg;
  3022. int i, err;
  3023. int type_idx = 0;
  3024. hda_nid_t nid;
  3025. const char *prev_label = NULL;
  3026. for (i = 0; i < cfg->num_inputs; i++) {
  3027. if (cfg->inputs[i].type > AUTO_PIN_MIC)
  3028. break;
  3029. nid = cfg->inputs[i].pin;
  3030. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
  3031. const char *label;
  3032. char boost_label[32];
  3033. label = hda_get_autocfg_input_label(codec, cfg, i);
  3034. if (prev_label && !strcmp(label, prev_label))
  3035. type_idx++;
  3036. else
  3037. type_idx = 0;
  3038. prev_label = label;
  3039. snprintf(boost_label, sizeof(boost_label),
  3040. "%s Boost Volume", label);
  3041. err = add_control(spec, ALC_CTL_WIDGET_VOL,
  3042. boost_label, type_idx,
  3043. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
  3044. if (err < 0)
  3045. return err;
  3046. }
  3047. }
  3048. return 0;
  3049. }
  3050. /* select or unmute the given capsrc route */
  3051. static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
  3052. int idx)
  3053. {
  3054. if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
  3055. snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
  3056. HDA_AMP_MUTE, 0);
  3057. } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
  3058. snd_hda_codec_write_cache(codec, cap, 0,
  3059. AC_VERB_SET_CONNECT_SEL, idx);
  3060. }
  3061. }
  3062. /* set the default connection to that pin */
  3063. static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
  3064. {
  3065. struct alc_spec *spec = codec->spec;
  3066. int i;
  3067. if (!pin)
  3068. return 0;
  3069. for (i = 0; i < spec->num_adc_nids; i++) {
  3070. hda_nid_t cap = spec->capsrc_nids ?
  3071. spec->capsrc_nids[i] : spec->adc_nids[i];
  3072. int idx;
  3073. idx = get_connection_index(codec, cap, pin);
  3074. if (idx < 0)
  3075. continue;
  3076. select_or_unmute_capsrc(codec, cap, idx);
  3077. return i; /* return the found index */
  3078. }
  3079. return -1; /* not found */
  3080. }
  3081. /* initialize some special cases for input sources */
  3082. static void alc_init_special_input_src(struct hda_codec *codec)
  3083. {
  3084. struct alc_spec *spec = codec->spec;
  3085. int i;
  3086. for (i = 0; i < spec->autocfg.num_inputs; i++)
  3087. init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
  3088. }
  3089. /* assign appropriate capture mixers */
  3090. static void set_capture_mixer(struct hda_codec *codec)
  3091. {
  3092. struct alc_spec *spec = codec->spec;
  3093. static const struct snd_kcontrol_new *caps[2][3] = {
  3094. { alc_capture_mixer_nosrc1,
  3095. alc_capture_mixer_nosrc2,
  3096. alc_capture_mixer_nosrc3 },
  3097. { alc_capture_mixer1,
  3098. alc_capture_mixer2,
  3099. alc_capture_mixer3 },
  3100. };
  3101. /* check whether either of ADC or MUX has a volume control */
  3102. if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
  3103. if (!spec->capsrc_nids)
  3104. return; /* no volume */
  3105. if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
  3106. return; /* no volume in capsrc, too */
  3107. spec->vol_in_capsrc = 1;
  3108. }
  3109. if (spec->num_adc_nids > 0) {
  3110. int mux = 0;
  3111. int num_adcs = 0;
  3112. if (spec->input_mux && spec->input_mux->num_items > 1)
  3113. mux = 1;
  3114. if (spec->auto_mic) {
  3115. num_adcs = 1;
  3116. mux = 0;
  3117. } else if (spec->dyn_adc_switch)
  3118. num_adcs = 1;
  3119. if (!num_adcs) {
  3120. if (spec->num_adc_nids > 3)
  3121. spec->num_adc_nids = 3;
  3122. else if (!spec->num_adc_nids)
  3123. return;
  3124. num_adcs = spec->num_adc_nids;
  3125. }
  3126. spec->cap_mixer = caps[mux][num_adcs - 1];
  3127. }
  3128. }
  3129. /*
  3130. * standard auto-parser initializations
  3131. */
  3132. static void alc_auto_init_std(struct hda_codec *codec)
  3133. {
  3134. struct alc_spec *spec = codec->spec;
  3135. alc_auto_init_multi_out(codec);
  3136. alc_auto_init_extra_out(codec);
  3137. alc_auto_init_analog_input(codec);
  3138. alc_auto_init_input_src(codec);
  3139. alc_auto_init_digital(codec);
  3140. if (spec->unsol_event)
  3141. alc_inithook(codec);
  3142. }
  3143. /*
  3144. * Digital-beep handlers
  3145. */
  3146. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3147. #define set_beep_amp(spec, nid, idx, dir) \
  3148. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
  3149. static const struct snd_pci_quirk beep_white_list[] = {
  3150. SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
  3151. SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
  3152. SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
  3153. SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
  3154. SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
  3155. {}
  3156. };
  3157. static inline int has_cdefine_beep(struct hda_codec *codec)
  3158. {
  3159. struct alc_spec *spec = codec->spec;
  3160. const struct snd_pci_quirk *q;
  3161. q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
  3162. if (q)
  3163. return q->value;
  3164. return spec->cdefine.enable_pcbeep;
  3165. }
  3166. #else
  3167. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  3168. #define has_cdefine_beep(codec) 0
  3169. #endif
  3170. /* parse the BIOS configuration and set up the alc_spec */
  3171. /* return 1 if successful, 0 if the proper config is not found,
  3172. * or a negative error code
  3173. */
  3174. static int alc_parse_auto_config(struct hda_codec *codec,
  3175. const hda_nid_t *ignore_nids,
  3176. const hda_nid_t *ssid_nids)
  3177. {
  3178. struct alc_spec *spec = codec->spec;
  3179. int err;
  3180. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
  3181. ignore_nids);
  3182. if (err < 0)
  3183. return err;
  3184. if (!spec->autocfg.line_outs) {
  3185. if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) {
  3186. spec->multiout.max_channels = 2;
  3187. spec->no_analog = 1;
  3188. goto dig_only;
  3189. }
  3190. return 0; /* can't find valid BIOS pin config */
  3191. }
  3192. err = alc_auto_fill_dac_nids(codec);
  3193. if (err < 0)
  3194. return err;
  3195. err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids);
  3196. if (err < 0)
  3197. return err;
  3198. err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg);
  3199. if (err < 0)
  3200. return err;
  3201. err = alc_auto_create_hp_out(codec);
  3202. if (err < 0)
  3203. return err;
  3204. err = alc_auto_create_speaker_out(codec);
  3205. if (err < 0)
  3206. return err;
  3207. err = alc_auto_create_input_ctls(codec);
  3208. if (err < 0)
  3209. return err;
  3210. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3211. dig_only:
  3212. alc_auto_parse_digital(codec);
  3213. if (!spec->no_analog)
  3214. alc_remove_invalid_adc_nids(codec);
  3215. if (ssid_nids)
  3216. alc_ssid_check(codec, ssid_nids);
  3217. if (!spec->no_analog) {
  3218. alc_auto_check_switches(codec);
  3219. err = alc_auto_add_mic_boost(codec);
  3220. if (err < 0)
  3221. return err;
  3222. }
  3223. if (spec->kctls.list)
  3224. add_mixer(spec, spec->kctls.list);
  3225. return 1;
  3226. }
  3227. static int alc880_parse_auto_config(struct hda_codec *codec)
  3228. {
  3229. static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
  3230. static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3231. return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
  3232. }
  3233. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3234. static const struct hda_amp_list alc880_loopbacks[] = {
  3235. { 0x0b, HDA_INPUT, 0 },
  3236. { 0x0b, HDA_INPUT, 1 },
  3237. { 0x0b, HDA_INPUT, 2 },
  3238. { 0x0b, HDA_INPUT, 3 },
  3239. { 0x0b, HDA_INPUT, 4 },
  3240. { } /* end */
  3241. };
  3242. #endif
  3243. /*
  3244. * board setups
  3245. */
  3246. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3247. #define alc_board_config \
  3248. snd_hda_check_board_config
  3249. #define alc_board_codec_sid_config \
  3250. snd_hda_check_board_codec_sid_config
  3251. #include "alc_quirks.c"
  3252. #else
  3253. #define alc_board_config(codec, nums, models, tbl) -1
  3254. #define alc_board_codec_sid_config(codec, nums, models, tbl) -1
  3255. #define setup_preset(codec, x) /* NOP */
  3256. #endif
  3257. /*
  3258. * OK, here we have finally the patch for ALC880
  3259. */
  3260. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3261. #include "alc880_quirks.c"
  3262. #endif
  3263. static int patch_alc880(struct hda_codec *codec)
  3264. {
  3265. struct alc_spec *spec;
  3266. int board_config;
  3267. int err;
  3268. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3269. if (spec == NULL)
  3270. return -ENOMEM;
  3271. codec->spec = spec;
  3272. spec->mixer_nid = 0x0b;
  3273. spec->need_dac_fix = 1;
  3274. board_config = alc_board_config(codec, ALC880_MODEL_LAST,
  3275. alc880_models, alc880_cfg_tbl);
  3276. if (board_config < 0) {
  3277. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3278. codec->chip_name);
  3279. board_config = ALC_MODEL_AUTO;
  3280. }
  3281. if (board_config == ALC_MODEL_AUTO) {
  3282. /* automatic parse from the BIOS config */
  3283. err = alc880_parse_auto_config(codec);
  3284. if (err < 0) {
  3285. alc_free(codec);
  3286. return err;
  3287. }
  3288. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3289. else if (!err) {
  3290. printk(KERN_INFO
  3291. "hda_codec: Cannot set up configuration "
  3292. "from BIOS. Using 3-stack mode...\n");
  3293. board_config = ALC880_3ST;
  3294. }
  3295. #endif
  3296. }
  3297. if (board_config != ALC_MODEL_AUTO)
  3298. setup_preset(codec, &alc880_presets[board_config]);
  3299. if (!spec->no_analog && !spec->adc_nids) {
  3300. alc_auto_fill_adc_caps(codec);
  3301. alc_rebuild_imux_for_auto_mic(codec);
  3302. alc_remove_invalid_adc_nids(codec);
  3303. }
  3304. if (!spec->no_analog && !spec->cap_mixer)
  3305. set_capture_mixer(codec);
  3306. if (!spec->no_analog) {
  3307. err = snd_hda_attach_beep_device(codec, 0x1);
  3308. if (err < 0) {
  3309. alc_free(codec);
  3310. return err;
  3311. }
  3312. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  3313. }
  3314. spec->vmaster_nid = 0x0c;
  3315. codec->patch_ops = alc_patch_ops;
  3316. if (board_config == ALC_MODEL_AUTO)
  3317. spec->init_hook = alc_auto_init_std;
  3318. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3319. if (!spec->loopback.amplist)
  3320. spec->loopback.amplist = alc880_loopbacks;
  3321. #endif
  3322. return 0;
  3323. }
  3324. /*
  3325. * ALC260 support
  3326. */
  3327. static int alc260_parse_auto_config(struct hda_codec *codec)
  3328. {
  3329. static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
  3330. static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
  3331. return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
  3332. }
  3333. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3334. static const struct hda_amp_list alc260_loopbacks[] = {
  3335. { 0x07, HDA_INPUT, 0 },
  3336. { 0x07, HDA_INPUT, 1 },
  3337. { 0x07, HDA_INPUT, 2 },
  3338. { 0x07, HDA_INPUT, 3 },
  3339. { 0x07, HDA_INPUT, 4 },
  3340. { } /* end */
  3341. };
  3342. #endif
  3343. /*
  3344. * Pin config fixes
  3345. */
  3346. enum {
  3347. PINFIX_HP_DC5750,
  3348. };
  3349. static const struct alc_fixup alc260_fixups[] = {
  3350. [PINFIX_HP_DC5750] = {
  3351. .type = ALC_FIXUP_PINS,
  3352. .v.pins = (const struct alc_pincfg[]) {
  3353. { 0x11, 0x90130110 }, /* speaker */
  3354. { }
  3355. }
  3356. },
  3357. };
  3358. static const struct snd_pci_quirk alc260_fixup_tbl[] = {
  3359. SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
  3360. {}
  3361. };
  3362. /*
  3363. */
  3364. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3365. #include "alc260_quirks.c"
  3366. #endif
  3367. static int patch_alc260(struct hda_codec *codec)
  3368. {
  3369. struct alc_spec *spec;
  3370. int err, board_config;
  3371. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3372. if (spec == NULL)
  3373. return -ENOMEM;
  3374. codec->spec = spec;
  3375. spec->mixer_nid = 0x07;
  3376. board_config = alc_board_config(codec, ALC260_MODEL_LAST,
  3377. alc260_models, alc260_cfg_tbl);
  3378. if (board_config < 0) {
  3379. snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3380. codec->chip_name);
  3381. board_config = ALC_MODEL_AUTO;
  3382. }
  3383. if (board_config == ALC_MODEL_AUTO) {
  3384. alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
  3385. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  3386. }
  3387. if (board_config == ALC_MODEL_AUTO) {
  3388. /* automatic parse from the BIOS config */
  3389. err = alc260_parse_auto_config(codec);
  3390. if (err < 0) {
  3391. alc_free(codec);
  3392. return err;
  3393. }
  3394. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3395. else if (!err) {
  3396. printk(KERN_INFO
  3397. "hda_codec: Cannot set up configuration "
  3398. "from BIOS. Using base mode...\n");
  3399. board_config = ALC260_BASIC;
  3400. }
  3401. #endif
  3402. }
  3403. if (board_config != ALC_MODEL_AUTO)
  3404. setup_preset(codec, &alc260_presets[board_config]);
  3405. if (!spec->no_analog && !spec->adc_nids) {
  3406. alc_auto_fill_adc_caps(codec);
  3407. alc_rebuild_imux_for_auto_mic(codec);
  3408. alc_remove_invalid_adc_nids(codec);
  3409. }
  3410. if (!spec->no_analog && !spec->cap_mixer)
  3411. set_capture_mixer(codec);
  3412. if (!spec->no_analog) {
  3413. err = snd_hda_attach_beep_device(codec, 0x1);
  3414. if (err < 0) {
  3415. alc_free(codec);
  3416. return err;
  3417. }
  3418. set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
  3419. }
  3420. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  3421. spec->vmaster_nid = 0x08;
  3422. codec->patch_ops = alc_patch_ops;
  3423. if (board_config == ALC_MODEL_AUTO)
  3424. spec->init_hook = alc_auto_init_std;
  3425. spec->shutup = alc_eapd_shutup;
  3426. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3427. if (!spec->loopback.amplist)
  3428. spec->loopback.amplist = alc260_loopbacks;
  3429. #endif
  3430. return 0;
  3431. }
  3432. /*
  3433. * ALC882/883/885/888/889 support
  3434. *
  3435. * ALC882 is almost identical with ALC880 but has cleaner and more flexible
  3436. * configuration. Each pin widget can choose any input DACs and a mixer.
  3437. * Each ADC is connected from a mixer of all inputs. This makes possible
  3438. * 6-channel independent captures.
  3439. *
  3440. * In addition, an independent DAC for the multi-playback (not used in this
  3441. * driver yet).
  3442. */
  3443. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3444. #define alc882_loopbacks alc880_loopbacks
  3445. #endif
  3446. /*
  3447. * Pin config fixes
  3448. */
  3449. enum {
  3450. PINFIX_ABIT_AW9D_MAX,
  3451. PINFIX_LENOVO_Y530,
  3452. PINFIX_PB_M5210,
  3453. PINFIX_ACER_ASPIRE_7736,
  3454. };
  3455. static const struct alc_fixup alc882_fixups[] = {
  3456. [PINFIX_ABIT_AW9D_MAX] = {
  3457. .type = ALC_FIXUP_PINS,
  3458. .v.pins = (const struct alc_pincfg[]) {
  3459. { 0x15, 0x01080104 }, /* side */
  3460. { 0x16, 0x01011012 }, /* rear */
  3461. { 0x17, 0x01016011 }, /* clfe */
  3462. { }
  3463. }
  3464. },
  3465. [PINFIX_LENOVO_Y530] = {
  3466. .type = ALC_FIXUP_PINS,
  3467. .v.pins = (const struct alc_pincfg[]) {
  3468. { 0x15, 0x99130112 }, /* rear int speakers */
  3469. { 0x16, 0x99130111 }, /* subwoofer */
  3470. { }
  3471. }
  3472. },
  3473. [PINFIX_PB_M5210] = {
  3474. .type = ALC_FIXUP_VERBS,
  3475. .v.verbs = (const struct hda_verb[]) {
  3476. { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
  3477. {}
  3478. }
  3479. },
  3480. [PINFIX_ACER_ASPIRE_7736] = {
  3481. .type = ALC_FIXUP_SKU,
  3482. .v.sku = ALC_FIXUP_SKU_IGNORE,
  3483. },
  3484. };
  3485. static const struct snd_pci_quirk alc882_fixup_tbl[] = {
  3486. SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
  3487. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
  3488. SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
  3489. SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
  3490. {}
  3491. };
  3492. /*
  3493. * BIOS auto configuration
  3494. */
  3495. /* almost identical with ALC880 parser... */
  3496. static int alc882_parse_auto_config(struct hda_codec *codec)
  3497. {
  3498. static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
  3499. static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3500. return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
  3501. }
  3502. /*
  3503. */
  3504. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3505. #include "alc882_quirks.c"
  3506. #endif
  3507. static int patch_alc882(struct hda_codec *codec)
  3508. {
  3509. struct alc_spec *spec;
  3510. int err, board_config;
  3511. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3512. if (spec == NULL)
  3513. return -ENOMEM;
  3514. codec->spec = spec;
  3515. spec->mixer_nid = 0x0b;
  3516. switch (codec->vendor_id) {
  3517. case 0x10ec0882:
  3518. case 0x10ec0885:
  3519. break;
  3520. default:
  3521. /* ALC883 and variants */
  3522. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  3523. break;
  3524. }
  3525. board_config = alc_board_config(codec, ALC882_MODEL_LAST,
  3526. alc882_models, alc882_cfg_tbl);
  3527. if (board_config < 0)
  3528. board_config = alc_board_codec_sid_config(codec,
  3529. ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
  3530. if (board_config < 0) {
  3531. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3532. codec->chip_name);
  3533. board_config = ALC_MODEL_AUTO;
  3534. }
  3535. if (board_config == ALC_MODEL_AUTO) {
  3536. alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
  3537. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  3538. }
  3539. alc_auto_parse_customize_define(codec);
  3540. if (board_config == ALC_MODEL_AUTO) {
  3541. /* automatic parse from the BIOS config */
  3542. err = alc882_parse_auto_config(codec);
  3543. if (err < 0) {
  3544. alc_free(codec);
  3545. return err;
  3546. }
  3547. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3548. else if (!err) {
  3549. printk(KERN_INFO
  3550. "hda_codec: Cannot set up configuration "
  3551. "from BIOS. Using base mode...\n");
  3552. board_config = ALC882_3ST_DIG;
  3553. }
  3554. #endif
  3555. }
  3556. if (board_config != ALC_MODEL_AUTO)
  3557. setup_preset(codec, &alc882_presets[board_config]);
  3558. if (!spec->no_analog && !spec->adc_nids) {
  3559. alc_auto_fill_adc_caps(codec);
  3560. alc_rebuild_imux_for_auto_mic(codec);
  3561. alc_remove_invalid_adc_nids(codec);
  3562. }
  3563. if (!spec->no_analog && !spec->cap_mixer)
  3564. set_capture_mixer(codec);
  3565. if (!spec->no_analog && has_cdefine_beep(codec)) {
  3566. err = snd_hda_attach_beep_device(codec, 0x1);
  3567. if (err < 0) {
  3568. alc_free(codec);
  3569. return err;
  3570. }
  3571. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  3572. }
  3573. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  3574. spec->vmaster_nid = 0x0c;
  3575. codec->patch_ops = alc_patch_ops;
  3576. if (board_config == ALC_MODEL_AUTO)
  3577. spec->init_hook = alc_auto_init_std;
  3578. alc_init_jacks(codec);
  3579. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3580. if (!spec->loopback.amplist)
  3581. spec->loopback.amplist = alc882_loopbacks;
  3582. #endif
  3583. return 0;
  3584. }
  3585. /*
  3586. * ALC262 support
  3587. */
  3588. static int alc262_parse_auto_config(struct hda_codec *codec)
  3589. {
  3590. static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
  3591. static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3592. return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
  3593. }
  3594. /*
  3595. * Pin config fixes
  3596. */
  3597. enum {
  3598. PINFIX_FSC_H270,
  3599. PINFIX_HP_Z200,
  3600. };
  3601. static const struct alc_fixup alc262_fixups[] = {
  3602. [PINFIX_FSC_H270] = {
  3603. .type = ALC_FIXUP_PINS,
  3604. .v.pins = (const struct alc_pincfg[]) {
  3605. { 0x14, 0x99130110 }, /* speaker */
  3606. { 0x15, 0x0221142f }, /* front HP */
  3607. { 0x1b, 0x0121141f }, /* rear HP */
  3608. { }
  3609. }
  3610. },
  3611. [PINFIX_HP_Z200] = {
  3612. .type = ALC_FIXUP_PINS,
  3613. .v.pins = (const struct alc_pincfg[]) {
  3614. { 0x16, 0x99130120 }, /* internal speaker */
  3615. { }
  3616. }
  3617. },
  3618. };
  3619. static const struct snd_pci_quirk alc262_fixup_tbl[] = {
  3620. SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
  3621. SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
  3622. {}
  3623. };
  3624. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3625. #define alc262_loopbacks alc880_loopbacks
  3626. #endif
  3627. /*
  3628. */
  3629. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3630. #include "alc262_quirks.c"
  3631. #endif
  3632. static int patch_alc262(struct hda_codec *codec)
  3633. {
  3634. struct alc_spec *spec;
  3635. int board_config;
  3636. int err;
  3637. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3638. if (spec == NULL)
  3639. return -ENOMEM;
  3640. codec->spec = spec;
  3641. spec->mixer_nid = 0x0b;
  3642. #if 0
  3643. /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
  3644. * under-run
  3645. */
  3646. {
  3647. int tmp;
  3648. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  3649. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  3650. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  3651. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
  3652. }
  3653. #endif
  3654. alc_auto_parse_customize_define(codec);
  3655. alc_fix_pll_init(codec, 0x20, 0x0a, 10);
  3656. board_config = alc_board_config(codec, ALC262_MODEL_LAST,
  3657. alc262_models, alc262_cfg_tbl);
  3658. if (board_config < 0) {
  3659. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3660. codec->chip_name);
  3661. board_config = ALC_MODEL_AUTO;
  3662. }
  3663. if (board_config == ALC_MODEL_AUTO) {
  3664. alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
  3665. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  3666. }
  3667. if (board_config == ALC_MODEL_AUTO) {
  3668. /* automatic parse from the BIOS config */
  3669. err = alc262_parse_auto_config(codec);
  3670. if (err < 0) {
  3671. alc_free(codec);
  3672. return err;
  3673. }
  3674. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3675. else if (!err) {
  3676. printk(KERN_INFO
  3677. "hda_codec: Cannot set up configuration "
  3678. "from BIOS. Using base mode...\n");
  3679. board_config = ALC262_BASIC;
  3680. }
  3681. #endif
  3682. }
  3683. if (board_config != ALC_MODEL_AUTO)
  3684. setup_preset(codec, &alc262_presets[board_config]);
  3685. if (!spec->no_analog && !spec->adc_nids) {
  3686. alc_auto_fill_adc_caps(codec);
  3687. alc_rebuild_imux_for_auto_mic(codec);
  3688. alc_remove_invalid_adc_nids(codec);
  3689. }
  3690. if (!spec->no_analog && !spec->cap_mixer)
  3691. set_capture_mixer(codec);
  3692. if (!spec->no_analog && has_cdefine_beep(codec)) {
  3693. err = snd_hda_attach_beep_device(codec, 0x1);
  3694. if (err < 0) {
  3695. alc_free(codec);
  3696. return err;
  3697. }
  3698. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  3699. }
  3700. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  3701. spec->vmaster_nid = 0x0c;
  3702. codec->patch_ops = alc_patch_ops;
  3703. if (board_config == ALC_MODEL_AUTO)
  3704. spec->init_hook = alc_auto_init_std;
  3705. spec->shutup = alc_eapd_shutup;
  3706. alc_init_jacks(codec);
  3707. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3708. if (!spec->loopback.amplist)
  3709. spec->loopback.amplist = alc262_loopbacks;
  3710. #endif
  3711. return 0;
  3712. }
  3713. /*
  3714. * ALC268
  3715. */
  3716. /* bind Beep switches of both NID 0x0f and 0x10 */
  3717. static const struct hda_bind_ctls alc268_bind_beep_sw = {
  3718. .ops = &snd_hda_bind_sw,
  3719. .values = {
  3720. HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
  3721. HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
  3722. 0
  3723. },
  3724. };
  3725. static const struct snd_kcontrol_new alc268_beep_mixer[] = {
  3726. HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
  3727. HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
  3728. { }
  3729. };
  3730. /* set PCBEEP vol = 0, mute connections */
  3731. static const struct hda_verb alc268_beep_init_verbs[] = {
  3732. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3733. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3734. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3735. { }
  3736. };
  3737. /*
  3738. * BIOS auto configuration
  3739. */
  3740. static int alc268_parse_auto_config(struct hda_codec *codec)
  3741. {
  3742. static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3743. struct alc_spec *spec = codec->spec;
  3744. int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
  3745. if (err > 0) {
  3746. if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
  3747. add_mixer(spec, alc268_beep_mixer);
  3748. add_verb(spec, alc268_beep_init_verbs);
  3749. }
  3750. }
  3751. return err;
  3752. }
  3753. /*
  3754. */
  3755. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3756. #include "alc268_quirks.c"
  3757. #endif
  3758. static int patch_alc268(struct hda_codec *codec)
  3759. {
  3760. struct alc_spec *spec;
  3761. int board_config;
  3762. int i, has_beep, err;
  3763. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3764. if (spec == NULL)
  3765. return -ENOMEM;
  3766. codec->spec = spec;
  3767. /* ALC268 has no aa-loopback mixer */
  3768. board_config = alc_board_config(codec, ALC268_MODEL_LAST,
  3769. alc268_models, alc268_cfg_tbl);
  3770. if (board_config < 0)
  3771. board_config = alc_board_codec_sid_config(codec,
  3772. ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
  3773. if (board_config < 0) {
  3774. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3775. codec->chip_name);
  3776. board_config = ALC_MODEL_AUTO;
  3777. }
  3778. if (board_config == ALC_MODEL_AUTO) {
  3779. /* automatic parse from the BIOS config */
  3780. err = alc268_parse_auto_config(codec);
  3781. if (err < 0) {
  3782. alc_free(codec);
  3783. return err;
  3784. }
  3785. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  3786. else if (!err) {
  3787. printk(KERN_INFO
  3788. "hda_codec: Cannot set up configuration "
  3789. "from BIOS. Using base mode...\n");
  3790. board_config = ALC268_3ST;
  3791. }
  3792. #endif
  3793. }
  3794. if (board_config != ALC_MODEL_AUTO)
  3795. setup_preset(codec, &alc268_presets[board_config]);
  3796. has_beep = 0;
  3797. for (i = 0; i < spec->num_mixers; i++) {
  3798. if (spec->mixers[i] == alc268_beep_mixer) {
  3799. has_beep = 1;
  3800. break;
  3801. }
  3802. }
  3803. if (has_beep) {
  3804. err = snd_hda_attach_beep_device(codec, 0x1);
  3805. if (err < 0) {
  3806. alc_free(codec);
  3807. return err;
  3808. }
  3809. if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
  3810. /* override the amp caps for beep generator */
  3811. snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
  3812. (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
  3813. (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
  3814. (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  3815. (0 << AC_AMPCAP_MUTE_SHIFT));
  3816. }
  3817. if (!spec->no_analog && !spec->adc_nids) {
  3818. alc_auto_fill_adc_caps(codec);
  3819. alc_rebuild_imux_for_auto_mic(codec);
  3820. alc_remove_invalid_adc_nids(codec);
  3821. }
  3822. if (!spec->no_analog && !spec->cap_mixer)
  3823. set_capture_mixer(codec);
  3824. spec->vmaster_nid = 0x02;
  3825. codec->patch_ops = alc_patch_ops;
  3826. if (board_config == ALC_MODEL_AUTO)
  3827. spec->init_hook = alc_auto_init_std;
  3828. spec->shutup = alc_eapd_shutup;
  3829. alc_init_jacks(codec);
  3830. return 0;
  3831. }
  3832. /*
  3833. * ALC269
  3834. */
  3835. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3836. #define alc269_loopbacks alc880_loopbacks
  3837. #endif
  3838. static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
  3839. .substreams = 1,
  3840. .channels_min = 2,
  3841. .channels_max = 8,
  3842. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  3843. /* NID is set in alc_build_pcms */
  3844. .ops = {
  3845. .open = alc_playback_pcm_open,
  3846. .prepare = alc_playback_pcm_prepare,
  3847. .cleanup = alc_playback_pcm_cleanup
  3848. },
  3849. };
  3850. static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
  3851. .substreams = 1,
  3852. .channels_min = 2,
  3853. .channels_max = 2,
  3854. .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
  3855. /* NID is set in alc_build_pcms */
  3856. };
  3857. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3858. static int alc269_mic2_for_mute_led(struct hda_codec *codec)
  3859. {
  3860. switch (codec->subsystem_id) {
  3861. case 0x103c1586:
  3862. return 1;
  3863. }
  3864. return 0;
  3865. }
  3866. static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
  3867. {
  3868. /* update mute-LED according to the speaker mute state */
  3869. if (nid == 0x01 || nid == 0x14) {
  3870. int pinval;
  3871. if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
  3872. HDA_AMP_MUTE)
  3873. pinval = 0x24;
  3874. else
  3875. pinval = 0x20;
  3876. /* mic2 vref pin is used for mute LED control */
  3877. snd_hda_codec_update_cache(codec, 0x19, 0,
  3878. AC_VERB_SET_PIN_WIDGET_CONTROL,
  3879. pinval);
  3880. }
  3881. return alc_check_power_status(codec, nid);
  3882. }
  3883. #endif /* CONFIG_SND_HDA_POWER_SAVE */
  3884. /* different alc269-variants */
  3885. enum {
  3886. ALC269_TYPE_ALC269VA,
  3887. ALC269_TYPE_ALC269VB,
  3888. ALC269_TYPE_ALC269VC,
  3889. };
  3890. /*
  3891. * BIOS auto configuration
  3892. */
  3893. static int alc269_parse_auto_config(struct hda_codec *codec)
  3894. {
  3895. static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
  3896. static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
  3897. static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  3898. struct alc_spec *spec = codec->spec;
  3899. const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
  3900. alc269va_ssids : alc269_ssids;
  3901. return alc_parse_auto_config(codec, alc269_ignore, ssids);
  3902. }
  3903. static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
  3904. {
  3905. int val = alc_read_coef_idx(codec, 0x04);
  3906. if (power_up)
  3907. val |= 1 << 11;
  3908. else
  3909. val &= ~(1 << 11);
  3910. alc_write_coef_idx(codec, 0x04, val);
  3911. }
  3912. static void alc269_shutup(struct hda_codec *codec)
  3913. {
  3914. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
  3915. alc269_toggle_power_output(codec, 0);
  3916. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
  3917. alc269_toggle_power_output(codec, 0);
  3918. msleep(150);
  3919. }
  3920. }
  3921. #ifdef CONFIG_PM
  3922. static int alc269_resume(struct hda_codec *codec)
  3923. {
  3924. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
  3925. alc269_toggle_power_output(codec, 0);
  3926. msleep(150);
  3927. }
  3928. codec->patch_ops.init(codec);
  3929. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
  3930. alc269_toggle_power_output(codec, 1);
  3931. msleep(200);
  3932. }
  3933. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
  3934. alc269_toggle_power_output(codec, 1);
  3935. snd_hda_codec_resume_amp(codec);
  3936. snd_hda_codec_resume_cache(codec);
  3937. hda_call_check_power_status(codec, 0x01);
  3938. return 0;
  3939. }
  3940. #endif /* CONFIG_PM */
  3941. static void alc269_fixup_hweq(struct hda_codec *codec,
  3942. const struct alc_fixup *fix, int action)
  3943. {
  3944. int coef;
  3945. if (action != ALC_FIXUP_ACT_INIT)
  3946. return;
  3947. coef = alc_read_coef_idx(codec, 0x1e);
  3948. alc_write_coef_idx(codec, 0x1e, coef | 0x80);
  3949. }
  3950. static void alc271_fixup_dmic(struct hda_codec *codec,
  3951. const struct alc_fixup *fix, int action)
  3952. {
  3953. static const struct hda_verb verbs[] = {
  3954. {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
  3955. {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
  3956. {}
  3957. };
  3958. unsigned int cfg;
  3959. if (strcmp(codec->chip_name, "ALC271X"))
  3960. return;
  3961. cfg = snd_hda_codec_get_pincfg(codec, 0x12);
  3962. if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
  3963. snd_hda_sequence_write(codec, verbs);
  3964. }
  3965. static void alc269_fixup_pcm_44k(struct hda_codec *codec,
  3966. const struct alc_fixup *fix, int action)
  3967. {
  3968. struct alc_spec *spec = codec->spec;
  3969. if (action != ALC_FIXUP_ACT_PROBE)
  3970. return;
  3971. /* Due to a hardware problem on Lenovo Ideadpad, we need to
  3972. * fix the sample rate of analog I/O to 44.1kHz
  3973. */
  3974. spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
  3975. spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
  3976. }
  3977. enum {
  3978. ALC269_FIXUP_SONY_VAIO,
  3979. ALC275_FIXUP_SONY_VAIO_GPIO2,
  3980. ALC269_FIXUP_DELL_M101Z,
  3981. ALC269_FIXUP_SKU_IGNORE,
  3982. ALC269_FIXUP_ASUS_G73JW,
  3983. ALC269_FIXUP_LENOVO_EAPD,
  3984. ALC275_FIXUP_SONY_HWEQ,
  3985. ALC271_FIXUP_DMIC,
  3986. ALC269_FIXUP_PCM_44K,
  3987. };
  3988. static const struct alc_fixup alc269_fixups[] = {
  3989. [ALC269_FIXUP_SONY_VAIO] = {
  3990. .type = ALC_FIXUP_VERBS,
  3991. .v.verbs = (const struct hda_verb[]) {
  3992. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
  3993. {}
  3994. }
  3995. },
  3996. [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
  3997. .type = ALC_FIXUP_VERBS,
  3998. .v.verbs = (const struct hda_verb[]) {
  3999. {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
  4000. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
  4001. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  4002. { }
  4003. },
  4004. .chained = true,
  4005. .chain_id = ALC269_FIXUP_SONY_VAIO
  4006. },
  4007. [ALC269_FIXUP_DELL_M101Z] = {
  4008. .type = ALC_FIXUP_VERBS,
  4009. .v.verbs = (const struct hda_verb[]) {
  4010. /* Enables internal speaker */
  4011. {0x20, AC_VERB_SET_COEF_INDEX, 13},
  4012. {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
  4013. {}
  4014. }
  4015. },
  4016. [ALC269_FIXUP_SKU_IGNORE] = {
  4017. .type = ALC_FIXUP_SKU,
  4018. .v.sku = ALC_FIXUP_SKU_IGNORE,
  4019. },
  4020. [ALC269_FIXUP_ASUS_G73JW] = {
  4021. .type = ALC_FIXUP_PINS,
  4022. .v.pins = (const struct alc_pincfg[]) {
  4023. { 0x17, 0x99130111 }, /* subwoofer */
  4024. { }
  4025. }
  4026. },
  4027. [ALC269_FIXUP_LENOVO_EAPD] = {
  4028. .type = ALC_FIXUP_VERBS,
  4029. .v.verbs = (const struct hda_verb[]) {
  4030. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  4031. {}
  4032. }
  4033. },
  4034. [ALC275_FIXUP_SONY_HWEQ] = {
  4035. .type = ALC_FIXUP_FUNC,
  4036. .v.func = alc269_fixup_hweq,
  4037. .chained = true,
  4038. .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
  4039. },
  4040. [ALC271_FIXUP_DMIC] = {
  4041. .type = ALC_FIXUP_FUNC,
  4042. .v.func = alc271_fixup_dmic,
  4043. },
  4044. [ALC269_FIXUP_PCM_44K] = {
  4045. .type = ALC_FIXUP_FUNC,
  4046. .v.func = alc269_fixup_pcm_44k,
  4047. },
  4048. };
  4049. static const struct snd_pci_quirk alc269_fixup_tbl[] = {
  4050. SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
  4051. SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
  4052. SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  4053. SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
  4054. SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
  4055. SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
  4056. SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
  4057. SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
  4058. SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
  4059. SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
  4060. SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
  4061. SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
  4062. SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
  4063. SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
  4064. {}
  4065. };
  4066. static int alc269_fill_coef(struct hda_codec *codec)
  4067. {
  4068. int val;
  4069. if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
  4070. alc_write_coef_idx(codec, 0xf, 0x960b);
  4071. alc_write_coef_idx(codec, 0xe, 0x8817);
  4072. }
  4073. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
  4074. alc_write_coef_idx(codec, 0xf, 0x960b);
  4075. alc_write_coef_idx(codec, 0xe, 0x8814);
  4076. }
  4077. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
  4078. val = alc_read_coef_idx(codec, 0x04);
  4079. /* Power up output pin */
  4080. alc_write_coef_idx(codec, 0x04, val | (1<<11));
  4081. }
  4082. if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
  4083. val = alc_read_coef_idx(codec, 0xd);
  4084. if ((val & 0x0c00) >> 10 != 0x1) {
  4085. /* Capless ramp up clock control */
  4086. alc_write_coef_idx(codec, 0xd, val | (1<<10));
  4087. }
  4088. val = alc_read_coef_idx(codec, 0x17);
  4089. if ((val & 0x01c0) >> 6 != 0x4) {
  4090. /* Class D power on reset */
  4091. alc_write_coef_idx(codec, 0x17, val | (1<<7));
  4092. }
  4093. }
  4094. val = alc_read_coef_idx(codec, 0xd); /* Class D */
  4095. alc_write_coef_idx(codec, 0xd, val | (1<<14));
  4096. val = alc_read_coef_idx(codec, 0x4); /* HP */
  4097. alc_write_coef_idx(codec, 0x4, val | (1<<11));
  4098. return 0;
  4099. }
  4100. /*
  4101. */
  4102. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4103. #include "alc269_quirks.c"
  4104. #endif
  4105. static int patch_alc269(struct hda_codec *codec)
  4106. {
  4107. struct alc_spec *spec;
  4108. int board_config, coef;
  4109. int err;
  4110. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4111. if (spec == NULL)
  4112. return -ENOMEM;
  4113. codec->spec = spec;
  4114. spec->mixer_nid = 0x0b;
  4115. alc_auto_parse_customize_define(codec);
  4116. if (codec->vendor_id == 0x10ec0269) {
  4117. spec->codec_variant = ALC269_TYPE_ALC269VA;
  4118. coef = alc_read_coef_idx(codec, 0);
  4119. if ((coef & 0x00f0) == 0x0010) {
  4120. if (codec->bus->pci->subsystem_vendor == 0x1025 &&
  4121. spec->cdefine.platform_type == 1) {
  4122. alc_codec_rename(codec, "ALC271X");
  4123. } else if ((coef & 0xf000) == 0x2000) {
  4124. alc_codec_rename(codec, "ALC259");
  4125. } else if ((coef & 0xf000) == 0x3000) {
  4126. alc_codec_rename(codec, "ALC258");
  4127. } else if ((coef & 0xfff0) == 0x3010) {
  4128. alc_codec_rename(codec, "ALC277");
  4129. } else {
  4130. alc_codec_rename(codec, "ALC269VB");
  4131. }
  4132. spec->codec_variant = ALC269_TYPE_ALC269VB;
  4133. } else if ((coef & 0x00f0) == 0x0020) {
  4134. if (coef == 0xa023)
  4135. alc_codec_rename(codec, "ALC259");
  4136. else if (coef == 0x6023)
  4137. alc_codec_rename(codec, "ALC281X");
  4138. else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
  4139. codec->bus->pci->subsystem_device == 0x21f3)
  4140. alc_codec_rename(codec, "ALC3202");
  4141. else
  4142. alc_codec_rename(codec, "ALC269VC");
  4143. spec->codec_variant = ALC269_TYPE_ALC269VC;
  4144. } else
  4145. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  4146. alc269_fill_coef(codec);
  4147. }
  4148. board_config = alc_board_config(codec, ALC269_MODEL_LAST,
  4149. alc269_models, alc269_cfg_tbl);
  4150. if (board_config < 0) {
  4151. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4152. codec->chip_name);
  4153. board_config = ALC_MODEL_AUTO;
  4154. }
  4155. if (board_config == ALC_MODEL_AUTO) {
  4156. alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
  4157. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4158. }
  4159. if (board_config == ALC_MODEL_AUTO) {
  4160. /* automatic parse from the BIOS config */
  4161. err = alc269_parse_auto_config(codec);
  4162. if (err < 0) {
  4163. alc_free(codec);
  4164. return err;
  4165. }
  4166. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4167. else if (!err) {
  4168. printk(KERN_INFO
  4169. "hda_codec: Cannot set up configuration "
  4170. "from BIOS. Using base mode...\n");
  4171. board_config = ALC269_BASIC;
  4172. }
  4173. #endif
  4174. }
  4175. if (board_config != ALC_MODEL_AUTO)
  4176. setup_preset(codec, &alc269_presets[board_config]);
  4177. if (!spec->no_analog && !spec->adc_nids) {
  4178. alc_auto_fill_adc_caps(codec);
  4179. alc_rebuild_imux_for_auto_mic(codec);
  4180. alc_remove_invalid_adc_nids(codec);
  4181. }
  4182. if (!spec->no_analog && !spec->cap_mixer)
  4183. set_capture_mixer(codec);
  4184. if (!spec->no_analog && has_cdefine_beep(codec)) {
  4185. err = snd_hda_attach_beep_device(codec, 0x1);
  4186. if (err < 0) {
  4187. alc_free(codec);
  4188. return err;
  4189. }
  4190. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  4191. }
  4192. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4193. spec->vmaster_nid = 0x02;
  4194. codec->patch_ops = alc_patch_ops;
  4195. #ifdef CONFIG_PM
  4196. codec->patch_ops.resume = alc269_resume;
  4197. #endif
  4198. if (board_config == ALC_MODEL_AUTO)
  4199. spec->init_hook = alc_auto_init_std;
  4200. spec->shutup = alc269_shutup;
  4201. alc_init_jacks(codec);
  4202. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4203. if (!spec->loopback.amplist)
  4204. spec->loopback.amplist = alc269_loopbacks;
  4205. if (alc269_mic2_for_mute_led(codec))
  4206. codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
  4207. #endif
  4208. return 0;
  4209. }
  4210. /*
  4211. * ALC861
  4212. */
  4213. static int alc861_parse_auto_config(struct hda_codec *codec)
  4214. {
  4215. static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
  4216. static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
  4217. return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
  4218. }
  4219. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4220. static const struct hda_amp_list alc861_loopbacks[] = {
  4221. { 0x15, HDA_INPUT, 0 },
  4222. { 0x15, HDA_INPUT, 1 },
  4223. { 0x15, HDA_INPUT, 2 },
  4224. { 0x15, HDA_INPUT, 3 },
  4225. { } /* end */
  4226. };
  4227. #endif
  4228. /* Pin config fixes */
  4229. enum {
  4230. PINFIX_FSC_AMILO_PI1505,
  4231. };
  4232. static const struct alc_fixup alc861_fixups[] = {
  4233. [PINFIX_FSC_AMILO_PI1505] = {
  4234. .type = ALC_FIXUP_PINS,
  4235. .v.pins = (const struct alc_pincfg[]) {
  4236. { 0x0b, 0x0221101f }, /* HP */
  4237. { 0x0f, 0x90170310 }, /* speaker */
  4238. { }
  4239. }
  4240. },
  4241. };
  4242. static const struct snd_pci_quirk alc861_fixup_tbl[] = {
  4243. SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
  4244. {}
  4245. };
  4246. /*
  4247. */
  4248. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4249. #include "alc861_quirks.c"
  4250. #endif
  4251. static int patch_alc861(struct hda_codec *codec)
  4252. {
  4253. struct alc_spec *spec;
  4254. int board_config;
  4255. int err;
  4256. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4257. if (spec == NULL)
  4258. return -ENOMEM;
  4259. codec->spec = spec;
  4260. spec->mixer_nid = 0x15;
  4261. board_config = alc_board_config(codec, ALC861_MODEL_LAST,
  4262. alc861_models, alc861_cfg_tbl);
  4263. if (board_config < 0) {
  4264. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4265. codec->chip_name);
  4266. board_config = ALC_MODEL_AUTO;
  4267. }
  4268. if (board_config == ALC_MODEL_AUTO) {
  4269. alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
  4270. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4271. }
  4272. if (board_config == ALC_MODEL_AUTO) {
  4273. /* automatic parse from the BIOS config */
  4274. err = alc861_parse_auto_config(codec);
  4275. if (err < 0) {
  4276. alc_free(codec);
  4277. return err;
  4278. }
  4279. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4280. else if (!err) {
  4281. printk(KERN_INFO
  4282. "hda_codec: Cannot set up configuration "
  4283. "from BIOS. Using base mode...\n");
  4284. board_config = ALC861_3ST_DIG;
  4285. }
  4286. #endif
  4287. }
  4288. if (board_config != ALC_MODEL_AUTO)
  4289. setup_preset(codec, &alc861_presets[board_config]);
  4290. if (!spec->no_analog && !spec->adc_nids) {
  4291. alc_auto_fill_adc_caps(codec);
  4292. alc_rebuild_imux_for_auto_mic(codec);
  4293. alc_remove_invalid_adc_nids(codec);
  4294. }
  4295. if (!spec->no_analog && !spec->cap_mixer)
  4296. set_capture_mixer(codec);
  4297. if (!spec->no_analog) {
  4298. err = snd_hda_attach_beep_device(codec, 0x23);
  4299. if (err < 0) {
  4300. alc_free(codec);
  4301. return err;
  4302. }
  4303. set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
  4304. }
  4305. spec->vmaster_nid = 0x03;
  4306. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4307. codec->patch_ops = alc_patch_ops;
  4308. if (board_config == ALC_MODEL_AUTO) {
  4309. spec->init_hook = alc_auto_init_std;
  4310. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4311. spec->power_hook = alc_power_eapd;
  4312. #endif
  4313. }
  4314. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4315. if (!spec->loopback.amplist)
  4316. spec->loopback.amplist = alc861_loopbacks;
  4317. #endif
  4318. return 0;
  4319. }
  4320. /*
  4321. * ALC861-VD support
  4322. *
  4323. * Based on ALC882
  4324. *
  4325. * In addition, an independent DAC
  4326. */
  4327. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4328. #define alc861vd_loopbacks alc880_loopbacks
  4329. #endif
  4330. static int alc861vd_parse_auto_config(struct hda_codec *codec)
  4331. {
  4332. static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
  4333. static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4334. return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
  4335. }
  4336. enum {
  4337. ALC660VD_FIX_ASUS_GPIO1
  4338. };
  4339. /* reset GPIO1 */
  4340. static const struct alc_fixup alc861vd_fixups[] = {
  4341. [ALC660VD_FIX_ASUS_GPIO1] = {
  4342. .type = ALC_FIXUP_VERBS,
  4343. .v.verbs = (const struct hda_verb[]) {
  4344. {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
  4345. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  4346. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  4347. { }
  4348. }
  4349. },
  4350. };
  4351. static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
  4352. SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
  4353. {}
  4354. };
  4355. static const struct hda_verb alc660vd_eapd_verbs[] = {
  4356. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
  4357. {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
  4358. { }
  4359. };
  4360. /*
  4361. */
  4362. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4363. #include "alc861vd_quirks.c"
  4364. #endif
  4365. static int patch_alc861vd(struct hda_codec *codec)
  4366. {
  4367. struct alc_spec *spec;
  4368. int err, board_config;
  4369. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4370. if (spec == NULL)
  4371. return -ENOMEM;
  4372. codec->spec = spec;
  4373. spec->mixer_nid = 0x0b;
  4374. board_config = alc_board_config(codec, ALC861VD_MODEL_LAST,
  4375. alc861vd_models, alc861vd_cfg_tbl);
  4376. if (board_config < 0) {
  4377. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4378. codec->chip_name);
  4379. board_config = ALC_MODEL_AUTO;
  4380. }
  4381. if (board_config == ALC_MODEL_AUTO) {
  4382. alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
  4383. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4384. }
  4385. if (board_config == ALC_MODEL_AUTO) {
  4386. /* automatic parse from the BIOS config */
  4387. err = alc861vd_parse_auto_config(codec);
  4388. if (err < 0) {
  4389. alc_free(codec);
  4390. return err;
  4391. }
  4392. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4393. else if (!err) {
  4394. printk(KERN_INFO
  4395. "hda_codec: Cannot set up configuration "
  4396. "from BIOS. Using base mode...\n");
  4397. board_config = ALC861VD_3ST;
  4398. }
  4399. #endif
  4400. }
  4401. if (board_config != ALC_MODEL_AUTO)
  4402. setup_preset(codec, &alc861vd_presets[board_config]);
  4403. if (codec->vendor_id == 0x10ec0660) {
  4404. /* always turn on EAPD */
  4405. add_verb(spec, alc660vd_eapd_verbs);
  4406. }
  4407. if (!spec->no_analog && !spec->adc_nids) {
  4408. alc_auto_fill_adc_caps(codec);
  4409. alc_rebuild_imux_for_auto_mic(codec);
  4410. alc_remove_invalid_adc_nids(codec);
  4411. }
  4412. if (!spec->no_analog && !spec->cap_mixer)
  4413. set_capture_mixer(codec);
  4414. if (!spec->no_analog) {
  4415. err = snd_hda_attach_beep_device(codec, 0x23);
  4416. if (err < 0) {
  4417. alc_free(codec);
  4418. return err;
  4419. }
  4420. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4421. }
  4422. spec->vmaster_nid = 0x02;
  4423. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4424. codec->patch_ops = alc_patch_ops;
  4425. if (board_config == ALC_MODEL_AUTO)
  4426. spec->init_hook = alc_auto_init_std;
  4427. spec->shutup = alc_eapd_shutup;
  4428. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4429. if (!spec->loopback.amplist)
  4430. spec->loopback.amplist = alc861vd_loopbacks;
  4431. #endif
  4432. return 0;
  4433. }
  4434. /*
  4435. * ALC662 support
  4436. *
  4437. * ALC662 is almost identical with ALC880 but has cleaner and more flexible
  4438. * configuration. Each pin widget can choose any input DACs and a mixer.
  4439. * Each ADC is connected from a mixer of all inputs. This makes possible
  4440. * 6-channel independent captures.
  4441. *
  4442. * In addition, an independent DAC for the multi-playback (not used in this
  4443. * driver yet).
  4444. */
  4445. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4446. #define alc662_loopbacks alc880_loopbacks
  4447. #endif
  4448. /*
  4449. * BIOS auto configuration
  4450. */
  4451. static int alc662_parse_auto_config(struct hda_codec *codec)
  4452. {
  4453. static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
  4454. static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
  4455. static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
  4456. const hda_nid_t *ssids;
  4457. if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
  4458. codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
  4459. ssids = alc663_ssids;
  4460. else
  4461. ssids = alc662_ssids;
  4462. return alc_parse_auto_config(codec, alc662_ignore, ssids);
  4463. }
  4464. static void alc272_fixup_mario(struct hda_codec *codec,
  4465. const struct alc_fixup *fix, int action)
  4466. {
  4467. if (action != ALC_FIXUP_ACT_PROBE)
  4468. return;
  4469. if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
  4470. (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
  4471. (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
  4472. (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  4473. (0 << AC_AMPCAP_MUTE_SHIFT)))
  4474. printk(KERN_WARNING
  4475. "hda_codec: failed to override amp caps for NID 0x2\n");
  4476. }
  4477. enum {
  4478. ALC662_FIXUP_ASPIRE,
  4479. ALC662_FIXUP_IDEAPAD,
  4480. ALC272_FIXUP_MARIO,
  4481. ALC662_FIXUP_CZC_P10T,
  4482. ALC662_FIXUP_SKU_IGNORE,
  4483. ALC662_FIXUP_HP_RP5800,
  4484. };
  4485. static const struct alc_fixup alc662_fixups[] = {
  4486. [ALC662_FIXUP_ASPIRE] = {
  4487. .type = ALC_FIXUP_PINS,
  4488. .v.pins = (const struct alc_pincfg[]) {
  4489. { 0x15, 0x99130112 }, /* subwoofer */
  4490. { }
  4491. }
  4492. },
  4493. [ALC662_FIXUP_IDEAPAD] = {
  4494. .type = ALC_FIXUP_PINS,
  4495. .v.pins = (const struct alc_pincfg[]) {
  4496. { 0x17, 0x99130112 }, /* subwoofer */
  4497. { }
  4498. }
  4499. },
  4500. [ALC272_FIXUP_MARIO] = {
  4501. .type = ALC_FIXUP_FUNC,
  4502. .v.func = alc272_fixup_mario,
  4503. },
  4504. [ALC662_FIXUP_CZC_P10T] = {
  4505. .type = ALC_FIXUP_VERBS,
  4506. .v.verbs = (const struct hda_verb[]) {
  4507. {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
  4508. {}
  4509. }
  4510. },
  4511. [ALC662_FIXUP_SKU_IGNORE] = {
  4512. .type = ALC_FIXUP_SKU,
  4513. .v.sku = ALC_FIXUP_SKU_IGNORE,
  4514. },
  4515. [ALC662_FIXUP_HP_RP5800] = {
  4516. .type = ALC_FIXUP_PINS,
  4517. .v.pins = (const struct alc_pincfg[]) {
  4518. { 0x14, 0x0221201f }, /* HP out */
  4519. { }
  4520. },
  4521. .chained = true,
  4522. .chain_id = ALC662_FIXUP_SKU_IGNORE
  4523. },
  4524. };
  4525. static const struct snd_pci_quirk alc662_fixup_tbl[] = {
  4526. SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
  4527. SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
  4528. SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
  4529. SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
  4530. SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
  4531. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
  4532. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
  4533. SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
  4534. {}
  4535. };
  4536. static const struct alc_model_fixup alc662_fixup_models[] = {
  4537. {.id = ALC272_FIXUP_MARIO, .name = "mario"},
  4538. {}
  4539. };
  4540. /*
  4541. */
  4542. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4543. #include "alc662_quirks.c"
  4544. #endif
  4545. static int patch_alc662(struct hda_codec *codec)
  4546. {
  4547. struct alc_spec *spec;
  4548. int err, board_config;
  4549. int coef;
  4550. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4551. if (!spec)
  4552. return -ENOMEM;
  4553. codec->spec = spec;
  4554. spec->mixer_nid = 0x0b;
  4555. alc_auto_parse_customize_define(codec);
  4556. alc_fix_pll_init(codec, 0x20, 0x04, 15);
  4557. coef = alc_read_coef_idx(codec, 0);
  4558. if (coef == 0x8020 || coef == 0x8011)
  4559. alc_codec_rename(codec, "ALC661");
  4560. else if (coef & (1 << 14) &&
  4561. codec->bus->pci->subsystem_vendor == 0x1025 &&
  4562. spec->cdefine.platform_type == 1)
  4563. alc_codec_rename(codec, "ALC272X");
  4564. else if (coef == 0x4011)
  4565. alc_codec_rename(codec, "ALC656");
  4566. board_config = alc_board_config(codec, ALC662_MODEL_LAST,
  4567. alc662_models, alc662_cfg_tbl);
  4568. if (board_config < 0) {
  4569. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4570. codec->chip_name);
  4571. board_config = ALC_MODEL_AUTO;
  4572. }
  4573. if (board_config == ALC_MODEL_AUTO) {
  4574. alc_pick_fixup(codec, alc662_fixup_models,
  4575. alc662_fixup_tbl, alc662_fixups);
  4576. alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
  4577. /* automatic parse from the BIOS config */
  4578. err = alc662_parse_auto_config(codec);
  4579. if (err < 0) {
  4580. alc_free(codec);
  4581. return err;
  4582. }
  4583. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4584. else if (!err) {
  4585. printk(KERN_INFO
  4586. "hda_codec: Cannot set up configuration "
  4587. "from BIOS. Using base mode...\n");
  4588. board_config = ALC662_3ST_2ch_DIG;
  4589. }
  4590. #endif
  4591. }
  4592. if (board_config != ALC_MODEL_AUTO)
  4593. setup_preset(codec, &alc662_presets[board_config]);
  4594. if (!spec->no_analog && !spec->adc_nids) {
  4595. alc_auto_fill_adc_caps(codec);
  4596. alc_rebuild_imux_for_auto_mic(codec);
  4597. alc_remove_invalid_adc_nids(codec);
  4598. }
  4599. if (!spec->no_analog && !spec->cap_mixer)
  4600. set_capture_mixer(codec);
  4601. if (!spec->no_analog && has_cdefine_beep(codec)) {
  4602. err = snd_hda_attach_beep_device(codec, 0x1);
  4603. if (err < 0) {
  4604. alc_free(codec);
  4605. return err;
  4606. }
  4607. switch (codec->vendor_id) {
  4608. case 0x10ec0662:
  4609. set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
  4610. break;
  4611. case 0x10ec0272:
  4612. case 0x10ec0663:
  4613. case 0x10ec0665:
  4614. set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
  4615. break;
  4616. case 0x10ec0273:
  4617. set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
  4618. break;
  4619. }
  4620. }
  4621. spec->vmaster_nid = 0x02;
  4622. alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
  4623. codec->patch_ops = alc_patch_ops;
  4624. if (board_config == ALC_MODEL_AUTO)
  4625. spec->init_hook = alc_auto_init_std;
  4626. spec->shutup = alc_eapd_shutup;
  4627. alc_init_jacks(codec);
  4628. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4629. if (!spec->loopback.amplist)
  4630. spec->loopback.amplist = alc662_loopbacks;
  4631. #endif
  4632. return 0;
  4633. }
  4634. static int patch_alc888(struct hda_codec *codec)
  4635. {
  4636. if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
  4637. kfree(codec->chip_name);
  4638. if (codec->vendor_id == 0x10ec0887)
  4639. codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
  4640. else
  4641. codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
  4642. if (!codec->chip_name) {
  4643. alc_free(codec);
  4644. return -ENOMEM;
  4645. }
  4646. return patch_alc662(codec);
  4647. }
  4648. return patch_alc882(codec);
  4649. }
  4650. static int patch_alc899(struct hda_codec *codec)
  4651. {
  4652. if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
  4653. kfree(codec->chip_name);
  4654. codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
  4655. }
  4656. return patch_alc882(codec);
  4657. }
  4658. /*
  4659. * ALC680 support
  4660. */
  4661. static int alc680_parse_auto_config(struct hda_codec *codec)
  4662. {
  4663. return alc_parse_auto_config(codec, NULL, NULL);
  4664. }
  4665. /*
  4666. */
  4667. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4668. #include "alc680_quirks.c"
  4669. #endif
  4670. static int patch_alc680(struct hda_codec *codec)
  4671. {
  4672. struct alc_spec *spec;
  4673. int board_config;
  4674. int err;
  4675. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4676. if (spec == NULL)
  4677. return -ENOMEM;
  4678. codec->spec = spec;
  4679. /* ALC680 has no aa-loopback mixer */
  4680. board_config = alc_board_config(codec, ALC680_MODEL_LAST,
  4681. alc680_models, alc680_cfg_tbl);
  4682. if (board_config < 0) {
  4683. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  4684. codec->chip_name);
  4685. board_config = ALC_MODEL_AUTO;
  4686. }
  4687. if (board_config == ALC_MODEL_AUTO) {
  4688. /* automatic parse from the BIOS config */
  4689. err = alc680_parse_auto_config(codec);
  4690. if (err < 0) {
  4691. alc_free(codec);
  4692. return err;
  4693. }
  4694. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4695. else if (!err) {
  4696. printk(KERN_INFO
  4697. "hda_codec: Cannot set up configuration "
  4698. "from BIOS. Using base mode...\n");
  4699. board_config = ALC680_BASE;
  4700. }
  4701. #endif
  4702. }
  4703. if (board_config != ALC_MODEL_AUTO) {
  4704. setup_preset(codec, &alc680_presets[board_config]);
  4705. #ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
  4706. spec->stream_analog_capture = &alc680_pcm_analog_auto_capture;
  4707. #endif
  4708. }
  4709. if (!spec->no_analog && !spec->adc_nids) {
  4710. alc_auto_fill_adc_caps(codec);
  4711. alc_rebuild_imux_for_auto_mic(codec);
  4712. alc_remove_invalid_adc_nids(codec);
  4713. }
  4714. if (!spec->no_analog && !spec->cap_mixer)
  4715. set_capture_mixer(codec);
  4716. spec->vmaster_nid = 0x02;
  4717. codec->patch_ops = alc_patch_ops;
  4718. if (board_config == ALC_MODEL_AUTO)
  4719. spec->init_hook = alc_auto_init_std;
  4720. return 0;
  4721. }
  4722. /*
  4723. * patch entries
  4724. */
  4725. static const struct hda_codec_preset snd_hda_preset_realtek[] = {
  4726. { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
  4727. { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
  4728. { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
  4729. { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
  4730. { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
  4731. { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
  4732. { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
  4733. { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
  4734. { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
  4735. { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
  4736. { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
  4737. .patch = patch_alc861 },
  4738. { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
  4739. { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
  4740. { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
  4741. { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
  4742. .patch = patch_alc882 },
  4743. { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
  4744. .patch = patch_alc662 },
  4745. { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
  4746. { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
  4747. { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
  4748. { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
  4749. { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
  4750. { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
  4751. { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
  4752. { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
  4753. .patch = patch_alc882 },
  4754. { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
  4755. .patch = patch_alc882 },
  4756. { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
  4757. { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
  4758. { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
  4759. .patch = patch_alc882 },
  4760. { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
  4761. { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
  4762. { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
  4763. { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
  4764. {} /* terminator */
  4765. };
  4766. MODULE_ALIAS("snd-hda-codec-id:10ec*");
  4767. MODULE_LICENSE("GPL");
  4768. MODULE_DESCRIPTION("Realtek HD-audio codec");
  4769. static struct hda_codec_preset_list realtek_list = {
  4770. .preset = snd_hda_preset_realtek,
  4771. .owner = THIS_MODULE,
  4772. };
  4773. static int __init patch_realtek_init(void)
  4774. {
  4775. return snd_hda_add_codec_preset(&realtek_list);
  4776. }
  4777. static void __exit patch_realtek_exit(void)
  4778. {
  4779. snd_hda_delete_codec_preset(&realtek_list);
  4780. }
  4781. module_init(patch_realtek_init)
  4782. module_exit(patch_realtek_exit)