patch_analog.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069
  1. /*
  2. * HD audio interface patch for AD1882, AD1884, AD1981HD, AD1983, AD1984,
  3. * AD1986A, AD1988
  4. *
  5. * Copyright (c) 2005-2007 Takashi Iwai <tiwai@suse.de>
  6. *
  7. * This driver is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This driver is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/delay.h>
  23. #include <linux/slab.h>
  24. #include <linux/pci.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include "hda_codec.h"
  28. #include "hda_local.h"
  29. #include "hda_beep.h"
  30. #include "hda_jack.h"
  31. struct ad198x_spec {
  32. const struct snd_kcontrol_new *mixers[6];
  33. int num_mixers;
  34. unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
  35. const struct hda_verb *init_verbs[6]; /* initialization verbs
  36. * don't forget NULL termination!
  37. */
  38. unsigned int num_init_verbs;
  39. /* playback */
  40. struct hda_multi_out multiout; /* playback set-up
  41. * max_channels, dacs must be set
  42. * dig_out_nid and hp_nid are optional
  43. */
  44. unsigned int cur_eapd;
  45. unsigned int need_dac_fix;
  46. const hda_nid_t *alt_dac_nid;
  47. const struct hda_pcm_stream *stream_analog_alt_playback;
  48. int independent_hp;
  49. int num_active_streams;
  50. /* capture */
  51. unsigned int num_adc_nids;
  52. const hda_nid_t *adc_nids;
  53. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  54. /* capture source */
  55. const struct hda_input_mux *input_mux;
  56. const hda_nid_t *capsrc_nids;
  57. unsigned int cur_mux[3];
  58. /* channel model */
  59. const struct hda_channel_mode *channel_mode;
  60. int num_channel_mode;
  61. /* PCM information */
  62. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  63. unsigned int spdif_route;
  64. /* dynamic controls, init_verbs and input_mux */
  65. struct auto_pin_cfg autocfg;
  66. struct snd_array kctls;
  67. struct hda_input_mux private_imux;
  68. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  69. unsigned int jack_present: 1;
  70. unsigned int inv_jack_detect: 1;/* inverted jack-detection */
  71. unsigned int inv_eapd: 1; /* inverted EAPD implementation */
  72. unsigned int analog_beep: 1; /* analog beep input present */
  73. unsigned int avoid_init_slave_vol:1;
  74. #ifdef CONFIG_SND_HDA_POWER_SAVE
  75. struct hda_loopback_check loopback;
  76. #endif
  77. /* for virtual master */
  78. hda_nid_t vmaster_nid;
  79. const char * const *slave_vols;
  80. const char * const *slave_sws;
  81. };
  82. /*
  83. * input MUX handling (common part)
  84. */
  85. static int ad198x_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  86. {
  87. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  88. struct ad198x_spec *spec = codec->spec;
  89. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  90. }
  91. static int ad198x_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  92. {
  93. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  94. struct ad198x_spec *spec = codec->spec;
  95. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  96. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  97. return 0;
  98. }
  99. static int ad198x_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  100. {
  101. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  102. struct ad198x_spec *spec = codec->spec;
  103. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  104. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  105. spec->capsrc_nids[adc_idx],
  106. &spec->cur_mux[adc_idx]);
  107. }
  108. /*
  109. * initialization (common callbacks)
  110. */
  111. static int ad198x_init(struct hda_codec *codec)
  112. {
  113. struct ad198x_spec *spec = codec->spec;
  114. int i;
  115. for (i = 0; i < spec->num_init_verbs; i++)
  116. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  117. return 0;
  118. }
  119. static const char * const ad_slave_pfxs[] = {
  120. "Front", "Surround", "Center", "LFE", "Side",
  121. "Headphone", "Mono", "Speaker", "IEC958",
  122. NULL
  123. };
  124. static const char * const ad1988_6stack_fp_slave_pfxs[] = {
  125. "Front", "Surround", "Center", "LFE", "Side", "IEC958",
  126. NULL
  127. };
  128. static void ad198x_free_kctls(struct hda_codec *codec);
  129. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  130. /* additional beep mixers; the actual parameters are overwritten at build */
  131. static const struct snd_kcontrol_new ad_beep_mixer[] = {
  132. HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_OUTPUT),
  133. HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_OUTPUT),
  134. { } /* end */
  135. };
  136. static const struct snd_kcontrol_new ad_beep2_mixer[] = {
  137. HDA_CODEC_VOLUME("Digital Beep Playback Volume", 0, 0, HDA_OUTPUT),
  138. HDA_CODEC_MUTE_BEEP("Digital Beep Playback Switch", 0, 0, HDA_OUTPUT),
  139. { } /* end */
  140. };
  141. #define set_beep_amp(spec, nid, idx, dir) \
  142. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir)) /* mono */
  143. #else
  144. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  145. #endif
  146. static int ad198x_build_controls(struct hda_codec *codec)
  147. {
  148. struct ad198x_spec *spec = codec->spec;
  149. struct snd_kcontrol *kctl;
  150. unsigned int i;
  151. int err;
  152. for (i = 0; i < spec->num_mixers; i++) {
  153. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  154. if (err < 0)
  155. return err;
  156. }
  157. if (spec->multiout.dig_out_nid) {
  158. err = snd_hda_create_spdif_out_ctls(codec,
  159. spec->multiout.dig_out_nid,
  160. spec->multiout.dig_out_nid);
  161. if (err < 0)
  162. return err;
  163. err = snd_hda_create_spdif_share_sw(codec,
  164. &spec->multiout);
  165. if (err < 0)
  166. return err;
  167. spec->multiout.share_spdif = 1;
  168. }
  169. if (spec->dig_in_nid) {
  170. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  171. if (err < 0)
  172. return err;
  173. }
  174. /* create beep controls if needed */
  175. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  176. if (spec->beep_amp) {
  177. const struct snd_kcontrol_new *knew;
  178. knew = spec->analog_beep ? ad_beep2_mixer : ad_beep_mixer;
  179. for ( ; knew->name; knew++) {
  180. struct snd_kcontrol *kctl;
  181. kctl = snd_ctl_new1(knew, codec);
  182. if (!kctl)
  183. return -ENOMEM;
  184. kctl->private_value = spec->beep_amp;
  185. err = snd_hda_ctl_add(codec, 0, kctl);
  186. if (err < 0)
  187. return err;
  188. }
  189. }
  190. #endif
  191. /* if we have no master control, let's create it */
  192. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  193. unsigned int vmaster_tlv[4];
  194. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  195. HDA_OUTPUT, vmaster_tlv);
  196. err = __snd_hda_add_vmaster(codec, "Master Playback Volume",
  197. vmaster_tlv,
  198. (spec->slave_vols ?
  199. spec->slave_vols : ad_slave_pfxs),
  200. "Playback Volume",
  201. !spec->avoid_init_slave_vol, NULL);
  202. if (err < 0)
  203. return err;
  204. }
  205. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  206. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  207. NULL,
  208. (spec->slave_sws ?
  209. spec->slave_sws : ad_slave_pfxs),
  210. "Playback Switch");
  211. if (err < 0)
  212. return err;
  213. }
  214. ad198x_free_kctls(codec); /* no longer needed */
  215. /* assign Capture Source enums to NID */
  216. kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
  217. if (!kctl)
  218. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  219. for (i = 0; kctl && i < kctl->count; i++) {
  220. err = snd_hda_add_nid(codec, kctl, i, spec->capsrc_nids[i]);
  221. if (err < 0)
  222. return err;
  223. }
  224. /* assign IEC958 enums to NID */
  225. kctl = snd_hda_find_mixer_ctl(codec,
  226. SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source");
  227. if (kctl) {
  228. err = snd_hda_add_nid(codec, kctl, 0,
  229. spec->multiout.dig_out_nid);
  230. if (err < 0)
  231. return err;
  232. }
  233. return 0;
  234. }
  235. #ifdef CONFIG_SND_HDA_POWER_SAVE
  236. static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  237. {
  238. struct ad198x_spec *spec = codec->spec;
  239. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  240. }
  241. #endif
  242. static void activate_ctl(struct hda_codec *codec, const char *name, int active)
  243. {
  244. struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
  245. if (ctl) {
  246. ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  247. ctl->vd[0].access |= active ? 0 :
  248. SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  249. ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
  250. ctl->vd[0].access |= active ?
  251. SNDRV_CTL_ELEM_ACCESS_WRITE : 0;
  252. snd_ctl_notify(codec->bus->card,
  253. SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
  254. }
  255. }
  256. static void set_stream_active(struct hda_codec *codec, bool active)
  257. {
  258. struct ad198x_spec *spec = codec->spec;
  259. if (active)
  260. spec->num_active_streams++;
  261. else
  262. spec->num_active_streams--;
  263. activate_ctl(codec, "Independent HP", spec->num_active_streams == 0);
  264. }
  265. static int ad1988_independent_hp_info(struct snd_kcontrol *kcontrol,
  266. struct snd_ctl_elem_info *uinfo)
  267. {
  268. static const char * const texts[] = { "OFF", "ON", NULL};
  269. int index;
  270. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  271. uinfo->count = 1;
  272. uinfo->value.enumerated.items = 2;
  273. index = uinfo->value.enumerated.item;
  274. if (index >= 2)
  275. index = 1;
  276. strcpy(uinfo->value.enumerated.name, texts[index]);
  277. return 0;
  278. }
  279. static int ad1988_independent_hp_get(struct snd_kcontrol *kcontrol,
  280. struct snd_ctl_elem_value *ucontrol)
  281. {
  282. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  283. struct ad198x_spec *spec = codec->spec;
  284. ucontrol->value.enumerated.item[0] = spec->independent_hp;
  285. return 0;
  286. }
  287. static int ad1988_independent_hp_put(struct snd_kcontrol *kcontrol,
  288. struct snd_ctl_elem_value *ucontrol)
  289. {
  290. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  291. struct ad198x_spec *spec = codec->spec;
  292. unsigned int select = ucontrol->value.enumerated.item[0];
  293. if (spec->independent_hp != select) {
  294. spec->independent_hp = select;
  295. if (spec->independent_hp)
  296. spec->multiout.hp_nid = 0;
  297. else
  298. spec->multiout.hp_nid = spec->alt_dac_nid[0];
  299. return 1;
  300. }
  301. return 0;
  302. }
  303. /*
  304. * Analog playback callbacks
  305. */
  306. static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
  307. struct hda_codec *codec,
  308. struct snd_pcm_substream *substream)
  309. {
  310. struct ad198x_spec *spec = codec->spec;
  311. int err;
  312. set_stream_active(codec, true);
  313. err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  314. hinfo);
  315. if (err < 0) {
  316. set_stream_active(codec, false);
  317. return err;
  318. }
  319. return 0;
  320. }
  321. static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  322. struct hda_codec *codec,
  323. unsigned int stream_tag,
  324. unsigned int format,
  325. struct snd_pcm_substream *substream)
  326. {
  327. struct ad198x_spec *spec = codec->spec;
  328. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  329. format, substream);
  330. }
  331. static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  332. struct hda_codec *codec,
  333. struct snd_pcm_substream *substream)
  334. {
  335. struct ad198x_spec *spec = codec->spec;
  336. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  337. }
  338. static int ad198x_playback_pcm_close(struct hda_pcm_stream *hinfo,
  339. struct hda_codec *codec,
  340. struct snd_pcm_substream *substream)
  341. {
  342. set_stream_active(codec, false);
  343. return 0;
  344. }
  345. static int ad1988_alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
  346. struct hda_codec *codec,
  347. struct snd_pcm_substream *substream)
  348. {
  349. struct ad198x_spec *spec = codec->spec;
  350. if (!spec->independent_hp)
  351. return -EBUSY;
  352. set_stream_active(codec, true);
  353. return 0;
  354. }
  355. static int ad1988_alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
  356. struct hda_codec *codec,
  357. struct snd_pcm_substream *substream)
  358. {
  359. set_stream_active(codec, false);
  360. return 0;
  361. }
  362. static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
  363. .substreams = 1,
  364. .channels_min = 2,
  365. .channels_max = 2,
  366. .ops = {
  367. .open = ad1988_alt_playback_pcm_open,
  368. .close = ad1988_alt_playback_pcm_close
  369. },
  370. };
  371. /*
  372. * Digital out
  373. */
  374. static int ad198x_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  375. struct hda_codec *codec,
  376. struct snd_pcm_substream *substream)
  377. {
  378. struct ad198x_spec *spec = codec->spec;
  379. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  380. }
  381. static int ad198x_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  382. struct hda_codec *codec,
  383. struct snd_pcm_substream *substream)
  384. {
  385. struct ad198x_spec *spec = codec->spec;
  386. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  387. }
  388. static int ad198x_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  389. struct hda_codec *codec,
  390. unsigned int stream_tag,
  391. unsigned int format,
  392. struct snd_pcm_substream *substream)
  393. {
  394. struct ad198x_spec *spec = codec->spec;
  395. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  396. format, substream);
  397. }
  398. static int ad198x_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  399. struct hda_codec *codec,
  400. struct snd_pcm_substream *substream)
  401. {
  402. struct ad198x_spec *spec = codec->spec;
  403. return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  404. }
  405. /*
  406. * Analog capture
  407. */
  408. static int ad198x_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  409. struct hda_codec *codec,
  410. unsigned int stream_tag,
  411. unsigned int format,
  412. struct snd_pcm_substream *substream)
  413. {
  414. struct ad198x_spec *spec = codec->spec;
  415. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  416. stream_tag, 0, format);
  417. return 0;
  418. }
  419. static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  420. struct hda_codec *codec,
  421. struct snd_pcm_substream *substream)
  422. {
  423. struct ad198x_spec *spec = codec->spec;
  424. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  425. return 0;
  426. }
  427. /*
  428. */
  429. static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
  430. .substreams = 1,
  431. .channels_min = 2,
  432. .channels_max = 6, /* changed later */
  433. .nid = 0, /* fill later */
  434. .ops = {
  435. .open = ad198x_playback_pcm_open,
  436. .prepare = ad198x_playback_pcm_prepare,
  437. .cleanup = ad198x_playback_pcm_cleanup,
  438. .close = ad198x_playback_pcm_close
  439. },
  440. };
  441. static const struct hda_pcm_stream ad198x_pcm_analog_capture = {
  442. .substreams = 1,
  443. .channels_min = 2,
  444. .channels_max = 2,
  445. .nid = 0, /* fill later */
  446. .ops = {
  447. .prepare = ad198x_capture_pcm_prepare,
  448. .cleanup = ad198x_capture_pcm_cleanup
  449. },
  450. };
  451. static const struct hda_pcm_stream ad198x_pcm_digital_playback = {
  452. .substreams = 1,
  453. .channels_min = 2,
  454. .channels_max = 2,
  455. .nid = 0, /* fill later */
  456. .ops = {
  457. .open = ad198x_dig_playback_pcm_open,
  458. .close = ad198x_dig_playback_pcm_close,
  459. .prepare = ad198x_dig_playback_pcm_prepare,
  460. .cleanup = ad198x_dig_playback_pcm_cleanup
  461. },
  462. };
  463. static const struct hda_pcm_stream ad198x_pcm_digital_capture = {
  464. .substreams = 1,
  465. .channels_min = 2,
  466. .channels_max = 2,
  467. /* NID is set in alc_build_pcms */
  468. };
  469. static int ad198x_build_pcms(struct hda_codec *codec)
  470. {
  471. struct ad198x_spec *spec = codec->spec;
  472. struct hda_pcm *info = spec->pcm_rec;
  473. codec->num_pcms = 1;
  474. codec->pcm_info = info;
  475. info->name = "AD198x Analog";
  476. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_analog_playback;
  477. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->multiout.max_channels;
  478. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  479. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_analog_capture;
  480. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  481. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  482. if (spec->multiout.dig_out_nid) {
  483. info++;
  484. codec->num_pcms++;
  485. codec->spdif_status_reset = 1;
  486. info->name = "AD198x Digital";
  487. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  488. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
  489. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  490. if (spec->dig_in_nid) {
  491. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad198x_pcm_digital_capture;
  492. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  493. }
  494. }
  495. if (spec->alt_dac_nid && spec->stream_analog_alt_playback) {
  496. codec->num_pcms++;
  497. info = spec->pcm_rec + 2;
  498. info->name = "AD198x Headphone";
  499. info->pcm_type = HDA_PCM_TYPE_AUDIO;
  500. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  501. *spec->stream_analog_alt_playback;
  502. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  503. spec->alt_dac_nid[0];
  504. }
  505. return 0;
  506. }
  507. static void ad198x_free_kctls(struct hda_codec *codec)
  508. {
  509. struct ad198x_spec *spec = codec->spec;
  510. if (spec->kctls.list) {
  511. struct snd_kcontrol_new *kctl = spec->kctls.list;
  512. int i;
  513. for (i = 0; i < spec->kctls.used; i++)
  514. kfree(kctl[i].name);
  515. }
  516. snd_array_free(&spec->kctls);
  517. }
  518. static void ad198x_power_eapd_write(struct hda_codec *codec, hda_nid_t front,
  519. hda_nid_t hp)
  520. {
  521. struct ad198x_spec *spec = codec->spec;
  522. if (snd_hda_query_pin_caps(codec, front) & AC_PINCAP_EAPD)
  523. snd_hda_codec_write(codec, front, 0, AC_VERB_SET_EAPD_BTLENABLE,
  524. !spec->inv_eapd ? 0x00 : 0x02);
  525. if (snd_hda_query_pin_caps(codec, hp) & AC_PINCAP_EAPD)
  526. snd_hda_codec_write(codec, hp, 0, AC_VERB_SET_EAPD_BTLENABLE,
  527. !spec->inv_eapd ? 0x00 : 0x02);
  528. }
  529. static void ad198x_power_eapd(struct hda_codec *codec)
  530. {
  531. /* We currently only handle front, HP */
  532. switch (codec->vendor_id) {
  533. case 0x11d41882:
  534. case 0x11d4882a:
  535. case 0x11d41884:
  536. case 0x11d41984:
  537. case 0x11d41883:
  538. case 0x11d4184a:
  539. case 0x11d4194a:
  540. case 0x11d4194b:
  541. case 0x11d41988:
  542. case 0x11d4198b:
  543. case 0x11d4989a:
  544. case 0x11d4989b:
  545. ad198x_power_eapd_write(codec, 0x12, 0x11);
  546. break;
  547. case 0x11d41981:
  548. case 0x11d41983:
  549. ad198x_power_eapd_write(codec, 0x05, 0x06);
  550. break;
  551. case 0x11d41986:
  552. ad198x_power_eapd_write(codec, 0x1b, 0x1a);
  553. break;
  554. }
  555. }
  556. static void ad198x_shutup(struct hda_codec *codec)
  557. {
  558. snd_hda_shutup_pins(codec);
  559. ad198x_power_eapd(codec);
  560. }
  561. static void ad198x_free(struct hda_codec *codec)
  562. {
  563. struct ad198x_spec *spec = codec->spec;
  564. if (!spec)
  565. return;
  566. ad198x_shutup(codec);
  567. ad198x_free_kctls(codec);
  568. kfree(spec);
  569. snd_hda_detach_beep_device(codec);
  570. }
  571. #ifdef CONFIG_PM
  572. static int ad198x_suspend(struct hda_codec *codec, pm_message_t state)
  573. {
  574. ad198x_shutup(codec);
  575. return 0;
  576. }
  577. #endif
  578. static const struct hda_codec_ops ad198x_patch_ops = {
  579. .build_controls = ad198x_build_controls,
  580. .build_pcms = ad198x_build_pcms,
  581. .init = ad198x_init,
  582. .free = ad198x_free,
  583. #ifdef CONFIG_SND_HDA_POWER_SAVE
  584. .check_power_status = ad198x_check_power_status,
  585. #endif
  586. #ifdef CONFIG_PM
  587. .suspend = ad198x_suspend,
  588. #endif
  589. .reboot_notify = ad198x_shutup,
  590. };
  591. /*
  592. * EAPD control
  593. * the private value = nid
  594. */
  595. #define ad198x_eapd_info snd_ctl_boolean_mono_info
  596. static int ad198x_eapd_get(struct snd_kcontrol *kcontrol,
  597. struct snd_ctl_elem_value *ucontrol)
  598. {
  599. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  600. struct ad198x_spec *spec = codec->spec;
  601. if (spec->inv_eapd)
  602. ucontrol->value.integer.value[0] = ! spec->cur_eapd;
  603. else
  604. ucontrol->value.integer.value[0] = spec->cur_eapd;
  605. return 0;
  606. }
  607. static int ad198x_eapd_put(struct snd_kcontrol *kcontrol,
  608. struct snd_ctl_elem_value *ucontrol)
  609. {
  610. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  611. struct ad198x_spec *spec = codec->spec;
  612. hda_nid_t nid = kcontrol->private_value & 0xff;
  613. unsigned int eapd;
  614. eapd = !!ucontrol->value.integer.value[0];
  615. if (spec->inv_eapd)
  616. eapd = !eapd;
  617. if (eapd == spec->cur_eapd)
  618. return 0;
  619. spec->cur_eapd = eapd;
  620. snd_hda_codec_write_cache(codec, nid,
  621. 0, AC_VERB_SET_EAPD_BTLENABLE,
  622. eapd ? 0x02 : 0x00);
  623. return 1;
  624. }
  625. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  626. struct snd_ctl_elem_info *uinfo);
  627. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  628. struct snd_ctl_elem_value *ucontrol);
  629. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  630. struct snd_ctl_elem_value *ucontrol);
  631. /*
  632. * AD1986A specific
  633. */
  634. #define AD1986A_SPDIF_OUT 0x02
  635. #define AD1986A_FRONT_DAC 0x03
  636. #define AD1986A_SURR_DAC 0x04
  637. #define AD1986A_CLFE_DAC 0x05
  638. #define AD1986A_ADC 0x06
  639. static const hda_nid_t ad1986a_dac_nids[3] = {
  640. AD1986A_FRONT_DAC, AD1986A_SURR_DAC, AD1986A_CLFE_DAC
  641. };
  642. static const hda_nid_t ad1986a_adc_nids[1] = { AD1986A_ADC };
  643. static const hda_nid_t ad1986a_capsrc_nids[1] = { 0x12 };
  644. static const struct hda_input_mux ad1986a_capture_source = {
  645. .num_items = 7,
  646. .items = {
  647. { "Mic", 0x0 },
  648. { "CD", 0x1 },
  649. { "Aux", 0x3 },
  650. { "Line", 0x4 },
  651. { "Mix", 0x5 },
  652. { "Mono", 0x6 },
  653. { "Phone", 0x7 },
  654. },
  655. };
  656. static const struct hda_bind_ctls ad1986a_bind_pcm_vol = {
  657. .ops = &snd_hda_bind_vol,
  658. .values = {
  659. HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  660. HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  661. HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  662. 0
  663. },
  664. };
  665. static const struct hda_bind_ctls ad1986a_bind_pcm_sw = {
  666. .ops = &snd_hda_bind_sw,
  667. .values = {
  668. HDA_COMPOSE_AMP_VAL(AD1986A_FRONT_DAC, 3, 0, HDA_OUTPUT),
  669. HDA_COMPOSE_AMP_VAL(AD1986A_SURR_DAC, 3, 0, HDA_OUTPUT),
  670. HDA_COMPOSE_AMP_VAL(AD1986A_CLFE_DAC, 3, 0, HDA_OUTPUT),
  671. 0
  672. },
  673. };
  674. /*
  675. * mixers
  676. */
  677. static const struct snd_kcontrol_new ad1986a_mixers[] = {
  678. /*
  679. * bind volumes/mutes of 3 DACs as a single PCM control for simplicity
  680. */
  681. HDA_BIND_VOL("PCM Playback Volume", &ad1986a_bind_pcm_vol),
  682. HDA_BIND_SW("PCM Playback Switch", &ad1986a_bind_pcm_sw),
  683. HDA_CODEC_VOLUME("Front Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  684. HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  685. HDA_CODEC_VOLUME("Surround Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  686. HDA_CODEC_MUTE("Surround Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  687. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x1d, 1, 0x0, HDA_OUTPUT),
  688. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x1d, 2, 0x0, HDA_OUTPUT),
  689. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x1d, 1, 0x0, HDA_OUTPUT),
  690. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x1d, 2, 0x0, HDA_OUTPUT),
  691. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x1a, 0x0, HDA_OUTPUT),
  692. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x0, HDA_OUTPUT),
  693. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  694. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  695. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  696. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  697. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  698. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  699. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  700. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  701. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  702. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  703. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT),
  704. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  705. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  706. {
  707. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  708. .name = "Capture Source",
  709. .info = ad198x_mux_enum_info,
  710. .get = ad198x_mux_enum_get,
  711. .put = ad198x_mux_enum_put,
  712. },
  713. HDA_CODEC_MUTE("Stereo Downmix Switch", 0x09, 0x0, HDA_OUTPUT),
  714. { } /* end */
  715. };
  716. /* additional mixers for 3stack mode */
  717. static const struct snd_kcontrol_new ad1986a_3st_mixers[] = {
  718. {
  719. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  720. .name = "Channel Mode",
  721. .info = ad198x_ch_mode_info,
  722. .get = ad198x_ch_mode_get,
  723. .put = ad198x_ch_mode_put,
  724. },
  725. { } /* end */
  726. };
  727. /* laptop model - 2ch only */
  728. static const hda_nid_t ad1986a_laptop_dac_nids[1] = { AD1986A_FRONT_DAC };
  729. /* master controls both pins 0x1a and 0x1b */
  730. static const struct hda_bind_ctls ad1986a_laptop_master_vol = {
  731. .ops = &snd_hda_bind_vol,
  732. .values = {
  733. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  734. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  735. 0,
  736. },
  737. };
  738. static const struct hda_bind_ctls ad1986a_laptop_master_sw = {
  739. .ops = &snd_hda_bind_sw,
  740. .values = {
  741. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  742. HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
  743. 0,
  744. },
  745. };
  746. static const struct snd_kcontrol_new ad1986a_laptop_mixers[] = {
  747. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  748. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  749. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  750. HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
  751. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  752. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  753. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x0, HDA_OUTPUT),
  754. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x0, HDA_OUTPUT),
  755. HDA_CODEC_VOLUME("Aux Playback Volume", 0x16, 0x0, HDA_OUTPUT),
  756. HDA_CODEC_MUTE("Aux Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  757. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  758. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  759. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  760. /*
  761. HDA_CODEC_VOLUME("Mono Playback Volume", 0x1e, 0x0, HDA_OUTPUT),
  762. HDA_CODEC_MUTE("Mono Playback Switch", 0x1e, 0x0, HDA_OUTPUT), */
  763. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  764. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  765. {
  766. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  767. .name = "Capture Source",
  768. .info = ad198x_mux_enum_info,
  769. .get = ad198x_mux_enum_get,
  770. .put = ad198x_mux_enum_put,
  771. },
  772. { } /* end */
  773. };
  774. /* laptop-eapd model - 2ch only */
  775. static const struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
  776. .num_items = 3,
  777. .items = {
  778. { "Mic", 0x0 },
  779. { "Internal Mic", 0x4 },
  780. { "Mix", 0x5 },
  781. },
  782. };
  783. static const struct hda_input_mux ad1986a_automic_capture_source = {
  784. .num_items = 2,
  785. .items = {
  786. { "Mic", 0x0 },
  787. { "Mix", 0x5 },
  788. },
  789. };
  790. static const struct snd_kcontrol_new ad1986a_laptop_master_mixers[] = {
  791. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  792. HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
  793. { } /* end */
  794. };
  795. static const struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
  796. HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  797. HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  798. HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  799. HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  800. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0f, 0x0, HDA_OUTPUT),
  801. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  802. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_OUTPUT),
  803. {
  804. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  805. .name = "Capture Source",
  806. .info = ad198x_mux_enum_info,
  807. .get = ad198x_mux_enum_get,
  808. .put = ad198x_mux_enum_put,
  809. },
  810. {
  811. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  812. .name = "External Amplifier",
  813. .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
  814. .info = ad198x_eapd_info,
  815. .get = ad198x_eapd_get,
  816. .put = ad198x_eapd_put,
  817. .private_value = 0x1b, /* port-D */
  818. },
  819. { } /* end */
  820. };
  821. static const struct snd_kcontrol_new ad1986a_laptop_intmic_mixers[] = {
  822. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0, HDA_OUTPUT),
  823. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0, HDA_OUTPUT),
  824. { } /* end */
  825. };
  826. /* re-connect the mic boost input according to the jack sensing */
  827. static void ad1986a_automic(struct hda_codec *codec)
  828. {
  829. unsigned int present;
  830. present = snd_hda_jack_detect(codec, 0x1f);
  831. /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
  832. snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
  833. present ? 0 : 2);
  834. }
  835. #define AD1986A_MIC_EVENT 0x36
  836. static void ad1986a_automic_unsol_event(struct hda_codec *codec,
  837. unsigned int res)
  838. {
  839. if ((res >> 26) != AD1986A_MIC_EVENT)
  840. return;
  841. ad1986a_automic(codec);
  842. }
  843. static int ad1986a_automic_init(struct hda_codec *codec)
  844. {
  845. ad198x_init(codec);
  846. ad1986a_automic(codec);
  847. return 0;
  848. }
  849. /* laptop-automute - 2ch only */
  850. static void ad1986a_update_hp(struct hda_codec *codec)
  851. {
  852. struct ad198x_spec *spec = codec->spec;
  853. unsigned int mute;
  854. if (spec->jack_present)
  855. mute = HDA_AMP_MUTE; /* mute internal speaker */
  856. else
  857. /* unmute internal speaker if necessary */
  858. mute = snd_hda_codec_amp_read(codec, 0x1a, 0, HDA_OUTPUT, 0);
  859. snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
  860. HDA_AMP_MUTE, mute);
  861. }
  862. static void ad1986a_hp_automute(struct hda_codec *codec)
  863. {
  864. struct ad198x_spec *spec = codec->spec;
  865. spec->jack_present = snd_hda_jack_detect(codec, 0x1a);
  866. if (spec->inv_jack_detect)
  867. spec->jack_present = !spec->jack_present;
  868. ad1986a_update_hp(codec);
  869. }
  870. #define AD1986A_HP_EVENT 0x37
  871. static void ad1986a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  872. {
  873. if ((res >> 26) != AD1986A_HP_EVENT)
  874. return;
  875. ad1986a_hp_automute(codec);
  876. }
  877. static int ad1986a_hp_init(struct hda_codec *codec)
  878. {
  879. ad198x_init(codec);
  880. ad1986a_hp_automute(codec);
  881. return 0;
  882. }
  883. /* bind hp and internal speaker mute (with plug check) */
  884. static int ad1986a_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  885. struct snd_ctl_elem_value *ucontrol)
  886. {
  887. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  888. long *valp = ucontrol->value.integer.value;
  889. int change;
  890. change = snd_hda_codec_amp_update(codec, 0x1a, 0, HDA_OUTPUT, 0,
  891. HDA_AMP_MUTE,
  892. valp[0] ? 0 : HDA_AMP_MUTE);
  893. change |= snd_hda_codec_amp_update(codec, 0x1a, 1, HDA_OUTPUT, 0,
  894. HDA_AMP_MUTE,
  895. valp[1] ? 0 : HDA_AMP_MUTE);
  896. if (change)
  897. ad1986a_update_hp(codec);
  898. return change;
  899. }
  900. static const struct snd_kcontrol_new ad1986a_automute_master_mixers[] = {
  901. HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
  902. {
  903. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  904. .name = "Master Playback Switch",
  905. .subdevice = HDA_SUBDEV_AMP_FLAG,
  906. .info = snd_hda_mixer_amp_switch_info,
  907. .get = snd_hda_mixer_amp_switch_get,
  908. .put = ad1986a_hp_master_sw_put,
  909. .private_value = HDA_COMPOSE_AMP_VAL(0x1a, 3, 0, HDA_OUTPUT),
  910. },
  911. { } /* end */
  912. };
  913. /*
  914. * initialization verbs
  915. */
  916. static const struct hda_verb ad1986a_init_verbs[] = {
  917. /* Front, Surround, CLFE DAC; mute as default */
  918. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  919. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  920. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  921. /* Downmix - off */
  922. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  923. /* HP, Line-Out, Surround, CLFE selectors */
  924. {0x0a, AC_VERB_SET_CONNECT_SEL, 0x0},
  925. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0},
  926. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  927. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  928. /* Mono selector */
  929. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x0},
  930. /* Mic selector: Mic 1/2 pin */
  931. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  932. /* Line-in selector: Line-in */
  933. {0x10, AC_VERB_SET_CONNECT_SEL, 0x0},
  934. /* Mic 1/2 swap */
  935. {0x11, AC_VERB_SET_CONNECT_SEL, 0x0},
  936. /* Record selector: mic */
  937. {0x12, AC_VERB_SET_CONNECT_SEL, 0x0},
  938. /* Mic, Phone, CD, Aux, Line-In amp; mute as default */
  939. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  940. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  941. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  942. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  943. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  944. /* PC beep */
  945. {0x18, AC_VERB_SET_CONNECT_SEL, 0x0},
  946. /* HP, Line-Out, Surround, CLFE, Mono pins; mute as default */
  947. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  948. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  949. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  950. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  951. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  952. /* HP Pin */
  953. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  954. /* Front, Surround, CLFE Pins */
  955. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  956. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  957. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  958. /* Mono Pin */
  959. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  960. /* Mic Pin */
  961. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  962. /* Line, Aux, CD, Beep-In Pin */
  963. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  964. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  965. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  966. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  967. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  968. { } /* end */
  969. };
  970. static const struct hda_verb ad1986a_ch2_init[] = {
  971. /* Surround out -> Line In */
  972. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  973. /* Line-in selectors */
  974. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x1 },
  975. /* CLFE -> Mic in */
  976. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  977. /* Mic selector, mix C/LFE (backmic) and Mic (frontmic) */
  978. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  979. { } /* end */
  980. };
  981. static const struct hda_verb ad1986a_ch4_init[] = {
  982. /* Surround out -> Surround */
  983. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  984. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  985. /* CLFE -> Mic in */
  986. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  987. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x4 },
  988. { } /* end */
  989. };
  990. static const struct hda_verb ad1986a_ch6_init[] = {
  991. /* Surround out -> Surround out */
  992. { 0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  993. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  994. /* CLFE -> CLFE */
  995. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  996. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x0 },
  997. { } /* end */
  998. };
  999. static const struct hda_channel_mode ad1986a_modes[3] = {
  1000. { 2, ad1986a_ch2_init },
  1001. { 4, ad1986a_ch4_init },
  1002. { 6, ad1986a_ch6_init },
  1003. };
  1004. /* eapd initialization */
  1005. static const struct hda_verb ad1986a_eapd_init_verbs[] = {
  1006. {0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  1007. {}
  1008. };
  1009. static const struct hda_verb ad1986a_automic_verbs[] = {
  1010. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1011. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1012. /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
  1013. {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
  1014. {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
  1015. {}
  1016. };
  1017. /* Ultra initialization */
  1018. static const struct hda_verb ad1986a_ultra_init[] = {
  1019. /* eapd initialization */
  1020. { 0x1b, AC_VERB_SET_EAPD_BTLENABLE, 0x00 },
  1021. /* CLFE -> Mic in */
  1022. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x2 },
  1023. { 0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1024. { 0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
  1025. { } /* end */
  1026. };
  1027. /* pin sensing on HP jack */
  1028. static const struct hda_verb ad1986a_hp_init_verbs[] = {
  1029. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_HP_EVENT},
  1030. {}
  1031. };
  1032. static void ad1986a_samsung_p50_unsol_event(struct hda_codec *codec,
  1033. unsigned int res)
  1034. {
  1035. switch (res >> 26) {
  1036. case AD1986A_HP_EVENT:
  1037. ad1986a_hp_automute(codec);
  1038. break;
  1039. case AD1986A_MIC_EVENT:
  1040. ad1986a_automic(codec);
  1041. break;
  1042. }
  1043. }
  1044. static int ad1986a_samsung_p50_init(struct hda_codec *codec)
  1045. {
  1046. ad198x_init(codec);
  1047. ad1986a_hp_automute(codec);
  1048. ad1986a_automic(codec);
  1049. return 0;
  1050. }
  1051. /* models */
  1052. enum {
  1053. AD1986A_6STACK,
  1054. AD1986A_3STACK,
  1055. AD1986A_LAPTOP,
  1056. AD1986A_LAPTOP_EAPD,
  1057. AD1986A_LAPTOP_AUTOMUTE,
  1058. AD1986A_ULTRA,
  1059. AD1986A_SAMSUNG,
  1060. AD1986A_SAMSUNG_P50,
  1061. AD1986A_MODELS
  1062. };
  1063. static const char * const ad1986a_models[AD1986A_MODELS] = {
  1064. [AD1986A_6STACK] = "6stack",
  1065. [AD1986A_3STACK] = "3stack",
  1066. [AD1986A_LAPTOP] = "laptop",
  1067. [AD1986A_LAPTOP_EAPD] = "laptop-eapd",
  1068. [AD1986A_LAPTOP_AUTOMUTE] = "laptop-automute",
  1069. [AD1986A_ULTRA] = "ultra",
  1070. [AD1986A_SAMSUNG] = "samsung",
  1071. [AD1986A_SAMSUNG_P50] = "samsung-p50",
  1072. };
  1073. static const struct snd_pci_quirk ad1986a_cfg_tbl[] = {
  1074. SND_PCI_QUIRK(0x103c, 0x30af, "HP B2800", AD1986A_LAPTOP_EAPD),
  1075. SND_PCI_QUIRK(0x1043, 0x1153, "ASUS M9", AD1986A_LAPTOP_EAPD),
  1076. SND_PCI_QUIRK(0x1043, 0x11f7, "ASUS U5A", AD1986A_LAPTOP_EAPD),
  1077. SND_PCI_QUIRK(0x1043, 0x1213, "ASUS A6J", AD1986A_LAPTOP_EAPD),
  1078. SND_PCI_QUIRK(0x1043, 0x1263, "ASUS U5F", AD1986A_LAPTOP_EAPD),
  1079. SND_PCI_QUIRK(0x1043, 0x1297, "ASUS Z62F", AD1986A_LAPTOP_EAPD),
  1080. SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS V1j", AD1986A_LAPTOP_EAPD),
  1081. SND_PCI_QUIRK(0x1043, 0x1302, "ASUS W3j", AD1986A_LAPTOP_EAPD),
  1082. SND_PCI_QUIRK(0x1043, 0x1443, "ASUS VX1", AD1986A_LAPTOP),
  1083. SND_PCI_QUIRK(0x1043, 0x1447, "ASUS A8J", AD1986A_3STACK),
  1084. SND_PCI_QUIRK(0x1043, 0x817f, "ASUS P5", AD1986A_3STACK),
  1085. SND_PCI_QUIRK(0x1043, 0x818f, "ASUS P5", AD1986A_LAPTOP),
  1086. SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS P5", AD1986A_3STACK),
  1087. SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS M2N", AD1986A_3STACK),
  1088. SND_PCI_QUIRK(0x1043, 0x8234, "ASUS M2N", AD1986A_3STACK),
  1089. SND_PCI_QUIRK(0x10de, 0xcb84, "ASUS A8N-VM", AD1986A_3STACK),
  1090. SND_PCI_QUIRK(0x1179, 0xff40, "Toshiba Satellite L40-10Q", AD1986A_3STACK),
  1091. SND_PCI_QUIRK(0x144d, 0xb03c, "Samsung R55", AD1986A_3STACK),
  1092. SND_PCI_QUIRK(0x144d, 0xc01e, "FSC V2060", AD1986A_LAPTOP),
  1093. SND_PCI_QUIRK(0x144d, 0xc024, "Samsung P50", AD1986A_SAMSUNG_P50),
  1094. SND_PCI_QUIRK(0x144d, 0xc027, "Samsung Q1", AD1986A_ULTRA),
  1095. SND_PCI_QUIRK_MASK(0x144d, 0xff00, 0xc000, "Samsung", AD1986A_SAMSUNG),
  1096. SND_PCI_QUIRK(0x144d, 0xc504, "Samsung Q35", AD1986A_3STACK),
  1097. SND_PCI_QUIRK(0x17aa, 0x1011, "Lenovo M55", AD1986A_LAPTOP),
  1098. SND_PCI_QUIRK(0x17aa, 0x1017, "Lenovo A60", AD1986A_3STACK),
  1099. SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo N100", AD1986A_LAPTOP_AUTOMUTE),
  1100. SND_PCI_QUIRK(0x17c0, 0x2017, "Samsung M50", AD1986A_LAPTOP),
  1101. {}
  1102. };
  1103. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1104. static const struct hda_amp_list ad1986a_loopbacks[] = {
  1105. { 0x13, HDA_OUTPUT, 0 }, /* Mic */
  1106. { 0x14, HDA_OUTPUT, 0 }, /* Phone */
  1107. { 0x15, HDA_OUTPUT, 0 }, /* CD */
  1108. { 0x16, HDA_OUTPUT, 0 }, /* Aux */
  1109. { 0x17, HDA_OUTPUT, 0 }, /* Line */
  1110. { } /* end */
  1111. };
  1112. #endif
  1113. static int is_jack_available(struct hda_codec *codec, hda_nid_t nid)
  1114. {
  1115. unsigned int conf = snd_hda_codec_get_pincfg(codec, nid);
  1116. return get_defcfg_connect(conf) != AC_JACK_PORT_NONE;
  1117. }
  1118. static int patch_ad1986a(struct hda_codec *codec)
  1119. {
  1120. struct ad198x_spec *spec;
  1121. int err, board_config;
  1122. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1123. if (spec == NULL)
  1124. return -ENOMEM;
  1125. codec->spec = spec;
  1126. err = snd_hda_attach_beep_device(codec, 0x19);
  1127. if (err < 0) {
  1128. ad198x_free(codec);
  1129. return err;
  1130. }
  1131. set_beep_amp(spec, 0x18, 0, HDA_OUTPUT);
  1132. spec->multiout.max_channels = 6;
  1133. spec->multiout.num_dacs = ARRAY_SIZE(ad1986a_dac_nids);
  1134. spec->multiout.dac_nids = ad1986a_dac_nids;
  1135. spec->multiout.dig_out_nid = AD1986A_SPDIF_OUT;
  1136. spec->num_adc_nids = 1;
  1137. spec->adc_nids = ad1986a_adc_nids;
  1138. spec->capsrc_nids = ad1986a_capsrc_nids;
  1139. spec->input_mux = &ad1986a_capture_source;
  1140. spec->num_mixers = 1;
  1141. spec->mixers[0] = ad1986a_mixers;
  1142. spec->num_init_verbs = 1;
  1143. spec->init_verbs[0] = ad1986a_init_verbs;
  1144. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1145. spec->loopback.amplist = ad1986a_loopbacks;
  1146. #endif
  1147. spec->vmaster_nid = 0x1b;
  1148. spec->inv_eapd = 1; /* AD1986A has the inverted EAPD implementation */
  1149. codec->patch_ops = ad198x_patch_ops;
  1150. /* override some parameters */
  1151. board_config = snd_hda_check_board_config(codec, AD1986A_MODELS,
  1152. ad1986a_models,
  1153. ad1986a_cfg_tbl);
  1154. switch (board_config) {
  1155. case AD1986A_3STACK:
  1156. spec->num_mixers = 2;
  1157. spec->mixers[1] = ad1986a_3st_mixers;
  1158. spec->num_init_verbs = 2;
  1159. spec->init_verbs[1] = ad1986a_ch2_init;
  1160. spec->channel_mode = ad1986a_modes;
  1161. spec->num_channel_mode = ARRAY_SIZE(ad1986a_modes);
  1162. spec->need_dac_fix = 1;
  1163. spec->multiout.max_channels = 2;
  1164. spec->multiout.num_dacs = 1;
  1165. break;
  1166. case AD1986A_LAPTOP:
  1167. spec->mixers[0] = ad1986a_laptop_mixers;
  1168. spec->multiout.max_channels = 2;
  1169. spec->multiout.num_dacs = 1;
  1170. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1171. break;
  1172. case AD1986A_LAPTOP_EAPD:
  1173. spec->num_mixers = 3;
  1174. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1175. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1176. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1177. spec->num_init_verbs = 2;
  1178. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1179. spec->multiout.max_channels = 2;
  1180. spec->multiout.num_dacs = 1;
  1181. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1182. if (!is_jack_available(codec, 0x25))
  1183. spec->multiout.dig_out_nid = 0;
  1184. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1185. break;
  1186. case AD1986A_SAMSUNG:
  1187. spec->num_mixers = 2;
  1188. spec->mixers[0] = ad1986a_laptop_master_mixers;
  1189. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1190. spec->num_init_verbs = 3;
  1191. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1192. spec->init_verbs[2] = ad1986a_automic_verbs;
  1193. spec->multiout.max_channels = 2;
  1194. spec->multiout.num_dacs = 1;
  1195. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1196. if (!is_jack_available(codec, 0x25))
  1197. spec->multiout.dig_out_nid = 0;
  1198. spec->input_mux = &ad1986a_automic_capture_source;
  1199. codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
  1200. codec->patch_ops.init = ad1986a_automic_init;
  1201. break;
  1202. case AD1986A_SAMSUNG_P50:
  1203. spec->num_mixers = 2;
  1204. spec->mixers[0] = ad1986a_automute_master_mixers;
  1205. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1206. spec->num_init_verbs = 4;
  1207. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1208. spec->init_verbs[2] = ad1986a_automic_verbs;
  1209. spec->init_verbs[3] = ad1986a_hp_init_verbs;
  1210. spec->multiout.max_channels = 2;
  1211. spec->multiout.num_dacs = 1;
  1212. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1213. if (!is_jack_available(codec, 0x25))
  1214. spec->multiout.dig_out_nid = 0;
  1215. spec->input_mux = &ad1986a_automic_capture_source;
  1216. codec->patch_ops.unsol_event = ad1986a_samsung_p50_unsol_event;
  1217. codec->patch_ops.init = ad1986a_samsung_p50_init;
  1218. break;
  1219. case AD1986A_LAPTOP_AUTOMUTE:
  1220. spec->num_mixers = 3;
  1221. spec->mixers[0] = ad1986a_automute_master_mixers;
  1222. spec->mixers[1] = ad1986a_laptop_eapd_mixers;
  1223. spec->mixers[2] = ad1986a_laptop_intmic_mixers;
  1224. spec->num_init_verbs = 3;
  1225. spec->init_verbs[1] = ad1986a_eapd_init_verbs;
  1226. spec->init_verbs[2] = ad1986a_hp_init_verbs;
  1227. spec->multiout.max_channels = 2;
  1228. spec->multiout.num_dacs = 1;
  1229. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1230. if (!is_jack_available(codec, 0x25))
  1231. spec->multiout.dig_out_nid = 0;
  1232. spec->input_mux = &ad1986a_laptop_eapd_capture_source;
  1233. codec->patch_ops.unsol_event = ad1986a_hp_unsol_event;
  1234. codec->patch_ops.init = ad1986a_hp_init;
  1235. /* Lenovo N100 seems to report the reversed bit
  1236. * for HP jack-sensing
  1237. */
  1238. spec->inv_jack_detect = 1;
  1239. break;
  1240. case AD1986A_ULTRA:
  1241. spec->mixers[0] = ad1986a_laptop_eapd_mixers;
  1242. spec->num_init_verbs = 2;
  1243. spec->init_verbs[1] = ad1986a_ultra_init;
  1244. spec->multiout.max_channels = 2;
  1245. spec->multiout.num_dacs = 1;
  1246. spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
  1247. spec->multiout.dig_out_nid = 0;
  1248. break;
  1249. }
  1250. /* AD1986A has a hardware problem that it can't share a stream
  1251. * with multiple output pins. The copy of front to surrounds
  1252. * causes noisy or silent outputs at a certain timing, e.g.
  1253. * changing the volume.
  1254. * So, let's disable the shared stream.
  1255. */
  1256. spec->multiout.no_share_stream = 1;
  1257. codec->no_trigger_sense = 1;
  1258. codec->no_sticky_stream = 1;
  1259. return 0;
  1260. }
  1261. /*
  1262. * AD1983 specific
  1263. */
  1264. #define AD1983_SPDIF_OUT 0x02
  1265. #define AD1983_DAC 0x03
  1266. #define AD1983_ADC 0x04
  1267. static const hda_nid_t ad1983_dac_nids[1] = { AD1983_DAC };
  1268. static const hda_nid_t ad1983_adc_nids[1] = { AD1983_ADC };
  1269. static const hda_nid_t ad1983_capsrc_nids[1] = { 0x15 };
  1270. static const struct hda_input_mux ad1983_capture_source = {
  1271. .num_items = 4,
  1272. .items = {
  1273. { "Mic", 0x0 },
  1274. { "Line", 0x1 },
  1275. { "Mix", 0x2 },
  1276. { "Mix Mono", 0x3 },
  1277. },
  1278. };
  1279. /*
  1280. * SPDIF playback route
  1281. */
  1282. static int ad1983_spdif_route_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1283. {
  1284. static const char * const texts[] = { "PCM", "ADC" };
  1285. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1286. uinfo->count = 1;
  1287. uinfo->value.enumerated.items = 2;
  1288. if (uinfo->value.enumerated.item > 1)
  1289. uinfo->value.enumerated.item = 1;
  1290. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1291. return 0;
  1292. }
  1293. static int ad1983_spdif_route_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1294. {
  1295. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1296. struct ad198x_spec *spec = codec->spec;
  1297. ucontrol->value.enumerated.item[0] = spec->spdif_route;
  1298. return 0;
  1299. }
  1300. static int ad1983_spdif_route_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1301. {
  1302. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1303. struct ad198x_spec *spec = codec->spec;
  1304. if (ucontrol->value.enumerated.item[0] > 1)
  1305. return -EINVAL;
  1306. if (spec->spdif_route != ucontrol->value.enumerated.item[0]) {
  1307. spec->spdif_route = ucontrol->value.enumerated.item[0];
  1308. snd_hda_codec_write_cache(codec, spec->multiout.dig_out_nid, 0,
  1309. AC_VERB_SET_CONNECT_SEL,
  1310. spec->spdif_route);
  1311. return 1;
  1312. }
  1313. return 0;
  1314. }
  1315. static const struct snd_kcontrol_new ad1983_mixers[] = {
  1316. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1317. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1318. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1319. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  1320. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  1321. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  1322. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1323. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1324. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1325. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1326. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1327. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1328. HDA_CODEC_VOLUME("Mic Boost Volume", 0x0c, 0x0, HDA_OUTPUT),
  1329. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1330. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1331. {
  1332. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1333. .name = "Capture Source",
  1334. .info = ad198x_mux_enum_info,
  1335. .get = ad198x_mux_enum_get,
  1336. .put = ad198x_mux_enum_put,
  1337. },
  1338. {
  1339. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1340. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1341. .info = ad1983_spdif_route_info,
  1342. .get = ad1983_spdif_route_get,
  1343. .put = ad1983_spdif_route_put,
  1344. },
  1345. { } /* end */
  1346. };
  1347. static const struct hda_verb ad1983_init_verbs[] = {
  1348. /* Front, HP, Mono; mute as default */
  1349. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1350. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1351. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1352. /* Beep, PCM, Mic, Line-In: mute */
  1353. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1354. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1355. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1356. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1357. /* Front, HP selectors; from Mix */
  1358. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  1359. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  1360. /* Mono selector; from Mix */
  1361. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  1362. /* Mic selector; Mic */
  1363. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1364. /* Line-in selector: Line-in */
  1365. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  1366. /* Mic boost: 0dB */
  1367. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1368. /* Record selector: mic */
  1369. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  1370. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1371. /* SPDIF route: PCM */
  1372. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  1373. /* Front Pin */
  1374. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1375. /* HP Pin */
  1376. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  1377. /* Mono Pin */
  1378. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1379. /* Mic Pin */
  1380. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1381. /* Line Pin */
  1382. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  1383. { } /* end */
  1384. };
  1385. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1386. static const struct hda_amp_list ad1983_loopbacks[] = {
  1387. { 0x12, HDA_OUTPUT, 0 }, /* Mic */
  1388. { 0x13, HDA_OUTPUT, 0 }, /* Line */
  1389. { } /* end */
  1390. };
  1391. #endif
  1392. static int patch_ad1983(struct hda_codec *codec)
  1393. {
  1394. struct ad198x_spec *spec;
  1395. int err;
  1396. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1397. if (spec == NULL)
  1398. return -ENOMEM;
  1399. codec->spec = spec;
  1400. err = snd_hda_attach_beep_device(codec, 0x10);
  1401. if (err < 0) {
  1402. ad198x_free(codec);
  1403. return err;
  1404. }
  1405. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  1406. spec->multiout.max_channels = 2;
  1407. spec->multiout.num_dacs = ARRAY_SIZE(ad1983_dac_nids);
  1408. spec->multiout.dac_nids = ad1983_dac_nids;
  1409. spec->multiout.dig_out_nid = AD1983_SPDIF_OUT;
  1410. spec->num_adc_nids = 1;
  1411. spec->adc_nids = ad1983_adc_nids;
  1412. spec->capsrc_nids = ad1983_capsrc_nids;
  1413. spec->input_mux = &ad1983_capture_source;
  1414. spec->num_mixers = 1;
  1415. spec->mixers[0] = ad1983_mixers;
  1416. spec->num_init_verbs = 1;
  1417. spec->init_verbs[0] = ad1983_init_verbs;
  1418. spec->spdif_route = 0;
  1419. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1420. spec->loopback.amplist = ad1983_loopbacks;
  1421. #endif
  1422. spec->vmaster_nid = 0x05;
  1423. codec->patch_ops = ad198x_patch_ops;
  1424. codec->no_trigger_sense = 1;
  1425. codec->no_sticky_stream = 1;
  1426. return 0;
  1427. }
  1428. /*
  1429. * AD1981 HD specific
  1430. */
  1431. #define AD1981_SPDIF_OUT 0x02
  1432. #define AD1981_DAC 0x03
  1433. #define AD1981_ADC 0x04
  1434. static const hda_nid_t ad1981_dac_nids[1] = { AD1981_DAC };
  1435. static const hda_nid_t ad1981_adc_nids[1] = { AD1981_ADC };
  1436. static const hda_nid_t ad1981_capsrc_nids[1] = { 0x15 };
  1437. /* 0x0c, 0x09, 0x0e, 0x0f, 0x19, 0x05, 0x18, 0x17 */
  1438. static const struct hda_input_mux ad1981_capture_source = {
  1439. .num_items = 7,
  1440. .items = {
  1441. { "Front Mic", 0x0 },
  1442. { "Line", 0x1 },
  1443. { "Mix", 0x2 },
  1444. { "Mix Mono", 0x3 },
  1445. { "CD", 0x4 },
  1446. { "Mic", 0x6 },
  1447. { "Aux", 0x7 },
  1448. },
  1449. };
  1450. static const struct snd_kcontrol_new ad1981_mixers[] = {
  1451. HDA_CODEC_VOLUME("Front Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1452. HDA_CODEC_MUTE("Front Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1453. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  1454. HDA_CODEC_MUTE("Headphone Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  1455. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x07, 1, 0x0, HDA_OUTPUT),
  1456. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x07, 1, 0x0, HDA_OUTPUT),
  1457. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1458. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1459. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1460. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1461. HDA_CODEC_VOLUME("Line Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1462. HDA_CODEC_MUTE("Line Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1463. HDA_CODEC_VOLUME("Aux Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  1464. HDA_CODEC_MUTE("Aux Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  1465. HDA_CODEC_VOLUME("Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1466. HDA_CODEC_MUTE("Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1467. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1468. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1469. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  1470. HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
  1471. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1472. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1473. {
  1474. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1475. .name = "Capture Source",
  1476. .info = ad198x_mux_enum_info,
  1477. .get = ad198x_mux_enum_get,
  1478. .put = ad198x_mux_enum_put,
  1479. },
  1480. /* identical with AD1983 */
  1481. {
  1482. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1483. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1484. .info = ad1983_spdif_route_info,
  1485. .get = ad1983_spdif_route_get,
  1486. .put = ad1983_spdif_route_put,
  1487. },
  1488. { } /* end */
  1489. };
  1490. static const struct hda_verb ad1981_init_verbs[] = {
  1491. /* Front, HP, Mono; mute as default */
  1492. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1493. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1494. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1495. /* Beep, PCM, Front Mic, Line, Rear Mic, Aux, CD-In: mute */
  1496. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1497. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1498. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1499. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1500. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1501. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1502. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1503. /* Front, HP selectors; from Mix */
  1504. {0x05, AC_VERB_SET_CONNECT_SEL, 0x01},
  1505. {0x06, AC_VERB_SET_CONNECT_SEL, 0x01},
  1506. /* Mono selector; from Mix */
  1507. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x03},
  1508. /* Mic Mixer; select Front Mic */
  1509. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1510. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1511. /* Mic boost: 0dB */
  1512. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1513. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1514. /* Record selector: Front mic */
  1515. {0x15, AC_VERB_SET_CONNECT_SEL, 0x0},
  1516. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1517. /* SPDIF route: PCM */
  1518. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0},
  1519. /* Front Pin */
  1520. {0x05, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1521. /* HP Pin */
  1522. {0x06, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  1523. /* Mono Pin */
  1524. {0x07, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  1525. /* Front & Rear Mic Pins */
  1526. {0x08, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1527. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  1528. /* Line Pin */
  1529. {0x09, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  1530. /* Digital Beep */
  1531. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
  1532. /* Line-Out as Input: disabled */
  1533. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1534. { } /* end */
  1535. };
  1536. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1537. static const struct hda_amp_list ad1981_loopbacks[] = {
  1538. { 0x12, HDA_OUTPUT, 0 }, /* Front Mic */
  1539. { 0x13, HDA_OUTPUT, 0 }, /* Line */
  1540. { 0x1b, HDA_OUTPUT, 0 }, /* Aux */
  1541. { 0x1c, HDA_OUTPUT, 0 }, /* Mic */
  1542. { 0x1d, HDA_OUTPUT, 0 }, /* CD */
  1543. { } /* end */
  1544. };
  1545. #endif
  1546. /*
  1547. * Patch for HP nx6320
  1548. *
  1549. * nx6320 uses EAPD in the reverse way - EAPD-on means the internal
  1550. * speaker output enabled _and_ mute-LED off.
  1551. */
  1552. #define AD1981_HP_EVENT 0x37
  1553. #define AD1981_MIC_EVENT 0x38
  1554. static const struct hda_verb ad1981_hp_init_verbs[] = {
  1555. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x00 }, /* default off */
  1556. /* pin sensing on HP and Mic jacks */
  1557. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1558. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1559. {}
  1560. };
  1561. /* turn on/off EAPD (+ mute HP) as a master switch */
  1562. static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1563. struct snd_ctl_elem_value *ucontrol)
  1564. {
  1565. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1566. struct ad198x_spec *spec = codec->spec;
  1567. if (! ad198x_eapd_put(kcontrol, ucontrol))
  1568. return 0;
  1569. /* change speaker pin appropriately */
  1570. snd_hda_codec_write(codec, 0x05, 0,
  1571. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1572. spec->cur_eapd ? PIN_OUT : 0);
  1573. /* toggle HP mute appropriately */
  1574. snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
  1575. HDA_AMP_MUTE,
  1576. spec->cur_eapd ? 0 : HDA_AMP_MUTE);
  1577. return 1;
  1578. }
  1579. /* bind volumes of both NID 0x05 and 0x06 */
  1580. static const struct hda_bind_ctls ad1981_hp_bind_master_vol = {
  1581. .ops = &snd_hda_bind_vol,
  1582. .values = {
  1583. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  1584. HDA_COMPOSE_AMP_VAL(0x06, 3, 0, HDA_OUTPUT),
  1585. 0
  1586. },
  1587. };
  1588. /* mute internal speaker if HP is plugged */
  1589. static void ad1981_hp_automute(struct hda_codec *codec)
  1590. {
  1591. unsigned int present;
  1592. present = snd_hda_jack_detect(codec, 0x06);
  1593. snd_hda_codec_amp_stereo(codec, 0x05, HDA_OUTPUT, 0,
  1594. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  1595. }
  1596. /* toggle input of built-in and mic jack appropriately */
  1597. static void ad1981_hp_automic(struct hda_codec *codec)
  1598. {
  1599. static const struct hda_verb mic_jack_on[] = {
  1600. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1601. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1602. {}
  1603. };
  1604. static const struct hda_verb mic_jack_off[] = {
  1605. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  1606. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  1607. {}
  1608. };
  1609. unsigned int present;
  1610. present = snd_hda_jack_detect(codec, 0x08);
  1611. if (present)
  1612. snd_hda_sequence_write(codec, mic_jack_on);
  1613. else
  1614. snd_hda_sequence_write(codec, mic_jack_off);
  1615. }
  1616. /* unsolicited event for HP jack sensing */
  1617. static void ad1981_hp_unsol_event(struct hda_codec *codec,
  1618. unsigned int res)
  1619. {
  1620. res >>= 26;
  1621. switch (res) {
  1622. case AD1981_HP_EVENT:
  1623. ad1981_hp_automute(codec);
  1624. break;
  1625. case AD1981_MIC_EVENT:
  1626. ad1981_hp_automic(codec);
  1627. break;
  1628. }
  1629. }
  1630. static const struct hda_input_mux ad1981_hp_capture_source = {
  1631. .num_items = 3,
  1632. .items = {
  1633. { "Mic", 0x0 },
  1634. { "Docking-Station", 0x1 },
  1635. { "Mix", 0x2 },
  1636. },
  1637. };
  1638. static const struct snd_kcontrol_new ad1981_hp_mixers[] = {
  1639. HDA_BIND_VOL("Master Playback Volume", &ad1981_hp_bind_master_vol),
  1640. {
  1641. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1642. .subdevice = HDA_SUBDEV_NID_FLAG | 0x05,
  1643. .name = "Master Playback Switch",
  1644. .info = ad198x_eapd_info,
  1645. .get = ad198x_eapd_get,
  1646. .put = ad1981_hp_master_sw_put,
  1647. .private_value = 0x05,
  1648. },
  1649. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1650. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1651. #if 0
  1652. /* FIXME: analog mic/line loopback doesn't work with my tests...
  1653. * (although recording is OK)
  1654. */
  1655. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1656. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1657. HDA_CODEC_VOLUME("Docking-Station Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1658. HDA_CODEC_MUTE("Docking-Station Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1659. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x1c, 0x0, HDA_OUTPUT),
  1660. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x1c, 0x0, HDA_OUTPUT),
  1661. /* FIXME: does this laptop have analog CD connection? */
  1662. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1663. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1664. #endif
  1665. HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  1666. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x18, 0x0, HDA_INPUT),
  1667. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1668. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1669. {
  1670. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1671. .name = "Capture Source",
  1672. .info = ad198x_mux_enum_info,
  1673. .get = ad198x_mux_enum_get,
  1674. .put = ad198x_mux_enum_put,
  1675. },
  1676. { } /* end */
  1677. };
  1678. /* initialize jack-sensing, too */
  1679. static int ad1981_hp_init(struct hda_codec *codec)
  1680. {
  1681. ad198x_init(codec);
  1682. ad1981_hp_automute(codec);
  1683. ad1981_hp_automic(codec);
  1684. return 0;
  1685. }
  1686. /* configuration for Toshiba Laptops */
  1687. static const struct hda_verb ad1981_toshiba_init_verbs[] = {
  1688. {0x05, AC_VERB_SET_EAPD_BTLENABLE, 0x01 }, /* default on */
  1689. /* pin sensing on HP and Mic jacks */
  1690. {0x06, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_HP_EVENT},
  1691. {0x08, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1981_MIC_EVENT},
  1692. {}
  1693. };
  1694. static const struct snd_kcontrol_new ad1981_toshiba_mixers[] = {
  1695. HDA_CODEC_VOLUME("Amp Volume", 0x1a, 0x0, HDA_OUTPUT),
  1696. HDA_CODEC_MUTE("Amp Switch", 0x1a, 0x0, HDA_OUTPUT),
  1697. { }
  1698. };
  1699. /* configuration for Lenovo Thinkpad T60 */
  1700. static const struct snd_kcontrol_new ad1981_thinkpad_mixers[] = {
  1701. HDA_CODEC_VOLUME("Master Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  1702. HDA_CODEC_MUTE("Master Playback Switch", 0x05, 0x0, HDA_OUTPUT),
  1703. HDA_CODEC_VOLUME("PCM Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  1704. HDA_CODEC_MUTE("PCM Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  1705. HDA_CODEC_VOLUME("Mic Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  1706. HDA_CODEC_MUTE("Mic Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  1707. HDA_CODEC_VOLUME("CD Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1708. HDA_CODEC_MUTE("CD Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1709. HDA_CODEC_VOLUME("Mic Boost Volume", 0x08, 0x0, HDA_INPUT),
  1710. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  1711. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_OUTPUT),
  1712. {
  1713. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1714. .name = "Capture Source",
  1715. .info = ad198x_mux_enum_info,
  1716. .get = ad198x_mux_enum_get,
  1717. .put = ad198x_mux_enum_put,
  1718. },
  1719. /* identical with AD1983 */
  1720. {
  1721. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1722. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  1723. .info = ad1983_spdif_route_info,
  1724. .get = ad1983_spdif_route_get,
  1725. .put = ad1983_spdif_route_put,
  1726. },
  1727. { } /* end */
  1728. };
  1729. static const struct hda_input_mux ad1981_thinkpad_capture_source = {
  1730. .num_items = 3,
  1731. .items = {
  1732. { "Mic", 0x0 },
  1733. { "Mix", 0x2 },
  1734. { "CD", 0x4 },
  1735. },
  1736. };
  1737. /* models */
  1738. enum {
  1739. AD1981_BASIC,
  1740. AD1981_HP,
  1741. AD1981_THINKPAD,
  1742. AD1981_TOSHIBA,
  1743. AD1981_MODELS
  1744. };
  1745. static const char * const ad1981_models[AD1981_MODELS] = {
  1746. [AD1981_HP] = "hp",
  1747. [AD1981_THINKPAD] = "thinkpad",
  1748. [AD1981_BASIC] = "basic",
  1749. [AD1981_TOSHIBA] = "toshiba"
  1750. };
  1751. static const struct snd_pci_quirk ad1981_cfg_tbl[] = {
  1752. SND_PCI_QUIRK(0x1014, 0x0597, "Lenovo Z60", AD1981_THINKPAD),
  1753. SND_PCI_QUIRK(0x1014, 0x05b7, "Lenovo Z60m", AD1981_THINKPAD),
  1754. /* All HP models */
  1755. SND_PCI_QUIRK_VENDOR(0x103c, "HP nx", AD1981_HP),
  1756. SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba U205", AD1981_TOSHIBA),
  1757. /* Lenovo Thinkpad T60/X60/Z6xx */
  1758. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1981_THINKPAD),
  1759. /* HP nx6320 (reversed SSID, H/W bug) */
  1760. SND_PCI_QUIRK(0x30b0, 0x103c, "HP nx6320", AD1981_HP),
  1761. {}
  1762. };
  1763. static int patch_ad1981(struct hda_codec *codec)
  1764. {
  1765. struct ad198x_spec *spec;
  1766. int err, board_config;
  1767. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1768. if (spec == NULL)
  1769. return -ENOMEM;
  1770. codec->spec = spec;
  1771. err = snd_hda_attach_beep_device(codec, 0x10);
  1772. if (err < 0) {
  1773. ad198x_free(codec);
  1774. return err;
  1775. }
  1776. set_beep_amp(spec, 0x0d, 0, HDA_OUTPUT);
  1777. spec->multiout.max_channels = 2;
  1778. spec->multiout.num_dacs = ARRAY_SIZE(ad1981_dac_nids);
  1779. spec->multiout.dac_nids = ad1981_dac_nids;
  1780. spec->multiout.dig_out_nid = AD1981_SPDIF_OUT;
  1781. spec->num_adc_nids = 1;
  1782. spec->adc_nids = ad1981_adc_nids;
  1783. spec->capsrc_nids = ad1981_capsrc_nids;
  1784. spec->input_mux = &ad1981_capture_source;
  1785. spec->num_mixers = 1;
  1786. spec->mixers[0] = ad1981_mixers;
  1787. spec->num_init_verbs = 1;
  1788. spec->init_verbs[0] = ad1981_init_verbs;
  1789. spec->spdif_route = 0;
  1790. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1791. spec->loopback.amplist = ad1981_loopbacks;
  1792. #endif
  1793. spec->vmaster_nid = 0x05;
  1794. codec->patch_ops = ad198x_patch_ops;
  1795. /* override some parameters */
  1796. board_config = snd_hda_check_board_config(codec, AD1981_MODELS,
  1797. ad1981_models,
  1798. ad1981_cfg_tbl);
  1799. switch (board_config) {
  1800. case AD1981_HP:
  1801. spec->mixers[0] = ad1981_hp_mixers;
  1802. spec->num_init_verbs = 2;
  1803. spec->init_verbs[1] = ad1981_hp_init_verbs;
  1804. if (!is_jack_available(codec, 0x0a))
  1805. spec->multiout.dig_out_nid = 0;
  1806. spec->input_mux = &ad1981_hp_capture_source;
  1807. codec->patch_ops.init = ad1981_hp_init;
  1808. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1809. /* set the upper-limit for mixer amp to 0dB for avoiding the
  1810. * possible damage by overloading
  1811. */
  1812. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  1813. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1814. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1815. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1816. (1 << AC_AMPCAP_MUTE_SHIFT));
  1817. break;
  1818. case AD1981_THINKPAD:
  1819. spec->mixers[0] = ad1981_thinkpad_mixers;
  1820. spec->input_mux = &ad1981_thinkpad_capture_source;
  1821. /* set the upper-limit for mixer amp to 0dB for avoiding the
  1822. * possible damage by overloading
  1823. */
  1824. snd_hda_override_amp_caps(codec, 0x11, HDA_INPUT,
  1825. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1826. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1827. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1828. (1 << AC_AMPCAP_MUTE_SHIFT));
  1829. break;
  1830. case AD1981_TOSHIBA:
  1831. spec->mixers[0] = ad1981_hp_mixers;
  1832. spec->mixers[1] = ad1981_toshiba_mixers;
  1833. spec->num_init_verbs = 2;
  1834. spec->init_verbs[1] = ad1981_toshiba_init_verbs;
  1835. spec->multiout.dig_out_nid = 0;
  1836. spec->input_mux = &ad1981_hp_capture_source;
  1837. codec->patch_ops.init = ad1981_hp_init;
  1838. codec->patch_ops.unsol_event = ad1981_hp_unsol_event;
  1839. break;
  1840. }
  1841. codec->no_trigger_sense = 1;
  1842. codec->no_sticky_stream = 1;
  1843. return 0;
  1844. }
  1845. /*
  1846. * AD1988
  1847. *
  1848. * Output pins and routes
  1849. *
  1850. * Pin Mix Sel DAC (*)
  1851. * port-A 0x11 (mute/hp) <- 0x22 <- 0x37 <- 03/04/06
  1852. * port-B 0x14 (mute/hp) <- 0x2b <- 0x30 <- 03/04/06
  1853. * port-C 0x15 (mute) <- 0x2c <- 0x31 <- 05/0a
  1854. * port-D 0x12 (mute/hp) <- 0x29 <- 04
  1855. * port-E 0x17 (mute/hp) <- 0x26 <- 0x32 <- 05/0a
  1856. * port-F 0x16 (mute) <- 0x2a <- 06
  1857. * port-G 0x24 (mute) <- 0x27 <- 05
  1858. * port-H 0x25 (mute) <- 0x28 <- 0a
  1859. * mono 0x13 (mute/amp)<- 0x1e <- 0x36 <- 03/04/06
  1860. *
  1861. * DAC0 = 03h, DAC1 = 04h, DAC2 = 05h, DAC3 = 06h, DAC4 = 0ah
  1862. * (*) DAC2/3/4 are swapped to DAC3/4/2 on AD198A rev.2 due to a h/w bug.
  1863. *
  1864. * Input pins and routes
  1865. *
  1866. * pin boost mix input # / adc input #
  1867. * port-A 0x11 -> 0x38 -> mix 2, ADC 0
  1868. * port-B 0x14 -> 0x39 -> mix 0, ADC 1
  1869. * port-C 0x15 -> 0x3a -> 33:0 - mix 1, ADC 2
  1870. * port-D 0x12 -> 0x3d -> mix 3, ADC 8
  1871. * port-E 0x17 -> 0x3c -> 34:0 - mix 4, ADC 4
  1872. * port-F 0x16 -> 0x3b -> mix 5, ADC 3
  1873. * port-G 0x24 -> N/A -> 33:1 - mix 1, 34:1 - mix 4, ADC 6
  1874. * port-H 0x25 -> N/A -> 33:2 - mix 1, 34:2 - mix 4, ADC 7
  1875. *
  1876. *
  1877. * DAC assignment
  1878. * 6stack - front/surr/CLFE/side/opt DACs - 04/06/05/0a/03
  1879. * 3stack - front/surr/CLFE/opt DACs - 04/05/0a/03
  1880. *
  1881. * Inputs of Analog Mix (0x20)
  1882. * 0:Port-B (front mic)
  1883. * 1:Port-C/G/H (line-in)
  1884. * 2:Port-A
  1885. * 3:Port-D (line-in/2)
  1886. * 4:Port-E/G/H (mic-in)
  1887. * 5:Port-F (mic2-in)
  1888. * 6:CD
  1889. * 7:Beep
  1890. *
  1891. * ADC selection
  1892. * 0:Port-A
  1893. * 1:Port-B (front mic-in)
  1894. * 2:Port-C (line-in)
  1895. * 3:Port-F (mic2-in)
  1896. * 4:Port-E (mic-in)
  1897. * 5:CD
  1898. * 6:Port-G
  1899. * 7:Port-H
  1900. * 8:Port-D (line-in/2)
  1901. * 9:Mix
  1902. *
  1903. * Proposed pin assignments by the datasheet
  1904. *
  1905. * 6-stack
  1906. * Port-A front headphone
  1907. * B front mic-in
  1908. * C rear line-in
  1909. * D rear front-out
  1910. * E rear mic-in
  1911. * F rear surround
  1912. * G rear CLFE
  1913. * H rear side
  1914. *
  1915. * 3-stack
  1916. * Port-A front headphone
  1917. * B front mic
  1918. * C rear line-in/surround
  1919. * D rear front-out
  1920. * E rear mic-in/CLFE
  1921. *
  1922. * laptop
  1923. * Port-A headphone
  1924. * B mic-in
  1925. * C docking station
  1926. * D internal speaker (with EAPD)
  1927. * E/F quad mic array
  1928. */
  1929. /* models */
  1930. enum {
  1931. AD1988_6STACK,
  1932. AD1988_6STACK_DIG,
  1933. AD1988_3STACK,
  1934. AD1988_3STACK_DIG,
  1935. AD1988_LAPTOP,
  1936. AD1988_LAPTOP_DIG,
  1937. AD1988_AUTO,
  1938. AD1988_MODEL_LAST,
  1939. };
  1940. /* reivision id to check workarounds */
  1941. #define AD1988A_REV2 0x100200
  1942. #define is_rev2(codec) \
  1943. ((codec)->vendor_id == 0x11d41988 && \
  1944. (codec)->revision_id == AD1988A_REV2)
  1945. /*
  1946. * mixers
  1947. */
  1948. static const hda_nid_t ad1988_6stack_dac_nids[4] = {
  1949. 0x04, 0x06, 0x05, 0x0a
  1950. };
  1951. static const hda_nid_t ad1988_3stack_dac_nids[3] = {
  1952. 0x04, 0x05, 0x0a
  1953. };
  1954. /* for AD1988A revision-2, DAC2-4 are swapped */
  1955. static const hda_nid_t ad1988_6stack_dac_nids_rev2[4] = {
  1956. 0x04, 0x05, 0x0a, 0x06
  1957. };
  1958. static const hda_nid_t ad1988_alt_dac_nid[1] = {
  1959. 0x03
  1960. };
  1961. static const hda_nid_t ad1988_3stack_dac_nids_rev2[3] = {
  1962. 0x04, 0x0a, 0x06
  1963. };
  1964. static const hda_nid_t ad1988_adc_nids[3] = {
  1965. 0x08, 0x09, 0x0f
  1966. };
  1967. static const hda_nid_t ad1988_capsrc_nids[3] = {
  1968. 0x0c, 0x0d, 0x0e
  1969. };
  1970. #define AD1988_SPDIF_OUT 0x02
  1971. #define AD1988_SPDIF_OUT_HDMI 0x0b
  1972. #define AD1988_SPDIF_IN 0x07
  1973. static const hda_nid_t ad1989b_slave_dig_outs[] = {
  1974. AD1988_SPDIF_OUT, AD1988_SPDIF_OUT_HDMI, 0
  1975. };
  1976. static const struct hda_input_mux ad1988_6stack_capture_source = {
  1977. .num_items = 5,
  1978. .items = {
  1979. { "Front Mic", 0x1 }, /* port-B */
  1980. { "Line", 0x2 }, /* port-C */
  1981. { "Mic", 0x4 }, /* port-E */
  1982. { "CD", 0x5 },
  1983. { "Mix", 0x9 },
  1984. },
  1985. };
  1986. static const struct hda_input_mux ad1988_laptop_capture_source = {
  1987. .num_items = 3,
  1988. .items = {
  1989. { "Mic/Line", 0x1 }, /* port-B */
  1990. { "CD", 0x5 },
  1991. { "Mix", 0x9 },
  1992. },
  1993. };
  1994. /*
  1995. */
  1996. static int ad198x_ch_mode_info(struct snd_kcontrol *kcontrol,
  1997. struct snd_ctl_elem_info *uinfo)
  1998. {
  1999. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2000. struct ad198x_spec *spec = codec->spec;
  2001. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  2002. spec->num_channel_mode);
  2003. }
  2004. static int ad198x_ch_mode_get(struct snd_kcontrol *kcontrol,
  2005. struct snd_ctl_elem_value *ucontrol)
  2006. {
  2007. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2008. struct ad198x_spec *spec = codec->spec;
  2009. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  2010. spec->num_channel_mode, spec->multiout.max_channels);
  2011. }
  2012. static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
  2013. struct snd_ctl_elem_value *ucontrol)
  2014. {
  2015. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2016. struct ad198x_spec *spec = codec->spec;
  2017. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  2018. spec->num_channel_mode,
  2019. &spec->multiout.max_channels);
  2020. if (err >= 0 && spec->need_dac_fix)
  2021. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  2022. return err;
  2023. }
  2024. static const struct snd_kcontrol_new ad1988_hp_mixers[] = {
  2025. {
  2026. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2027. .name = "Independent HP",
  2028. .info = ad1988_independent_hp_info,
  2029. .get = ad1988_independent_hp_get,
  2030. .put = ad1988_independent_hp_put,
  2031. },
  2032. { } /* end */
  2033. };
  2034. /* 6-stack mode */
  2035. static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
  2036. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2037. HDA_CODEC_VOLUME("Surround Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  2038. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  2039. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  2040. HDA_CODEC_VOLUME("Side Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  2041. { } /* end */
  2042. };
  2043. static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
  2044. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2045. HDA_CODEC_VOLUME("Surround Playback Volume", 0x05, 0x0, HDA_OUTPUT),
  2046. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  2047. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0a, 2, 0x0, HDA_OUTPUT),
  2048. HDA_CODEC_VOLUME("Side Playback Volume", 0x06, 0x0, HDA_OUTPUT),
  2049. { } /* end */
  2050. };
  2051. static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
  2052. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  2053. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  2054. HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
  2055. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
  2056. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x27, 2, 2, HDA_INPUT),
  2057. HDA_BIND_MUTE("Side Playback Switch", 0x28, 2, HDA_INPUT),
  2058. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  2059. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  2060. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  2061. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  2062. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  2063. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  2064. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  2065. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  2066. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  2067. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  2068. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  2069. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  2070. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  2071. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  2072. { } /* end */
  2073. };
  2074. /* 3-stack mode */
  2075. static const struct snd_kcontrol_new ad1988_3stack_mixers1[] = {
  2076. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2077. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  2078. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  2079. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  2080. { } /* end */
  2081. };
  2082. static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
  2083. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2084. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0a, 0x0, HDA_OUTPUT),
  2085. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x06, 1, 0x0, HDA_OUTPUT),
  2086. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x06, 2, 0x0, HDA_OUTPUT),
  2087. { } /* end */
  2088. };
  2089. static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
  2090. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  2091. HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
  2092. HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
  2093. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
  2094. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x26, 2, 2, HDA_INPUT),
  2095. HDA_BIND_MUTE("Headphone Playback Switch", 0x22, 2, HDA_INPUT),
  2096. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  2097. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  2098. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  2099. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  2100. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  2101. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  2102. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  2103. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x4, HDA_INPUT),
  2104. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x4, HDA_INPUT),
  2105. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  2106. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  2107. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  2108. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  2109. {
  2110. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2111. .name = "Channel Mode",
  2112. .info = ad198x_ch_mode_info,
  2113. .get = ad198x_ch_mode_get,
  2114. .put = ad198x_ch_mode_put,
  2115. },
  2116. { } /* end */
  2117. };
  2118. /* laptop mode */
  2119. static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
  2120. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  2121. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  2122. HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
  2123. HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
  2124. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x6, HDA_INPUT),
  2125. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x6, HDA_INPUT),
  2126. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x0, HDA_INPUT),
  2127. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x0, HDA_INPUT),
  2128. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x1, HDA_INPUT),
  2129. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x1, HDA_INPUT),
  2130. HDA_CODEC_VOLUME("Analog Mix Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  2131. HDA_CODEC_MUTE("Analog Mix Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  2132. HDA_CODEC_VOLUME("Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  2133. {
  2134. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2135. .name = "External Amplifier",
  2136. .subdevice = HDA_SUBDEV_NID_FLAG | 0x12,
  2137. .info = ad198x_eapd_info,
  2138. .get = ad198x_eapd_get,
  2139. .put = ad198x_eapd_put,
  2140. .private_value = 0x12, /* port-D */
  2141. },
  2142. { } /* end */
  2143. };
  2144. /* capture */
  2145. static const struct snd_kcontrol_new ad1988_capture_mixers[] = {
  2146. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  2147. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  2148. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  2149. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  2150. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x0e, 0x0, HDA_OUTPUT),
  2151. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x0e, 0x0, HDA_OUTPUT),
  2152. {
  2153. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2154. /* The multiple "Capture Source" controls confuse alsamixer
  2155. * So call somewhat different..
  2156. */
  2157. /* .name = "Capture Source", */
  2158. .name = "Input Source",
  2159. .count = 3,
  2160. .info = ad198x_mux_enum_info,
  2161. .get = ad198x_mux_enum_get,
  2162. .put = ad198x_mux_enum_put,
  2163. },
  2164. { } /* end */
  2165. };
  2166. static int ad1988_spdif_playback_source_info(struct snd_kcontrol *kcontrol,
  2167. struct snd_ctl_elem_info *uinfo)
  2168. {
  2169. static const char * const texts[] = {
  2170. "PCM", "ADC1", "ADC2", "ADC3"
  2171. };
  2172. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  2173. uinfo->count = 1;
  2174. uinfo->value.enumerated.items = 4;
  2175. if (uinfo->value.enumerated.item >= 4)
  2176. uinfo->value.enumerated.item = 3;
  2177. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  2178. return 0;
  2179. }
  2180. static int ad1988_spdif_playback_source_get(struct snd_kcontrol *kcontrol,
  2181. struct snd_ctl_elem_value *ucontrol)
  2182. {
  2183. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2184. unsigned int sel;
  2185. sel = snd_hda_codec_read(codec, 0x1d, 0, AC_VERB_GET_AMP_GAIN_MUTE,
  2186. AC_AMP_GET_INPUT);
  2187. if (!(sel & 0x80))
  2188. ucontrol->value.enumerated.item[0] = 0;
  2189. else {
  2190. sel = snd_hda_codec_read(codec, 0x0b, 0,
  2191. AC_VERB_GET_CONNECT_SEL, 0);
  2192. if (sel < 3)
  2193. sel++;
  2194. else
  2195. sel = 0;
  2196. ucontrol->value.enumerated.item[0] = sel;
  2197. }
  2198. return 0;
  2199. }
  2200. static int ad1988_spdif_playback_source_put(struct snd_kcontrol *kcontrol,
  2201. struct snd_ctl_elem_value *ucontrol)
  2202. {
  2203. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2204. unsigned int val, sel;
  2205. int change;
  2206. val = ucontrol->value.enumerated.item[0];
  2207. if (val > 3)
  2208. return -EINVAL;
  2209. if (!val) {
  2210. sel = snd_hda_codec_read(codec, 0x1d, 0,
  2211. AC_VERB_GET_AMP_GAIN_MUTE,
  2212. AC_AMP_GET_INPUT);
  2213. change = sel & 0x80;
  2214. if (change) {
  2215. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2216. AC_VERB_SET_AMP_GAIN_MUTE,
  2217. AMP_IN_UNMUTE(0));
  2218. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2219. AC_VERB_SET_AMP_GAIN_MUTE,
  2220. AMP_IN_MUTE(1));
  2221. }
  2222. } else {
  2223. sel = snd_hda_codec_read(codec, 0x1d, 0,
  2224. AC_VERB_GET_AMP_GAIN_MUTE,
  2225. AC_AMP_GET_INPUT | 0x01);
  2226. change = sel & 0x80;
  2227. if (change) {
  2228. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2229. AC_VERB_SET_AMP_GAIN_MUTE,
  2230. AMP_IN_MUTE(0));
  2231. snd_hda_codec_write_cache(codec, 0x1d, 0,
  2232. AC_VERB_SET_AMP_GAIN_MUTE,
  2233. AMP_IN_UNMUTE(1));
  2234. }
  2235. sel = snd_hda_codec_read(codec, 0x0b, 0,
  2236. AC_VERB_GET_CONNECT_SEL, 0) + 1;
  2237. change |= sel != val;
  2238. if (change)
  2239. snd_hda_codec_write_cache(codec, 0x0b, 0,
  2240. AC_VERB_SET_CONNECT_SEL,
  2241. val - 1);
  2242. }
  2243. return change;
  2244. }
  2245. static const struct snd_kcontrol_new ad1988_spdif_out_mixers[] = {
  2246. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  2247. {
  2248. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2249. .name = "IEC958 Playback Source",
  2250. .subdevice = HDA_SUBDEV_NID_FLAG | 0x1b,
  2251. .info = ad1988_spdif_playback_source_info,
  2252. .get = ad1988_spdif_playback_source_get,
  2253. .put = ad1988_spdif_playback_source_put,
  2254. },
  2255. { } /* end */
  2256. };
  2257. static const struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
  2258. HDA_CODEC_VOLUME("IEC958 Capture Volume", 0x1c, 0x0, HDA_INPUT),
  2259. { } /* end */
  2260. };
  2261. static const struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
  2262. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  2263. HDA_CODEC_VOLUME("HDMI Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  2264. { } /* end */
  2265. };
  2266. /*
  2267. * initialization verbs
  2268. */
  2269. /*
  2270. * for 6-stack (+dig)
  2271. */
  2272. static const struct hda_verb ad1988_6stack_init_verbs[] = {
  2273. /* Front, Surround, CLFE, side DAC; unmute as default */
  2274. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2275. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2276. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2277. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2278. /* Port-A front headphon path */
  2279. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2280. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2281. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2282. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2283. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2284. /* Port-D line-out path */
  2285. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2286. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2287. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2288. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2289. /* Port-F surround path */
  2290. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2291. {0x2a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2292. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2293. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2294. /* Port-G CLFE path */
  2295. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2296. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2297. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2298. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2299. /* Port-H side path */
  2300. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2301. {0x28, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2302. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2303. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2304. /* Mono out path */
  2305. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2306. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2307. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2308. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2309. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2310. /* Port-B front mic-in path */
  2311. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2312. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2313. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2314. /* Port-C line-in path */
  2315. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2316. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2317. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2318. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2319. /* Port-E mic-in path */
  2320. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2321. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2322. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2323. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  2324. /* Analog CD Input */
  2325. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2326. /* Analog Mix output amp */
  2327. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2328. { }
  2329. };
  2330. static const struct hda_verb ad1988_6stack_fp_init_verbs[] = {
  2331. /* Headphone; unmute as default */
  2332. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2333. /* Port-A front headphon path */
  2334. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2335. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2336. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2337. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2338. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2339. { }
  2340. };
  2341. static const struct hda_verb ad1988_capture_init_verbs[] = {
  2342. /* mute analog mix */
  2343. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2344. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2345. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2346. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2347. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2348. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2349. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2350. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2351. /* select ADCs - front-mic */
  2352. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2353. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2354. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2355. { }
  2356. };
  2357. static const struct hda_verb ad1988_spdif_init_verbs[] = {
  2358. /* SPDIF out sel */
  2359. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  2360. {0x0b, AC_VERB_SET_CONNECT_SEL, 0x0}, /* ADC1 */
  2361. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2362. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2363. /* SPDIF out pin */
  2364. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2365. { }
  2366. };
  2367. static const struct hda_verb ad1988_spdif_in_init_verbs[] = {
  2368. /* unmute SPDIF input pin */
  2369. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2370. { }
  2371. };
  2372. /* AD1989 has no ADC -> SPDIF route */
  2373. static const struct hda_verb ad1989_spdif_init_verbs[] = {
  2374. /* SPDIF-1 out pin */
  2375. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2376. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2377. /* SPDIF-2/HDMI out pin */
  2378. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2379. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  2380. { }
  2381. };
  2382. /*
  2383. * verbs for 3stack (+dig)
  2384. */
  2385. static const struct hda_verb ad1988_3stack_ch2_init[] = {
  2386. /* set port-C to line-in */
  2387. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2388. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  2389. /* set port-E to mic-in */
  2390. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2391. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  2392. { } /* end */
  2393. };
  2394. static const struct hda_verb ad1988_3stack_ch6_init[] = {
  2395. /* set port-C to surround out */
  2396. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2397. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2398. /* set port-E to CLFE out */
  2399. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  2400. { 0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2401. { } /* end */
  2402. };
  2403. static const struct hda_channel_mode ad1988_3stack_modes[2] = {
  2404. { 2, ad1988_3stack_ch2_init },
  2405. { 6, ad1988_3stack_ch6_init },
  2406. };
  2407. static const struct hda_verb ad1988_3stack_init_verbs[] = {
  2408. /* Front, Surround, CLFE, side DAC; unmute as default */
  2409. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2410. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2411. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2412. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2413. /* Port-A front headphon path */
  2414. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2415. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2416. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2417. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2418. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2419. /* Port-D line-out path */
  2420. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2421. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2422. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2423. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2424. /* Mono out path */
  2425. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2426. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2427. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2428. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2429. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2430. /* Port-B front mic-in path */
  2431. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2432. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2433. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2434. /* Port-C line-in/surround path - 6ch mode as default */
  2435. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2436. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2437. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2438. {0x31, AC_VERB_SET_CONNECT_SEL, 0x0}, /* output sel: DAC 0x05 */
  2439. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2440. /* Port-E mic-in/CLFE path - 6ch mode as default */
  2441. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2442. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2443. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2444. {0x32, AC_VERB_SET_CONNECT_SEL, 0x1}, /* output sel: DAC 0x0a */
  2445. {0x34, AC_VERB_SET_CONNECT_SEL, 0x0},
  2446. /* mute analog mix */
  2447. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2448. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2449. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2450. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2451. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2452. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2453. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2454. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2455. /* select ADCs - front-mic */
  2456. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2457. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2458. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2459. /* Analog Mix output amp */
  2460. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2461. { }
  2462. };
  2463. /*
  2464. * verbs for laptop mode (+dig)
  2465. */
  2466. static const struct hda_verb ad1988_laptop_hp_on[] = {
  2467. /* unmute port-A and mute port-D */
  2468. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2469. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2470. { } /* end */
  2471. };
  2472. static const struct hda_verb ad1988_laptop_hp_off[] = {
  2473. /* mute port-A and unmute port-D */
  2474. { 0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2475. { 0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  2476. { } /* end */
  2477. };
  2478. #define AD1988_HP_EVENT 0x01
  2479. static const struct hda_verb ad1988_laptop_init_verbs[] = {
  2480. /* Front, Surround, CLFE, side DAC; unmute as default */
  2481. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2482. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2483. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2484. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2485. /* Port-A front headphon path */
  2486. {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
  2487. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2488. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2489. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2490. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2491. /* unsolicited event for pin-sense */
  2492. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1988_HP_EVENT },
  2493. /* Port-D line-out path + EAPD */
  2494. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2495. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2496. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2497. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2498. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x00}, /* EAPD-off */
  2499. /* Mono out path */
  2500. {0x36, AC_VERB_SET_CONNECT_SEL, 0x1}, /* DAC1:04h */
  2501. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2502. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2503. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2504. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, 0xb01f}, /* unmute, 0dB */
  2505. /* Port-B mic-in path */
  2506. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2507. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2508. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2509. /* Port-C docking station - try to output */
  2510. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2511. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2512. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2513. {0x33, AC_VERB_SET_CONNECT_SEL, 0x0},
  2514. /* mute analog mix */
  2515. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2516. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2517. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2518. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2519. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2520. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  2521. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  2522. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  2523. /* select ADCs - mic */
  2524. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  2525. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x1},
  2526. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  2527. /* Analog Mix output amp */
  2528. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  2529. { }
  2530. };
  2531. static void ad1988_laptop_unsol_event(struct hda_codec *codec, unsigned int res)
  2532. {
  2533. if ((res >> 26) != AD1988_HP_EVENT)
  2534. return;
  2535. if (snd_hda_jack_detect(codec, 0x11))
  2536. snd_hda_sequence_write(codec, ad1988_laptop_hp_on);
  2537. else
  2538. snd_hda_sequence_write(codec, ad1988_laptop_hp_off);
  2539. }
  2540. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2541. static const struct hda_amp_list ad1988_loopbacks[] = {
  2542. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  2543. { 0x20, HDA_INPUT, 1 }, /* Line */
  2544. { 0x20, HDA_INPUT, 4 }, /* Mic */
  2545. { 0x20, HDA_INPUT, 6 }, /* CD */
  2546. { } /* end */
  2547. };
  2548. #endif
  2549. /*
  2550. * Automatic parse of I/O pins from the BIOS configuration
  2551. */
  2552. enum {
  2553. AD_CTL_WIDGET_VOL,
  2554. AD_CTL_WIDGET_MUTE,
  2555. AD_CTL_BIND_MUTE,
  2556. };
  2557. static const struct snd_kcontrol_new ad1988_control_templates[] = {
  2558. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  2559. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  2560. HDA_BIND_MUTE(NULL, 0, 0, 0),
  2561. };
  2562. /* add dynamic controls */
  2563. static int add_control(struct ad198x_spec *spec, int type, const char *name,
  2564. unsigned long val)
  2565. {
  2566. struct snd_kcontrol_new *knew;
  2567. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  2568. knew = snd_array_new(&spec->kctls);
  2569. if (!knew)
  2570. return -ENOMEM;
  2571. *knew = ad1988_control_templates[type];
  2572. knew->name = kstrdup(name, GFP_KERNEL);
  2573. if (! knew->name)
  2574. return -ENOMEM;
  2575. if (get_amp_nid_(val))
  2576. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  2577. knew->private_value = val;
  2578. return 0;
  2579. }
  2580. #define AD1988_PIN_CD_NID 0x18
  2581. #define AD1988_PIN_BEEP_NID 0x10
  2582. static const hda_nid_t ad1988_mixer_nids[8] = {
  2583. /* A B C D E F G H */
  2584. 0x22, 0x2b, 0x2c, 0x29, 0x26, 0x2a, 0x27, 0x28
  2585. };
  2586. static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
  2587. {
  2588. static const hda_nid_t idx_to_dac[8] = {
  2589. /* A B C D E F G H */
  2590. 0x03, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
  2591. };
  2592. static const hda_nid_t idx_to_dac_rev2[8] = {
  2593. /* A B C D E F G H */
  2594. 0x03, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
  2595. };
  2596. if (is_rev2(codec))
  2597. return idx_to_dac_rev2[idx];
  2598. else
  2599. return idx_to_dac[idx];
  2600. }
  2601. static const hda_nid_t ad1988_boost_nids[8] = {
  2602. 0x38, 0x39, 0x3a, 0x3d, 0x3c, 0x3b, 0, 0
  2603. };
  2604. static int ad1988_pin_idx(hda_nid_t nid)
  2605. {
  2606. static const hda_nid_t ad1988_io_pins[8] = {
  2607. 0x11, 0x14, 0x15, 0x12, 0x17, 0x16, 0x24, 0x25
  2608. };
  2609. int i;
  2610. for (i = 0; i < ARRAY_SIZE(ad1988_io_pins); i++)
  2611. if (ad1988_io_pins[i] == nid)
  2612. return i;
  2613. return 0; /* should be -1 */
  2614. }
  2615. static int ad1988_pin_to_loopback_idx(hda_nid_t nid)
  2616. {
  2617. static const int loopback_idx[8] = {
  2618. 2, 0, 1, 3, 4, 5, 1, 4
  2619. };
  2620. switch (nid) {
  2621. case AD1988_PIN_CD_NID:
  2622. return 6;
  2623. default:
  2624. return loopback_idx[ad1988_pin_idx(nid)];
  2625. }
  2626. }
  2627. static int ad1988_pin_to_adc_idx(hda_nid_t nid)
  2628. {
  2629. static const int adc_idx[8] = {
  2630. 0, 1, 2, 8, 4, 3, 6, 7
  2631. };
  2632. switch (nid) {
  2633. case AD1988_PIN_CD_NID:
  2634. return 5;
  2635. default:
  2636. return adc_idx[ad1988_pin_idx(nid)];
  2637. }
  2638. }
  2639. /* fill in the dac_nids table from the parsed pin configuration */
  2640. static int ad1988_auto_fill_dac_nids(struct hda_codec *codec,
  2641. const struct auto_pin_cfg *cfg)
  2642. {
  2643. struct ad198x_spec *spec = codec->spec;
  2644. int i, idx;
  2645. spec->multiout.dac_nids = spec->private_dac_nids;
  2646. /* check the pins hardwired to audio widget */
  2647. for (i = 0; i < cfg->line_outs; i++) {
  2648. idx = ad1988_pin_idx(cfg->line_out_pins[i]);
  2649. spec->private_dac_nids[i] = ad1988_idx_to_dac(codec, idx);
  2650. }
  2651. spec->multiout.num_dacs = cfg->line_outs;
  2652. return 0;
  2653. }
  2654. /* add playback controls from the parsed DAC table */
  2655. static int ad1988_auto_create_multi_out_ctls(struct ad198x_spec *spec,
  2656. const struct auto_pin_cfg *cfg)
  2657. {
  2658. char name[32];
  2659. static const char * const chname[4] = {
  2660. "Front", "Surround", NULL /*CLFE*/, "Side"
  2661. };
  2662. hda_nid_t nid;
  2663. int i, err;
  2664. for (i = 0; i < cfg->line_outs; i++) {
  2665. hda_nid_t dac = spec->multiout.dac_nids[i];
  2666. if (! dac)
  2667. continue;
  2668. nid = ad1988_mixer_nids[ad1988_pin_idx(cfg->line_out_pins[i])];
  2669. if (i == 2) {
  2670. /* Center/LFE */
  2671. err = add_control(spec, AD_CTL_WIDGET_VOL,
  2672. "Center Playback Volume",
  2673. HDA_COMPOSE_AMP_VAL(dac, 1, 0, HDA_OUTPUT));
  2674. if (err < 0)
  2675. return err;
  2676. err = add_control(spec, AD_CTL_WIDGET_VOL,
  2677. "LFE Playback Volume",
  2678. HDA_COMPOSE_AMP_VAL(dac, 2, 0, HDA_OUTPUT));
  2679. if (err < 0)
  2680. return err;
  2681. err = add_control(spec, AD_CTL_BIND_MUTE,
  2682. "Center Playback Switch",
  2683. HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT));
  2684. if (err < 0)
  2685. return err;
  2686. err = add_control(spec, AD_CTL_BIND_MUTE,
  2687. "LFE Playback Switch",
  2688. HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT));
  2689. if (err < 0)
  2690. return err;
  2691. } else {
  2692. sprintf(name, "%s Playback Volume", chname[i]);
  2693. err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2694. HDA_COMPOSE_AMP_VAL(dac, 3, 0, HDA_OUTPUT));
  2695. if (err < 0)
  2696. return err;
  2697. sprintf(name, "%s Playback Switch", chname[i]);
  2698. err = add_control(spec, AD_CTL_BIND_MUTE, name,
  2699. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT));
  2700. if (err < 0)
  2701. return err;
  2702. }
  2703. }
  2704. return 0;
  2705. }
  2706. /* add playback controls for speaker and HP outputs */
  2707. static int ad1988_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
  2708. const char *pfx)
  2709. {
  2710. struct ad198x_spec *spec = codec->spec;
  2711. hda_nid_t nid;
  2712. int i, idx, err;
  2713. char name[32];
  2714. if (! pin)
  2715. return 0;
  2716. idx = ad1988_pin_idx(pin);
  2717. nid = ad1988_idx_to_dac(codec, idx);
  2718. /* check whether the corresponding DAC was already taken */
  2719. for (i = 0; i < spec->autocfg.line_outs; i++) {
  2720. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  2721. hda_nid_t dac = ad1988_idx_to_dac(codec, ad1988_pin_idx(pin));
  2722. if (dac == nid)
  2723. break;
  2724. }
  2725. if (i >= spec->autocfg.line_outs) {
  2726. /* specify the DAC as the extra output */
  2727. if (!spec->multiout.hp_nid)
  2728. spec->multiout.hp_nid = nid;
  2729. else
  2730. spec->multiout.extra_out_nid[0] = nid;
  2731. /* control HP volume/switch on the output mixer amp */
  2732. sprintf(name, "%s Playback Volume", pfx);
  2733. err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2734. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT));
  2735. if (err < 0)
  2736. return err;
  2737. }
  2738. nid = ad1988_mixer_nids[idx];
  2739. sprintf(name, "%s Playback Switch", pfx);
  2740. if ((err = add_control(spec, AD_CTL_BIND_MUTE, name,
  2741. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  2742. return err;
  2743. return 0;
  2744. }
  2745. /* create input playback/capture controls for the given pin */
  2746. static int new_analog_input(struct ad198x_spec *spec, hda_nid_t pin,
  2747. const char *ctlname, int ctlidx, int boost)
  2748. {
  2749. char name[32];
  2750. int err, idx;
  2751. sprintf(name, "%s Playback Volume", ctlname);
  2752. idx = ad1988_pin_to_loopback_idx(pin);
  2753. if ((err = add_control(spec, AD_CTL_WIDGET_VOL, name,
  2754. HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  2755. return err;
  2756. sprintf(name, "%s Playback Switch", ctlname);
  2757. if ((err = add_control(spec, AD_CTL_WIDGET_MUTE, name,
  2758. HDA_COMPOSE_AMP_VAL(0x20, 3, idx, HDA_INPUT))) < 0)
  2759. return err;
  2760. if (boost) {
  2761. hda_nid_t bnid;
  2762. idx = ad1988_pin_idx(pin);
  2763. bnid = ad1988_boost_nids[idx];
  2764. if (bnid) {
  2765. sprintf(name, "%s Boost Volume", ctlname);
  2766. return add_control(spec, AD_CTL_WIDGET_VOL, name,
  2767. HDA_COMPOSE_AMP_VAL(bnid, 3, idx, HDA_OUTPUT));
  2768. }
  2769. }
  2770. return 0;
  2771. }
  2772. /* create playback/capture controls for input pins */
  2773. static int ad1988_auto_create_analog_input_ctls(struct hda_codec *codec,
  2774. const struct auto_pin_cfg *cfg)
  2775. {
  2776. struct ad198x_spec *spec = codec->spec;
  2777. struct hda_input_mux *imux = &spec->private_imux;
  2778. int i, err, type, type_idx;
  2779. for (i = 0; i < cfg->num_inputs; i++) {
  2780. const char *label;
  2781. type = cfg->inputs[i].type;
  2782. label = hda_get_autocfg_input_label(codec, cfg, i);
  2783. snd_hda_add_imux_item(imux, label,
  2784. ad1988_pin_to_adc_idx(cfg->inputs[i].pin),
  2785. &type_idx);
  2786. err = new_analog_input(spec, cfg->inputs[i].pin,
  2787. label, type_idx,
  2788. type == AUTO_PIN_MIC);
  2789. if (err < 0)
  2790. return err;
  2791. }
  2792. snd_hda_add_imux_item(imux, "Mix", 9, NULL);
  2793. if ((err = add_control(spec, AD_CTL_WIDGET_VOL,
  2794. "Analog Mix Playback Volume",
  2795. HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  2796. return err;
  2797. if ((err = add_control(spec, AD_CTL_WIDGET_MUTE,
  2798. "Analog Mix Playback Switch",
  2799. HDA_COMPOSE_AMP_VAL(0x21, 3, 0x0, HDA_OUTPUT))) < 0)
  2800. return err;
  2801. return 0;
  2802. }
  2803. static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
  2804. hda_nid_t nid, int pin_type,
  2805. int dac_idx)
  2806. {
  2807. /* set as output */
  2808. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  2809. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  2810. switch (nid) {
  2811. case 0x11: /* port-A - DAC 03 */
  2812. snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
  2813. break;
  2814. case 0x14: /* port-B - DAC 06 */
  2815. snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
  2816. break;
  2817. case 0x15: /* port-C - DAC 05 */
  2818. snd_hda_codec_write(codec, 0x31, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
  2819. break;
  2820. case 0x17: /* port-E - DAC 0a */
  2821. snd_hda_codec_write(codec, 0x32, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2822. break;
  2823. case 0x13: /* mono - DAC 04 */
  2824. snd_hda_codec_write(codec, 0x36, 0, AC_VERB_SET_CONNECT_SEL, 0x01);
  2825. break;
  2826. }
  2827. }
  2828. static void ad1988_auto_init_multi_out(struct hda_codec *codec)
  2829. {
  2830. struct ad198x_spec *spec = codec->spec;
  2831. int i;
  2832. for (i = 0; i < spec->autocfg.line_outs; i++) {
  2833. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  2834. ad1988_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  2835. }
  2836. }
  2837. static void ad1988_auto_init_extra_out(struct hda_codec *codec)
  2838. {
  2839. struct ad198x_spec *spec = codec->spec;
  2840. hda_nid_t pin;
  2841. pin = spec->autocfg.speaker_pins[0];
  2842. if (pin) /* connect to front */
  2843. ad1988_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
  2844. pin = spec->autocfg.hp_pins[0];
  2845. if (pin) /* connect to front */
  2846. ad1988_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  2847. }
  2848. static void ad1988_auto_init_analog_input(struct hda_codec *codec)
  2849. {
  2850. struct ad198x_spec *spec = codec->spec;
  2851. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2852. int i, idx;
  2853. for (i = 0; i < cfg->num_inputs; i++) {
  2854. hda_nid_t nid = cfg->inputs[i].pin;
  2855. int type = cfg->inputs[i].type;
  2856. switch (nid) {
  2857. case 0x15: /* port-C */
  2858. snd_hda_codec_write(codec, 0x33, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  2859. break;
  2860. case 0x17: /* port-E */
  2861. snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_CONNECT_SEL, 0x0);
  2862. break;
  2863. }
  2864. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  2865. type == AUTO_PIN_MIC ? PIN_VREF80 : PIN_IN);
  2866. if (nid != AD1988_PIN_CD_NID)
  2867. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2868. AMP_OUT_MUTE);
  2869. idx = ad1988_pin_idx(nid);
  2870. if (ad1988_boost_nids[idx])
  2871. snd_hda_codec_write(codec, ad1988_boost_nids[idx], 0,
  2872. AC_VERB_SET_AMP_GAIN_MUTE,
  2873. AMP_OUT_ZERO);
  2874. }
  2875. }
  2876. /* parse the BIOS configuration and set up the alc_spec */
  2877. /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  2878. static int ad1988_parse_auto_config(struct hda_codec *codec)
  2879. {
  2880. struct ad198x_spec *spec = codec->spec;
  2881. int err;
  2882. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  2883. return err;
  2884. if ((err = ad1988_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  2885. return err;
  2886. if (! spec->autocfg.line_outs)
  2887. return 0; /* can't find valid BIOS pin config */
  2888. if ((err = ad1988_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  2889. (err = ad1988_auto_create_extra_out(codec,
  2890. spec->autocfg.speaker_pins[0],
  2891. "Speaker")) < 0 ||
  2892. (err = ad1988_auto_create_extra_out(codec, spec->autocfg.hp_pins[0],
  2893. "Headphone")) < 0 ||
  2894. (err = ad1988_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  2895. return err;
  2896. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2897. if (spec->autocfg.dig_outs)
  2898. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2899. if (spec->autocfg.dig_in_pin)
  2900. spec->dig_in_nid = AD1988_SPDIF_IN;
  2901. if (spec->kctls.list)
  2902. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2903. spec->init_verbs[spec->num_init_verbs++] = ad1988_6stack_init_verbs;
  2904. spec->input_mux = &spec->private_imux;
  2905. return 1;
  2906. }
  2907. /* init callback for auto-configuration model -- overriding the default init */
  2908. static int ad1988_auto_init(struct hda_codec *codec)
  2909. {
  2910. ad198x_init(codec);
  2911. ad1988_auto_init_multi_out(codec);
  2912. ad1988_auto_init_extra_out(codec);
  2913. ad1988_auto_init_analog_input(codec);
  2914. return 0;
  2915. }
  2916. /*
  2917. */
  2918. static const char * const ad1988_models[AD1988_MODEL_LAST] = {
  2919. [AD1988_6STACK] = "6stack",
  2920. [AD1988_6STACK_DIG] = "6stack-dig",
  2921. [AD1988_3STACK] = "3stack",
  2922. [AD1988_3STACK_DIG] = "3stack-dig",
  2923. [AD1988_LAPTOP] = "laptop",
  2924. [AD1988_LAPTOP_DIG] = "laptop-dig",
  2925. [AD1988_AUTO] = "auto",
  2926. };
  2927. static const struct snd_pci_quirk ad1988_cfg_tbl[] = {
  2928. SND_PCI_QUIRK(0x1043, 0x81ec, "Asus P5B-DLX", AD1988_6STACK_DIG),
  2929. SND_PCI_QUIRK(0x1043, 0x81f6, "Asus M2N-SLI", AD1988_6STACK_DIG),
  2930. SND_PCI_QUIRK(0x1043, 0x8277, "Asus P5K-E/WIFI-AP", AD1988_6STACK_DIG),
  2931. SND_PCI_QUIRK(0x1043, 0x82c0, "Asus M3N-HT Deluxe", AD1988_6STACK_DIG),
  2932. SND_PCI_QUIRK(0x1043, 0x8311, "Asus P5Q-Premium/Pro", AD1988_6STACK_DIG),
  2933. {}
  2934. };
  2935. static int patch_ad1988(struct hda_codec *codec)
  2936. {
  2937. struct ad198x_spec *spec;
  2938. int err, board_config;
  2939. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2940. if (spec == NULL)
  2941. return -ENOMEM;
  2942. codec->spec = spec;
  2943. if (is_rev2(codec))
  2944. snd_printk(KERN_INFO "patch_analog: AD1988A rev.2 is detected, enable workarounds\n");
  2945. board_config = snd_hda_check_board_config(codec, AD1988_MODEL_LAST,
  2946. ad1988_models, ad1988_cfg_tbl);
  2947. if (board_config < 0) {
  2948. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  2949. codec->chip_name);
  2950. board_config = AD1988_AUTO;
  2951. }
  2952. if (board_config == AD1988_AUTO) {
  2953. /* automatic parse from the BIOS config */
  2954. err = ad1988_parse_auto_config(codec);
  2955. if (err < 0) {
  2956. ad198x_free(codec);
  2957. return err;
  2958. } else if (! err) {
  2959. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 6-stack mode...\n");
  2960. board_config = AD1988_6STACK;
  2961. }
  2962. }
  2963. err = snd_hda_attach_beep_device(codec, 0x10);
  2964. if (err < 0) {
  2965. ad198x_free(codec);
  2966. return err;
  2967. }
  2968. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  2969. if (!spec->multiout.hp_nid)
  2970. spec->multiout.hp_nid = ad1988_alt_dac_nid[0];
  2971. switch (board_config) {
  2972. case AD1988_6STACK:
  2973. case AD1988_6STACK_DIG:
  2974. spec->multiout.max_channels = 8;
  2975. spec->multiout.num_dacs = 4;
  2976. if (is_rev2(codec))
  2977. spec->multiout.dac_nids = ad1988_6stack_dac_nids_rev2;
  2978. else
  2979. spec->multiout.dac_nids = ad1988_6stack_dac_nids;
  2980. spec->input_mux = &ad1988_6stack_capture_source;
  2981. spec->num_mixers = 2;
  2982. if (is_rev2(codec))
  2983. spec->mixers[0] = ad1988_6stack_mixers1_rev2;
  2984. else
  2985. spec->mixers[0] = ad1988_6stack_mixers1;
  2986. spec->mixers[1] = ad1988_6stack_mixers2;
  2987. spec->num_init_verbs = 1;
  2988. spec->init_verbs[0] = ad1988_6stack_init_verbs;
  2989. if (board_config == AD1988_6STACK_DIG) {
  2990. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  2991. spec->dig_in_nid = AD1988_SPDIF_IN;
  2992. }
  2993. break;
  2994. case AD1988_3STACK:
  2995. case AD1988_3STACK_DIG:
  2996. spec->multiout.max_channels = 6;
  2997. spec->multiout.num_dacs = 3;
  2998. if (is_rev2(codec))
  2999. spec->multiout.dac_nids = ad1988_3stack_dac_nids_rev2;
  3000. else
  3001. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  3002. spec->input_mux = &ad1988_6stack_capture_source;
  3003. spec->channel_mode = ad1988_3stack_modes;
  3004. spec->num_channel_mode = ARRAY_SIZE(ad1988_3stack_modes);
  3005. spec->num_mixers = 2;
  3006. if (is_rev2(codec))
  3007. spec->mixers[0] = ad1988_3stack_mixers1_rev2;
  3008. else
  3009. spec->mixers[0] = ad1988_3stack_mixers1;
  3010. spec->mixers[1] = ad1988_3stack_mixers2;
  3011. spec->num_init_verbs = 1;
  3012. spec->init_verbs[0] = ad1988_3stack_init_verbs;
  3013. if (board_config == AD1988_3STACK_DIG)
  3014. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  3015. break;
  3016. case AD1988_LAPTOP:
  3017. case AD1988_LAPTOP_DIG:
  3018. spec->multiout.max_channels = 2;
  3019. spec->multiout.num_dacs = 1;
  3020. spec->multiout.dac_nids = ad1988_3stack_dac_nids;
  3021. spec->input_mux = &ad1988_laptop_capture_source;
  3022. spec->num_mixers = 1;
  3023. spec->mixers[0] = ad1988_laptop_mixers;
  3024. spec->inv_eapd = 1; /* inverted EAPD */
  3025. spec->num_init_verbs = 1;
  3026. spec->init_verbs[0] = ad1988_laptop_init_verbs;
  3027. if (board_config == AD1988_LAPTOP_DIG)
  3028. spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
  3029. break;
  3030. }
  3031. if (spec->autocfg.hp_pins[0]) {
  3032. spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
  3033. spec->slave_vols = ad1988_6stack_fp_slave_pfxs;
  3034. spec->slave_sws = ad1988_6stack_fp_slave_pfxs;
  3035. spec->alt_dac_nid = ad1988_alt_dac_nid;
  3036. spec->stream_analog_alt_playback =
  3037. &ad198x_pcm_analog_alt_playback;
  3038. }
  3039. spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
  3040. spec->adc_nids = ad1988_adc_nids;
  3041. spec->capsrc_nids = ad1988_capsrc_nids;
  3042. spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
  3043. spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
  3044. if (spec->multiout.dig_out_nid) {
  3045. if (codec->vendor_id >= 0x11d4989a) {
  3046. spec->mixers[spec->num_mixers++] =
  3047. ad1989_spdif_out_mixers;
  3048. spec->init_verbs[spec->num_init_verbs++] =
  3049. ad1989_spdif_init_verbs;
  3050. codec->slave_dig_outs = ad1989b_slave_dig_outs;
  3051. } else {
  3052. spec->mixers[spec->num_mixers++] =
  3053. ad1988_spdif_out_mixers;
  3054. spec->init_verbs[spec->num_init_verbs++] =
  3055. ad1988_spdif_init_verbs;
  3056. }
  3057. }
  3058. if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a) {
  3059. spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
  3060. spec->init_verbs[spec->num_init_verbs++] =
  3061. ad1988_spdif_in_init_verbs;
  3062. }
  3063. codec->patch_ops = ad198x_patch_ops;
  3064. switch (board_config) {
  3065. case AD1988_AUTO:
  3066. codec->patch_ops.init = ad1988_auto_init;
  3067. break;
  3068. case AD1988_LAPTOP:
  3069. case AD1988_LAPTOP_DIG:
  3070. codec->patch_ops.unsol_event = ad1988_laptop_unsol_event;
  3071. break;
  3072. }
  3073. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3074. spec->loopback.amplist = ad1988_loopbacks;
  3075. #endif
  3076. spec->vmaster_nid = 0x04;
  3077. codec->no_trigger_sense = 1;
  3078. codec->no_sticky_stream = 1;
  3079. return 0;
  3080. }
  3081. /*
  3082. * AD1884 / AD1984
  3083. *
  3084. * port-B - front line/mic-in
  3085. * port-E - aux in/out
  3086. * port-F - aux in/out
  3087. * port-C - rear line/mic-in
  3088. * port-D - rear line/hp-out
  3089. * port-A - front line/hp-out
  3090. *
  3091. * AD1984 = AD1884 + two digital mic-ins
  3092. *
  3093. * FIXME:
  3094. * For simplicity, we share the single DAC for both HP and line-outs
  3095. * right now. The inidividual playbacks could be easily implemented,
  3096. * but no build-up framework is given, so far.
  3097. */
  3098. static const hda_nid_t ad1884_dac_nids[1] = {
  3099. 0x04,
  3100. };
  3101. static const hda_nid_t ad1884_adc_nids[2] = {
  3102. 0x08, 0x09,
  3103. };
  3104. static const hda_nid_t ad1884_capsrc_nids[2] = {
  3105. 0x0c, 0x0d,
  3106. };
  3107. #define AD1884_SPDIF_OUT 0x02
  3108. static const struct hda_input_mux ad1884_capture_source = {
  3109. .num_items = 4,
  3110. .items = {
  3111. { "Front Mic", 0x0 },
  3112. { "Mic", 0x1 },
  3113. { "CD", 0x2 },
  3114. { "Mix", 0x3 },
  3115. },
  3116. };
  3117. static const struct snd_kcontrol_new ad1884_base_mixers[] = {
  3118. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  3119. /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
  3120. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3121. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3122. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  3123. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  3124. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3125. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3126. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  3127. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  3128. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
  3129. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
  3130. HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  3131. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3132. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3133. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3134. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3135. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3136. {
  3137. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3138. /* The multiple "Capture Source" controls confuse alsamixer
  3139. * So call somewhat different..
  3140. */
  3141. /* .name = "Capture Source", */
  3142. .name = "Input Source",
  3143. .count = 2,
  3144. .info = ad198x_mux_enum_info,
  3145. .get = ad198x_mux_enum_get,
  3146. .put = ad198x_mux_enum_put,
  3147. },
  3148. /* SPDIF controls */
  3149. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  3150. {
  3151. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3152. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  3153. /* identical with ad1983 */
  3154. .info = ad1983_spdif_route_info,
  3155. .get = ad1983_spdif_route_get,
  3156. .put = ad1983_spdif_route_put,
  3157. },
  3158. { } /* end */
  3159. };
  3160. static const struct snd_kcontrol_new ad1984_dmic_mixers[] = {
  3161. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x05, 0x0, HDA_INPUT),
  3162. HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x05, 0x0, HDA_INPUT),
  3163. HDA_CODEC_VOLUME_IDX("Digital Mic Capture Volume", 1, 0x06, 0x0,
  3164. HDA_INPUT),
  3165. HDA_CODEC_MUTE_IDX("Digital Mic Capture Switch", 1, 0x06, 0x0,
  3166. HDA_INPUT),
  3167. { } /* end */
  3168. };
  3169. /*
  3170. * initialization verbs
  3171. */
  3172. static const struct hda_verb ad1884_init_verbs[] = {
  3173. /* DACs; mute as default */
  3174. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3175. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3176. /* Port-A (HP) mixer */
  3177. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3178. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3179. /* Port-A pin */
  3180. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3181. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3182. /* HP selector - select DAC2 */
  3183. {0x22, AC_VERB_SET_CONNECT_SEL, 0x1},
  3184. /* Port-D (Line-out) mixer */
  3185. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3186. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3187. /* Port-D pin */
  3188. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3189. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3190. /* Mono-out mixer */
  3191. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3192. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3193. /* Mono-out pin */
  3194. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3195. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3196. /* Mono selector */
  3197. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x1},
  3198. /* Port-B (front mic) pin */
  3199. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3200. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3201. /* Port-C (rear mic) pin */
  3202. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3203. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3204. /* Analog mixer; mute as default */
  3205. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3206. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3207. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3208. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3209. /* Analog Mix output amp */
  3210. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  3211. /* SPDIF output selector */
  3212. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  3213. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  3214. { } /* end */
  3215. };
  3216. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3217. static const struct hda_amp_list ad1884_loopbacks[] = {
  3218. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  3219. { 0x20, HDA_INPUT, 1 }, /* Mic */
  3220. { 0x20, HDA_INPUT, 2 }, /* CD */
  3221. { 0x20, HDA_INPUT, 4 }, /* Docking */
  3222. { } /* end */
  3223. };
  3224. #endif
  3225. static const char * const ad1884_slave_vols[] = {
  3226. "PCM", "Mic", "Mono", "Front Mic", "Mic", "CD",
  3227. "Internal Mic", "Docking Mic", /* "Beep", */ "IEC958",
  3228. NULL
  3229. };
  3230. static int patch_ad1884(struct hda_codec *codec)
  3231. {
  3232. struct ad198x_spec *spec;
  3233. int err;
  3234. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3235. if (spec == NULL)
  3236. return -ENOMEM;
  3237. codec->spec = spec;
  3238. err = snd_hda_attach_beep_device(codec, 0x10);
  3239. if (err < 0) {
  3240. ad198x_free(codec);
  3241. return err;
  3242. }
  3243. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  3244. spec->multiout.max_channels = 2;
  3245. spec->multiout.num_dacs = ARRAY_SIZE(ad1884_dac_nids);
  3246. spec->multiout.dac_nids = ad1884_dac_nids;
  3247. spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
  3248. spec->num_adc_nids = ARRAY_SIZE(ad1884_adc_nids);
  3249. spec->adc_nids = ad1884_adc_nids;
  3250. spec->capsrc_nids = ad1884_capsrc_nids;
  3251. spec->input_mux = &ad1884_capture_source;
  3252. spec->num_mixers = 1;
  3253. spec->mixers[0] = ad1884_base_mixers;
  3254. spec->num_init_verbs = 1;
  3255. spec->init_verbs[0] = ad1884_init_verbs;
  3256. spec->spdif_route = 0;
  3257. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3258. spec->loopback.amplist = ad1884_loopbacks;
  3259. #endif
  3260. spec->vmaster_nid = 0x04;
  3261. /* we need to cover all playback volumes */
  3262. spec->slave_vols = ad1884_slave_vols;
  3263. /* slaves may contain input volumes, so we can't raise to 0dB blindly */
  3264. spec->avoid_init_slave_vol = 1;
  3265. codec->patch_ops = ad198x_patch_ops;
  3266. codec->no_trigger_sense = 1;
  3267. codec->no_sticky_stream = 1;
  3268. return 0;
  3269. }
  3270. /*
  3271. * Lenovo Thinkpad T61/X61
  3272. */
  3273. static const struct hda_input_mux ad1984_thinkpad_capture_source = {
  3274. .num_items = 4,
  3275. .items = {
  3276. { "Mic", 0x0 },
  3277. { "Internal Mic", 0x1 },
  3278. { "Mix", 0x3 },
  3279. { "Docking-Station", 0x4 },
  3280. },
  3281. };
  3282. /*
  3283. * Dell Precision T3400
  3284. */
  3285. static const struct hda_input_mux ad1984_dell_desktop_capture_source = {
  3286. .num_items = 3,
  3287. .items = {
  3288. { "Front Mic", 0x0 },
  3289. { "Line-In", 0x1 },
  3290. { "Mix", 0x3 },
  3291. },
  3292. };
  3293. static const struct snd_kcontrol_new ad1984_thinkpad_mixers[] = {
  3294. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  3295. /* HDA_CODEC_VOLUME_IDX("PCM Playback Volume", 1, 0x03, 0x0, HDA_OUTPUT), */
  3296. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3297. HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3298. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3299. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3300. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  3301. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  3302. HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
  3303. HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
  3304. HDA_CODEC_VOLUME("Docking Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  3305. HDA_CODEC_MUTE("Docking Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  3306. HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3307. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  3308. HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  3309. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3310. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3311. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3312. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3313. {
  3314. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3315. /* The multiple "Capture Source" controls confuse alsamixer
  3316. * So call somewhat different..
  3317. */
  3318. /* .name = "Capture Source", */
  3319. .name = "Input Source",
  3320. .count = 2,
  3321. .info = ad198x_mux_enum_info,
  3322. .get = ad198x_mux_enum_get,
  3323. .put = ad198x_mux_enum_put,
  3324. },
  3325. /* SPDIF controls */
  3326. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  3327. {
  3328. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3329. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  3330. /* identical with ad1983 */
  3331. .info = ad1983_spdif_route_info,
  3332. .get = ad1983_spdif_route_get,
  3333. .put = ad1983_spdif_route_put,
  3334. },
  3335. { } /* end */
  3336. };
  3337. /* additional verbs */
  3338. static const struct hda_verb ad1984_thinkpad_init_verbs[] = {
  3339. /* Port-E (docking station mic) pin */
  3340. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3341. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3342. /* docking mic boost */
  3343. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3344. /* Analog PC Beeper - allow firmware/ACPI beeps */
  3345. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3) | 0x1a},
  3346. /* Analog mixer - docking mic; mute as default */
  3347. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3348. /* enable EAPD bit */
  3349. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  3350. { } /* end */
  3351. };
  3352. /*
  3353. * Dell Precision T3400
  3354. */
  3355. static const struct snd_kcontrol_new ad1984_dell_desktop_mixers[] = {
  3356. HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  3357. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3358. HDA_CODEC_MUTE("Speaker Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3359. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  3360. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  3361. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3362. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3363. HDA_CODEC_VOLUME("Line-In Playback Volume", 0x20, 0x01, HDA_INPUT),
  3364. HDA_CODEC_MUTE("Line-In Playback Switch", 0x20, 0x01, HDA_INPUT),
  3365. HDA_CODEC_VOLUME("Line-In Boost Volume", 0x15, 0x0, HDA_INPUT),
  3366. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3367. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3368. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3369. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3370. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3371. {
  3372. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3373. /* The multiple "Capture Source" controls confuse alsamixer
  3374. * So call somewhat different..
  3375. */
  3376. /* .name = "Capture Source", */
  3377. .name = "Input Source",
  3378. .count = 2,
  3379. .info = ad198x_mux_enum_info,
  3380. .get = ad198x_mux_enum_get,
  3381. .put = ad198x_mux_enum_put,
  3382. },
  3383. { } /* end */
  3384. };
  3385. /* Digial MIC ADC NID 0x05 + 0x06 */
  3386. static int ad1984_pcm_dmic_prepare(struct hda_pcm_stream *hinfo,
  3387. struct hda_codec *codec,
  3388. unsigned int stream_tag,
  3389. unsigned int format,
  3390. struct snd_pcm_substream *substream)
  3391. {
  3392. snd_hda_codec_setup_stream(codec, 0x05 + substream->number,
  3393. stream_tag, 0, format);
  3394. return 0;
  3395. }
  3396. static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
  3397. struct hda_codec *codec,
  3398. struct snd_pcm_substream *substream)
  3399. {
  3400. snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
  3401. return 0;
  3402. }
  3403. static const struct hda_pcm_stream ad1984_pcm_dmic_capture = {
  3404. .substreams = 2,
  3405. .channels_min = 2,
  3406. .channels_max = 2,
  3407. .nid = 0x05,
  3408. .ops = {
  3409. .prepare = ad1984_pcm_dmic_prepare,
  3410. .cleanup = ad1984_pcm_dmic_cleanup
  3411. },
  3412. };
  3413. static int ad1984_build_pcms(struct hda_codec *codec)
  3414. {
  3415. struct ad198x_spec *spec = codec->spec;
  3416. struct hda_pcm *info;
  3417. int err;
  3418. err = ad198x_build_pcms(codec);
  3419. if (err < 0)
  3420. return err;
  3421. info = spec->pcm_rec + codec->num_pcms;
  3422. codec->num_pcms++;
  3423. info->name = "AD1984 Digital Mic";
  3424. info->stream[SNDRV_PCM_STREAM_CAPTURE] = ad1984_pcm_dmic_capture;
  3425. return 0;
  3426. }
  3427. /* models */
  3428. enum {
  3429. AD1984_BASIC,
  3430. AD1984_THINKPAD,
  3431. AD1984_DELL_DESKTOP,
  3432. AD1984_MODELS
  3433. };
  3434. static const char * const ad1984_models[AD1984_MODELS] = {
  3435. [AD1984_BASIC] = "basic",
  3436. [AD1984_THINKPAD] = "thinkpad",
  3437. [AD1984_DELL_DESKTOP] = "dell_desktop",
  3438. };
  3439. static const struct snd_pci_quirk ad1984_cfg_tbl[] = {
  3440. /* Lenovo Thinkpad T61/X61 */
  3441. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo Thinkpad", AD1984_THINKPAD),
  3442. SND_PCI_QUIRK(0x1028, 0x0214, "Dell T3400", AD1984_DELL_DESKTOP),
  3443. SND_PCI_QUIRK(0x1028, 0x0233, "Dell Latitude E6400", AD1984_DELL_DESKTOP),
  3444. {}
  3445. };
  3446. static int patch_ad1984(struct hda_codec *codec)
  3447. {
  3448. struct ad198x_spec *spec;
  3449. int board_config, err;
  3450. err = patch_ad1884(codec);
  3451. if (err < 0)
  3452. return err;
  3453. spec = codec->spec;
  3454. board_config = snd_hda_check_board_config(codec, AD1984_MODELS,
  3455. ad1984_models, ad1984_cfg_tbl);
  3456. switch (board_config) {
  3457. case AD1984_BASIC:
  3458. /* additional digital mics */
  3459. spec->mixers[spec->num_mixers++] = ad1984_dmic_mixers;
  3460. codec->patch_ops.build_pcms = ad1984_build_pcms;
  3461. break;
  3462. case AD1984_THINKPAD:
  3463. if (codec->subsystem_id == 0x17aa20fb) {
  3464. /* Thinpad X300 does not have the ability to do SPDIF,
  3465. or attach to docking station to use SPDIF */
  3466. spec->multiout.dig_out_nid = 0;
  3467. } else
  3468. spec->multiout.dig_out_nid = AD1884_SPDIF_OUT;
  3469. spec->input_mux = &ad1984_thinkpad_capture_source;
  3470. spec->mixers[0] = ad1984_thinkpad_mixers;
  3471. spec->init_verbs[spec->num_init_verbs++] = ad1984_thinkpad_init_verbs;
  3472. spec->analog_beep = 1;
  3473. break;
  3474. case AD1984_DELL_DESKTOP:
  3475. spec->multiout.dig_out_nid = 0;
  3476. spec->input_mux = &ad1984_dell_desktop_capture_source;
  3477. spec->mixers[0] = ad1984_dell_desktop_mixers;
  3478. break;
  3479. }
  3480. return 0;
  3481. }
  3482. /*
  3483. * AD1883 / AD1884A / AD1984A / AD1984B
  3484. *
  3485. * port-B (0x14) - front mic-in
  3486. * port-E (0x1c) - rear mic-in
  3487. * port-F (0x16) - CD / ext out
  3488. * port-C (0x15) - rear line-in
  3489. * port-D (0x12) - rear line-out
  3490. * port-A (0x11) - front hp-out
  3491. *
  3492. * AD1984A = AD1884A + digital-mic
  3493. * AD1883 = equivalent with AD1984A
  3494. * AD1984B = AD1984A + extra SPDIF-out
  3495. *
  3496. * FIXME:
  3497. * We share the single DAC for both HP and line-outs (see AD1884/1984).
  3498. */
  3499. static const hda_nid_t ad1884a_dac_nids[1] = {
  3500. 0x03,
  3501. };
  3502. #define ad1884a_adc_nids ad1884_adc_nids
  3503. #define ad1884a_capsrc_nids ad1884_capsrc_nids
  3504. #define AD1884A_SPDIF_OUT 0x02
  3505. static const struct hda_input_mux ad1884a_capture_source = {
  3506. .num_items = 5,
  3507. .items = {
  3508. { "Front Mic", 0x0 },
  3509. { "Mic", 0x4 },
  3510. { "Line", 0x1 },
  3511. { "CD", 0x2 },
  3512. { "Mix", 0x3 },
  3513. },
  3514. };
  3515. static const struct snd_kcontrol_new ad1884a_base_mixers[] = {
  3516. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3517. HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  3518. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  3519. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3520. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  3521. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  3522. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3523. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3524. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3525. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3526. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
  3527. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
  3528. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  3529. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  3530. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
  3531. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
  3532. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3533. HDA_CODEC_VOLUME("Line Boost Volume", 0x15, 0x0, HDA_INPUT),
  3534. HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  3535. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3536. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3537. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  3538. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  3539. {
  3540. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3541. /* The multiple "Capture Source" controls confuse alsamixer
  3542. * So call somewhat different..
  3543. */
  3544. /* .name = "Capture Source", */
  3545. .name = "Input Source",
  3546. .count = 2,
  3547. .info = ad198x_mux_enum_info,
  3548. .get = ad198x_mux_enum_get,
  3549. .put = ad198x_mux_enum_put,
  3550. },
  3551. /* SPDIF controls */
  3552. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  3553. {
  3554. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3555. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  3556. /* identical with ad1983 */
  3557. .info = ad1983_spdif_route_info,
  3558. .get = ad1983_spdif_route_get,
  3559. .put = ad1983_spdif_route_put,
  3560. },
  3561. { } /* end */
  3562. };
  3563. /*
  3564. * initialization verbs
  3565. */
  3566. static const struct hda_verb ad1884a_init_verbs[] = {
  3567. /* DACs; unmute as default */
  3568. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3569. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3570. /* Port-A (HP) mixer - route only from analog mixer */
  3571. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3572. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3573. /* Port-A pin */
  3574. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3575. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3576. /* Port-D (Line-out) mixer - route only from analog mixer */
  3577. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3578. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3579. /* Port-D pin */
  3580. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3581. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3582. /* Mono-out mixer - route only from analog mixer */
  3583. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3584. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3585. /* Mono-out pin */
  3586. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3587. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3588. /* Port-B (front mic) pin */
  3589. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3590. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3591. /* Port-C (rear line-in) pin */
  3592. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3593. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3594. /* Port-E (rear mic) pin */
  3595. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3596. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3597. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
  3598. /* Port-F (CD) pin */
  3599. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3600. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3601. /* Analog mixer; mute as default */
  3602. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3603. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3604. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3605. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3606. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
  3607. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3608. /* Analog Mix output amp */
  3609. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3610. /* capture sources */
  3611. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
  3612. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3613. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3614. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3615. /* SPDIF output amp */
  3616. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  3617. { } /* end */
  3618. };
  3619. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3620. static const struct hda_amp_list ad1884a_loopbacks[] = {
  3621. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  3622. { 0x20, HDA_INPUT, 1 }, /* Mic */
  3623. { 0x20, HDA_INPUT, 2 }, /* CD */
  3624. { 0x20, HDA_INPUT, 4 }, /* Docking */
  3625. { } /* end */
  3626. };
  3627. #endif
  3628. /*
  3629. * Laptop model
  3630. *
  3631. * Port A: Headphone jack
  3632. * Port B: MIC jack
  3633. * Port C: Internal MIC
  3634. * Port D: Dock Line Out (if enabled)
  3635. * Port E: Dock Line In (if enabled)
  3636. * Port F: Internal speakers
  3637. */
  3638. static int ad1884a_mobile_master_sw_put(struct snd_kcontrol *kcontrol,
  3639. struct snd_ctl_elem_value *ucontrol)
  3640. {
  3641. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3642. int ret = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  3643. int mute = (!ucontrol->value.integer.value[0] &&
  3644. !ucontrol->value.integer.value[1]);
  3645. /* toggle GPIO1 according to the mute state */
  3646. snd_hda_codec_write_cache(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
  3647. mute ? 0x02 : 0x0);
  3648. return ret;
  3649. }
  3650. static const struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
  3651. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3652. {
  3653. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3654. .name = "Master Playback Switch",
  3655. .subdevice = HDA_SUBDEV_AMP_FLAG,
  3656. .info = snd_hda_mixer_amp_switch_info,
  3657. .get = snd_hda_mixer_amp_switch_get,
  3658. .put = ad1884a_mobile_master_sw_put,
  3659. .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  3660. },
  3661. HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3662. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3663. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3664. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3665. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3666. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  3667. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  3668. HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  3669. HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  3670. HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3671. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  3672. HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  3673. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3674. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3675. { } /* end */
  3676. };
  3677. static const struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
  3678. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3679. /*HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
  3680. {
  3681. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3682. .name = "Master Playback Switch",
  3683. .subdevice = HDA_SUBDEV_AMP_FLAG,
  3684. .info = snd_hda_mixer_amp_switch_info,
  3685. .get = snd_hda_mixer_amp_switch_get,
  3686. .put = ad1884a_mobile_master_sw_put,
  3687. .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  3688. },
  3689. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3690. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3691. HDA_CODEC_VOLUME("Mic Capture Volume", 0x14, 0x0, HDA_INPUT),
  3692. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x15, 0x0, HDA_INPUT),
  3693. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3694. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3695. { } /* end */
  3696. };
  3697. /* mute internal speaker if HP is plugged */
  3698. static void ad1884a_hp_automute(struct hda_codec *codec)
  3699. {
  3700. unsigned int present;
  3701. present = snd_hda_jack_detect(codec, 0x11);
  3702. snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
  3703. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3704. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
  3705. present ? 0x00 : 0x02);
  3706. }
  3707. /* switch to external mic if plugged */
  3708. static void ad1884a_hp_automic(struct hda_codec *codec)
  3709. {
  3710. unsigned int present;
  3711. present = snd_hda_jack_detect(codec, 0x14);
  3712. snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL,
  3713. present ? 0 : 1);
  3714. }
  3715. #define AD1884A_HP_EVENT 0x37
  3716. #define AD1884A_MIC_EVENT 0x36
  3717. /* unsolicited event for HP jack sensing */
  3718. static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
  3719. {
  3720. switch (res >> 26) {
  3721. case AD1884A_HP_EVENT:
  3722. ad1884a_hp_automute(codec);
  3723. break;
  3724. case AD1884A_MIC_EVENT:
  3725. ad1884a_hp_automic(codec);
  3726. break;
  3727. }
  3728. }
  3729. /* initialize jack-sensing, too */
  3730. static int ad1884a_hp_init(struct hda_codec *codec)
  3731. {
  3732. ad198x_init(codec);
  3733. ad1884a_hp_automute(codec);
  3734. ad1884a_hp_automic(codec);
  3735. return 0;
  3736. }
  3737. /* mute internal speaker if HP or docking HP is plugged */
  3738. static void ad1884a_laptop_automute(struct hda_codec *codec)
  3739. {
  3740. unsigned int present;
  3741. present = snd_hda_jack_detect(codec, 0x11);
  3742. if (!present)
  3743. present = snd_hda_jack_detect(codec, 0x12);
  3744. snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
  3745. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3746. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
  3747. present ? 0x00 : 0x02);
  3748. }
  3749. /* switch to external mic if plugged */
  3750. static void ad1884a_laptop_automic(struct hda_codec *codec)
  3751. {
  3752. unsigned int idx;
  3753. if (snd_hda_jack_detect(codec, 0x14))
  3754. idx = 0;
  3755. else if (snd_hda_jack_detect(codec, 0x1c))
  3756. idx = 4;
  3757. else
  3758. idx = 1;
  3759. snd_hda_codec_write(codec, 0x0c, 0, AC_VERB_SET_CONNECT_SEL, idx);
  3760. }
  3761. /* unsolicited event for HP jack sensing */
  3762. static void ad1884a_laptop_unsol_event(struct hda_codec *codec,
  3763. unsigned int res)
  3764. {
  3765. switch (res >> 26) {
  3766. case AD1884A_HP_EVENT:
  3767. ad1884a_laptop_automute(codec);
  3768. break;
  3769. case AD1884A_MIC_EVENT:
  3770. ad1884a_laptop_automic(codec);
  3771. break;
  3772. }
  3773. }
  3774. /* initialize jack-sensing, too */
  3775. static int ad1884a_laptop_init(struct hda_codec *codec)
  3776. {
  3777. ad198x_init(codec);
  3778. ad1884a_laptop_automute(codec);
  3779. ad1884a_laptop_automic(codec);
  3780. return 0;
  3781. }
  3782. /* additional verbs for laptop model */
  3783. static const struct hda_verb ad1884a_laptop_verbs[] = {
  3784. /* Port-A (HP) pin - always unmuted */
  3785. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3786. /* Port-F (int speaker) mixer - route only from analog mixer */
  3787. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3788. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3789. /* Port-F (int speaker) pin */
  3790. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3791. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3792. /* required for compaq 6530s/6531s speaker output */
  3793. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3794. /* Port-C pin - internal mic-in */
  3795. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3796. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3797. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3798. /* Port-D (docking line-out) pin - default unmuted */
  3799. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3800. /* analog mix */
  3801. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3802. /* unsolicited event for pin-sense */
  3803. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3804. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3805. {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3806. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3807. /* allow to touch GPIO1 (for mute control) */
  3808. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  3809. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  3810. {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  3811. { } /* end */
  3812. };
  3813. static const struct hda_verb ad1884a_mobile_verbs[] = {
  3814. /* DACs; unmute as default */
  3815. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3816. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3817. /* Port-A (HP) mixer - route only from analog mixer */
  3818. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3819. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3820. /* Port-A pin */
  3821. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3822. /* Port-A (HP) pin - always unmuted */
  3823. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3824. /* Port-B (mic jack) pin */
  3825. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3826. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3827. /* Port-C (int mic) pin */
  3828. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3829. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3830. /* Port-F (int speaker) mixer - route only from analog mixer */
  3831. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3832. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3833. /* Port-F pin */
  3834. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3835. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3836. /* Analog mixer; mute as default */
  3837. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3838. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3839. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3840. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3841. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3842. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  3843. /* Analog Mix output amp */
  3844. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3845. /* capture sources */
  3846. /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
  3847. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3848. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  3849. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3850. /* unsolicited event for pin-sense */
  3851. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3852. {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  3853. /* allow to touch GPIO1 (for mute control) */
  3854. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  3855. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  3856. {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  3857. { } /* end */
  3858. };
  3859. /*
  3860. * Thinkpad X300
  3861. * 0x11 - HP
  3862. * 0x12 - speaker
  3863. * 0x14 - mic-in
  3864. * 0x17 - built-in mic
  3865. */
  3866. static const struct hda_verb ad1984a_thinkpad_verbs[] = {
  3867. /* HP unmute */
  3868. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3869. /* analog mix */
  3870. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3871. /* turn on EAPD */
  3872. {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  3873. /* unsolicited event for pin-sense */
  3874. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3875. /* internal mic - dmic */
  3876. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3877. /* set magic COEFs for dmic */
  3878. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  3879. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  3880. { } /* end */
  3881. };
  3882. static const struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
  3883. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3884. HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  3885. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3886. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3887. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  3888. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  3889. HDA_CODEC_VOLUME("Mic Boost Volume", 0x14, 0x0, HDA_INPUT),
  3890. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
  3891. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3892. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3893. {
  3894. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3895. .name = "Capture Source",
  3896. .info = ad198x_mux_enum_info,
  3897. .get = ad198x_mux_enum_get,
  3898. .put = ad198x_mux_enum_put,
  3899. },
  3900. { } /* end */
  3901. };
  3902. static const struct hda_input_mux ad1984a_thinkpad_capture_source = {
  3903. .num_items = 3,
  3904. .items = {
  3905. { "Mic", 0x0 },
  3906. { "Internal Mic", 0x5 },
  3907. { "Mix", 0x3 },
  3908. },
  3909. };
  3910. /* mute internal speaker if HP is plugged */
  3911. static void ad1984a_thinkpad_automute(struct hda_codec *codec)
  3912. {
  3913. unsigned int present;
  3914. present = snd_hda_jack_detect(codec, 0x11);
  3915. snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
  3916. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3917. }
  3918. /* unsolicited event for HP jack sensing */
  3919. static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
  3920. unsigned int res)
  3921. {
  3922. if ((res >> 26) != AD1884A_HP_EVENT)
  3923. return;
  3924. ad1984a_thinkpad_automute(codec);
  3925. }
  3926. /* initialize jack-sensing, too */
  3927. static int ad1984a_thinkpad_init(struct hda_codec *codec)
  3928. {
  3929. ad198x_init(codec);
  3930. ad1984a_thinkpad_automute(codec);
  3931. return 0;
  3932. }
  3933. /*
  3934. * Precision R5500
  3935. * 0x12 - HP/line-out
  3936. * 0x13 - speaker (mono)
  3937. * 0x15 - mic-in
  3938. */
  3939. static const struct hda_verb ad1984a_precision_verbs[] = {
  3940. /* Unmute main output path */
  3941. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  3942. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x1f}, /* 0dB */
  3943. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(5) + 0x17}, /* 0dB */
  3944. /* Analog mixer; mute as default */
  3945. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3946. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3947. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3948. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3949. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3950. /* Select mic as input */
  3951. {0x0c, AC_VERB_SET_CONNECT_SEL, 0x1},
  3952. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE + 0x27}, /* 0dB */
  3953. /* Configure as mic */
  3954. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3955. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x7002}, /* raise mic as default */
  3956. /* HP unmute */
  3957. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3958. /* turn on EAPD */
  3959. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  3960. /* unsolicited event for pin-sense */
  3961. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  3962. { } /* end */
  3963. };
  3964. static const struct snd_kcontrol_new ad1984a_precision_mixers[] = {
  3965. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  3966. HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
  3967. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  3968. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  3969. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  3970. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  3971. HDA_CODEC_VOLUME("Mic Boost Volume", 0x15, 0x0, HDA_INPUT),
  3972. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  3973. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  3974. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  3975. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  3976. { } /* end */
  3977. };
  3978. /* mute internal speaker if HP is plugged */
  3979. static void ad1984a_precision_automute(struct hda_codec *codec)
  3980. {
  3981. unsigned int present;
  3982. present = snd_hda_jack_detect(codec, 0x12);
  3983. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  3984. HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
  3985. }
  3986. /* unsolicited event for HP jack sensing */
  3987. static void ad1984a_precision_unsol_event(struct hda_codec *codec,
  3988. unsigned int res)
  3989. {
  3990. if ((res >> 26) != AD1884A_HP_EVENT)
  3991. return;
  3992. ad1984a_precision_automute(codec);
  3993. }
  3994. /* initialize jack-sensing, too */
  3995. static int ad1984a_precision_init(struct hda_codec *codec)
  3996. {
  3997. ad198x_init(codec);
  3998. ad1984a_precision_automute(codec);
  3999. return 0;
  4000. }
  4001. /*
  4002. * HP Touchsmart
  4003. * port-A (0x11) - front hp-out
  4004. * port-B (0x14) - unused
  4005. * port-C (0x15) - unused
  4006. * port-D (0x12) - rear line out
  4007. * port-E (0x1c) - front mic-in
  4008. * port-F (0x16) - Internal speakers
  4009. * digital-mic (0x17) - Internal mic
  4010. */
  4011. static const struct hda_verb ad1984a_touchsmart_verbs[] = {
  4012. /* DACs; unmute as default */
  4013. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  4014. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
  4015. /* Port-A (HP) mixer - route only from analog mixer */
  4016. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4017. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4018. /* Port-A pin */
  4019. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4020. /* Port-A (HP) pin - always unmuted */
  4021. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4022. /* Port-E (int speaker) mixer - route only from analog mixer */
  4023. {0x25, AC_VERB_SET_AMP_GAIN_MUTE, 0x03},
  4024. /* Port-E pin */
  4025. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  4026. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4027. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4028. /* Port-F (int speaker) mixer - route only from analog mixer */
  4029. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4030. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4031. /* Port-F pin */
  4032. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4033. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4034. /* Analog mixer; mute as default */
  4035. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4036. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4037. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4038. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4039. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4040. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  4041. /* Analog Mix output amp */
  4042. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4043. /* capture sources */
  4044. /* {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0}, */ /* set via unsol */
  4045. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4046. {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
  4047. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4048. /* unsolicited event for pin-sense */
  4049. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
  4050. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_MIC_EVENT},
  4051. /* allow to touch GPIO1 (for mute control) */
  4052. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  4053. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  4054. {0x01, AC_VERB_SET_GPIO_DATA, 0x02}, /* first muted */
  4055. /* internal mic - dmic */
  4056. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  4057. /* set magic COEFs for dmic */
  4058. {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
  4059. {0x01, AC_VERB_SET_PROC_COEF, 0x08},
  4060. { } /* end */
  4061. };
  4062. static const struct snd_kcontrol_new ad1984a_touchsmart_mixers[] = {
  4063. HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
  4064. /* HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),*/
  4065. {
  4066. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4067. .subdevice = HDA_SUBDEV_AMP_FLAG,
  4068. .name = "Master Playback Switch",
  4069. .info = snd_hda_mixer_amp_switch_info,
  4070. .get = snd_hda_mixer_amp_switch_get,
  4071. .put = ad1884a_mobile_master_sw_put,
  4072. .private_value = HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
  4073. },
  4074. HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
  4075. HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
  4076. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  4077. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  4078. HDA_CODEC_VOLUME("Mic Boost Volume", 0x25, 0x0, HDA_OUTPUT),
  4079. HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x17, 0x0, HDA_INPUT),
  4080. { } /* end */
  4081. };
  4082. /* switch to external mic if plugged */
  4083. static void ad1984a_touchsmart_automic(struct hda_codec *codec)
  4084. {
  4085. if (snd_hda_jack_detect(codec, 0x1c))
  4086. snd_hda_codec_write(codec, 0x0c, 0,
  4087. AC_VERB_SET_CONNECT_SEL, 0x4);
  4088. else
  4089. snd_hda_codec_write(codec, 0x0c, 0,
  4090. AC_VERB_SET_CONNECT_SEL, 0x5);
  4091. }
  4092. /* unsolicited event for HP jack sensing */
  4093. static void ad1984a_touchsmart_unsol_event(struct hda_codec *codec,
  4094. unsigned int res)
  4095. {
  4096. switch (res >> 26) {
  4097. case AD1884A_HP_EVENT:
  4098. ad1884a_hp_automute(codec);
  4099. break;
  4100. case AD1884A_MIC_EVENT:
  4101. ad1984a_touchsmart_automic(codec);
  4102. break;
  4103. }
  4104. }
  4105. /* initialize jack-sensing, too */
  4106. static int ad1984a_touchsmart_init(struct hda_codec *codec)
  4107. {
  4108. ad198x_init(codec);
  4109. ad1884a_hp_automute(codec);
  4110. ad1984a_touchsmart_automic(codec);
  4111. return 0;
  4112. }
  4113. /*
  4114. */
  4115. enum {
  4116. AD1884A_DESKTOP,
  4117. AD1884A_LAPTOP,
  4118. AD1884A_MOBILE,
  4119. AD1884A_THINKPAD,
  4120. AD1984A_TOUCHSMART,
  4121. AD1984A_PRECISION,
  4122. AD1884A_MODELS
  4123. };
  4124. static const char * const ad1884a_models[AD1884A_MODELS] = {
  4125. [AD1884A_DESKTOP] = "desktop",
  4126. [AD1884A_LAPTOP] = "laptop",
  4127. [AD1884A_MOBILE] = "mobile",
  4128. [AD1884A_THINKPAD] = "thinkpad",
  4129. [AD1984A_TOUCHSMART] = "touchsmart",
  4130. [AD1984A_PRECISION] = "precision",
  4131. };
  4132. static const struct snd_pci_quirk ad1884a_cfg_tbl[] = {
  4133. SND_PCI_QUIRK(0x1028, 0x04ac, "Precision R5500", AD1984A_PRECISION),
  4134. SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
  4135. SND_PCI_QUIRK(0x103c, 0x3037, "HP 2230s", AD1884A_LAPTOP),
  4136. SND_PCI_QUIRK(0x103c, 0x3056, "HP", AD1884A_MOBILE),
  4137. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x3070, "HP", AD1884A_MOBILE),
  4138. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30d0, "HP laptop", AD1884A_LAPTOP),
  4139. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x30e0, "HP laptop", AD1884A_LAPTOP),
  4140. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3600, "HP laptop", AD1884A_LAPTOP),
  4141. SND_PCI_QUIRK_MASK(0x103c, 0xfff0, 0x7010, "HP laptop", AD1884A_MOBILE),
  4142. SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
  4143. SND_PCI_QUIRK(0x103c, 0x2a82, "Touchsmart", AD1984A_TOUCHSMART),
  4144. {}
  4145. };
  4146. static int patch_ad1884a(struct hda_codec *codec)
  4147. {
  4148. struct ad198x_spec *spec;
  4149. int err, board_config;
  4150. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4151. if (spec == NULL)
  4152. return -ENOMEM;
  4153. codec->spec = spec;
  4154. err = snd_hda_attach_beep_device(codec, 0x10);
  4155. if (err < 0) {
  4156. ad198x_free(codec);
  4157. return err;
  4158. }
  4159. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  4160. spec->multiout.max_channels = 2;
  4161. spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
  4162. spec->multiout.dac_nids = ad1884a_dac_nids;
  4163. spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
  4164. spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
  4165. spec->adc_nids = ad1884a_adc_nids;
  4166. spec->capsrc_nids = ad1884a_capsrc_nids;
  4167. spec->input_mux = &ad1884a_capture_source;
  4168. spec->num_mixers = 1;
  4169. spec->mixers[0] = ad1884a_base_mixers;
  4170. spec->num_init_verbs = 1;
  4171. spec->init_verbs[0] = ad1884a_init_verbs;
  4172. spec->spdif_route = 0;
  4173. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4174. spec->loopback.amplist = ad1884a_loopbacks;
  4175. #endif
  4176. codec->patch_ops = ad198x_patch_ops;
  4177. /* override some parameters */
  4178. board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
  4179. ad1884a_models,
  4180. ad1884a_cfg_tbl);
  4181. switch (board_config) {
  4182. case AD1884A_LAPTOP:
  4183. spec->mixers[0] = ad1884a_laptop_mixers;
  4184. spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
  4185. spec->multiout.dig_out_nid = 0;
  4186. codec->patch_ops.unsol_event = ad1884a_laptop_unsol_event;
  4187. codec->patch_ops.init = ad1884a_laptop_init;
  4188. /* set the upper-limit for mixer amp to 0dB for avoiding the
  4189. * possible damage by overloading
  4190. */
  4191. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  4192. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  4193. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  4194. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  4195. (1 << AC_AMPCAP_MUTE_SHIFT));
  4196. break;
  4197. case AD1884A_MOBILE:
  4198. spec->mixers[0] = ad1884a_mobile_mixers;
  4199. spec->init_verbs[0] = ad1884a_mobile_verbs;
  4200. spec->multiout.dig_out_nid = 0;
  4201. codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
  4202. codec->patch_ops.init = ad1884a_hp_init;
  4203. /* set the upper-limit for mixer amp to 0dB for avoiding the
  4204. * possible damage by overloading
  4205. */
  4206. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  4207. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  4208. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  4209. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  4210. (1 << AC_AMPCAP_MUTE_SHIFT));
  4211. break;
  4212. case AD1884A_THINKPAD:
  4213. spec->mixers[0] = ad1984a_thinkpad_mixers;
  4214. spec->init_verbs[spec->num_init_verbs++] =
  4215. ad1984a_thinkpad_verbs;
  4216. spec->multiout.dig_out_nid = 0;
  4217. spec->input_mux = &ad1984a_thinkpad_capture_source;
  4218. codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
  4219. codec->patch_ops.init = ad1984a_thinkpad_init;
  4220. break;
  4221. case AD1984A_PRECISION:
  4222. spec->mixers[0] = ad1984a_precision_mixers;
  4223. spec->init_verbs[spec->num_init_verbs++] =
  4224. ad1984a_precision_verbs;
  4225. spec->multiout.dig_out_nid = 0;
  4226. codec->patch_ops.unsol_event = ad1984a_precision_unsol_event;
  4227. codec->patch_ops.init = ad1984a_precision_init;
  4228. break;
  4229. case AD1984A_TOUCHSMART:
  4230. spec->mixers[0] = ad1984a_touchsmart_mixers;
  4231. spec->init_verbs[0] = ad1984a_touchsmart_verbs;
  4232. spec->multiout.dig_out_nid = 0;
  4233. codec->patch_ops.unsol_event = ad1984a_touchsmart_unsol_event;
  4234. codec->patch_ops.init = ad1984a_touchsmart_init;
  4235. /* set the upper-limit for mixer amp to 0dB for avoiding the
  4236. * possible damage by overloading
  4237. */
  4238. snd_hda_override_amp_caps(codec, 0x20, HDA_INPUT,
  4239. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  4240. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  4241. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  4242. (1 << AC_AMPCAP_MUTE_SHIFT));
  4243. break;
  4244. }
  4245. codec->no_trigger_sense = 1;
  4246. codec->no_sticky_stream = 1;
  4247. return 0;
  4248. }
  4249. /*
  4250. * AD1882 / AD1882A
  4251. *
  4252. * port-A - front hp-out
  4253. * port-B - front mic-in
  4254. * port-C - rear line-in, shared surr-out (3stack)
  4255. * port-D - rear line-out
  4256. * port-E - rear mic-in, shared clfe-out (3stack)
  4257. * port-F - rear surr-out (6stack)
  4258. * port-G - rear clfe-out (6stack)
  4259. */
  4260. static const hda_nid_t ad1882_dac_nids[3] = {
  4261. 0x04, 0x03, 0x05
  4262. };
  4263. static const hda_nid_t ad1882_adc_nids[2] = {
  4264. 0x08, 0x09,
  4265. };
  4266. static const hda_nid_t ad1882_capsrc_nids[2] = {
  4267. 0x0c, 0x0d,
  4268. };
  4269. #define AD1882_SPDIF_OUT 0x02
  4270. /* list: 0x11, 0x39, 0x3a, 0x18, 0x3c, 0x3b, 0x12, 0x20 */
  4271. static const struct hda_input_mux ad1882_capture_source = {
  4272. .num_items = 5,
  4273. .items = {
  4274. { "Front Mic", 0x1 },
  4275. { "Mic", 0x4 },
  4276. { "Line", 0x2 },
  4277. { "CD", 0x3 },
  4278. { "Mix", 0x7 },
  4279. },
  4280. };
  4281. /* list: 0x11, 0x39, 0x3a, 0x3c, 0x18, 0x1f, 0x12, 0x20 */
  4282. static const struct hda_input_mux ad1882a_capture_source = {
  4283. .num_items = 5,
  4284. .items = {
  4285. { "Front Mic", 0x1 },
  4286. { "Mic", 0x4},
  4287. { "Line", 0x2 },
  4288. { "Digital Mic", 0x06 },
  4289. { "Mix", 0x7 },
  4290. },
  4291. };
  4292. static const struct snd_kcontrol_new ad1882_base_mixers[] = {
  4293. HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
  4294. HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
  4295. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x05, 1, 0x0, HDA_OUTPUT),
  4296. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x05, 2, 0x0, HDA_OUTPUT),
  4297. HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  4298. HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  4299. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  4300. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
  4301. HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
  4302. HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
  4303. HDA_CODEC_VOLUME("Line-In Boost Volume", 0x3a, 0x0, HDA_OUTPUT),
  4304. HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
  4305. HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
  4306. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
  4307. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
  4308. {
  4309. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4310. /* The multiple "Capture Source" controls confuse alsamixer
  4311. * So call somewhat different..
  4312. */
  4313. /* .name = "Capture Source", */
  4314. .name = "Input Source",
  4315. .count = 2,
  4316. .info = ad198x_mux_enum_info,
  4317. .get = ad198x_mux_enum_get,
  4318. .put = ad198x_mux_enum_put,
  4319. },
  4320. /* SPDIF controls */
  4321. HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
  4322. {
  4323. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4324. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
  4325. /* identical with ad1983 */
  4326. .info = ad1983_spdif_route_info,
  4327. .get = ad1983_spdif_route_get,
  4328. .put = ad1983_spdif_route_put,
  4329. },
  4330. { } /* end */
  4331. };
  4332. static const struct snd_kcontrol_new ad1882_loopback_mixers[] = {
  4333. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  4334. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  4335. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
  4336. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
  4337. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x04, HDA_INPUT),
  4338. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x04, HDA_INPUT),
  4339. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
  4340. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
  4341. { } /* end */
  4342. };
  4343. static const struct snd_kcontrol_new ad1882a_loopback_mixers[] = {
  4344. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
  4345. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
  4346. HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
  4347. HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
  4348. HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
  4349. HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
  4350. HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x06, HDA_INPUT),
  4351. HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x06, HDA_INPUT),
  4352. HDA_CODEC_VOLUME("Digital Mic Boost Volume", 0x1f, 0x0, HDA_INPUT),
  4353. { } /* end */
  4354. };
  4355. static const struct snd_kcontrol_new ad1882_3stack_mixers[] = {
  4356. HDA_CODEC_MUTE("Surround Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  4357. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x17, 1, 0x0, HDA_OUTPUT),
  4358. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x17, 2, 0x0, HDA_OUTPUT),
  4359. {
  4360. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4361. .name = "Channel Mode",
  4362. .info = ad198x_ch_mode_info,
  4363. .get = ad198x_ch_mode_get,
  4364. .put = ad198x_ch_mode_put,
  4365. },
  4366. { } /* end */
  4367. };
  4368. static const struct snd_kcontrol_new ad1882_6stack_mixers[] = {
  4369. HDA_CODEC_MUTE("Surround Playback Switch", 0x16, 0x0, HDA_OUTPUT),
  4370. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x24, 1, 0x0, HDA_OUTPUT),
  4371. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x24, 2, 0x0, HDA_OUTPUT),
  4372. { } /* end */
  4373. };
  4374. static const struct hda_verb ad1882_ch2_init[] = {
  4375. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  4376. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4377. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4378. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4379. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4380. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4381. { } /* end */
  4382. };
  4383. static const struct hda_verb ad1882_ch4_init[] = {
  4384. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4385. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4386. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4387. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4388. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4389. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4390. { } /* end */
  4391. };
  4392. static const struct hda_verb ad1882_ch6_init[] = {
  4393. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4394. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4395. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4396. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4397. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4398. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4399. { } /* end */
  4400. };
  4401. static const struct hda_channel_mode ad1882_modes[3] = {
  4402. { 2, ad1882_ch2_init },
  4403. { 4, ad1882_ch4_init },
  4404. { 6, ad1882_ch6_init },
  4405. };
  4406. /*
  4407. * initialization verbs
  4408. */
  4409. static const struct hda_verb ad1882_init_verbs[] = {
  4410. /* DACs; mute as default */
  4411. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  4412. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  4413. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  4414. /* Port-A (HP) mixer */
  4415. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4416. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4417. /* Port-A pin */
  4418. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4419. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4420. /* HP selector - select DAC2 */
  4421. {0x37, AC_VERB_SET_CONNECT_SEL, 0x1},
  4422. /* Port-D (Line-out) mixer */
  4423. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4424. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4425. /* Port-D pin */
  4426. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4427. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4428. /* Mono-out mixer */
  4429. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4430. {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4431. /* Mono-out pin */
  4432. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  4433. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4434. /* Port-B (front mic) pin */
  4435. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4436. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4437. {0x39, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  4438. /* Port-C (line-in) pin */
  4439. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  4440. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4441. {0x3a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  4442. /* Port-C mixer - mute as input */
  4443. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4444. {0x2c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4445. /* Port-E (mic-in) pin */
  4446. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  4447. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4448. {0x3c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* boost */
  4449. /* Port-E mixer - mute as input */
  4450. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4451. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4452. /* Port-F (surround) */
  4453. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4454. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4455. /* Port-G (CLFE) */
  4456. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  4457. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4458. /* Analog mixer; mute as default */
  4459. /* list: 0x39, 0x3a, 0x11, 0x12, 0x3c, 0x3b, 0x18, 0x1a */
  4460. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4461. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4462. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  4463. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  4464. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  4465. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
  4466. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
  4467. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
  4468. /* Analog Mix output amp */
  4469. {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x1f}, /* 0dB */
  4470. /* SPDIF output selector */
  4471. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  4472. {0x02, AC_VERB_SET_CONNECT_SEL, 0x0}, /* PCM */
  4473. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
  4474. { } /* end */
  4475. };
  4476. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4477. static const struct hda_amp_list ad1882_loopbacks[] = {
  4478. { 0x20, HDA_INPUT, 0 }, /* Front Mic */
  4479. { 0x20, HDA_INPUT, 1 }, /* Mic */
  4480. { 0x20, HDA_INPUT, 4 }, /* Line */
  4481. { 0x20, HDA_INPUT, 6 }, /* CD */
  4482. { } /* end */
  4483. };
  4484. #endif
  4485. /* models */
  4486. enum {
  4487. AD1882_3STACK,
  4488. AD1882_6STACK,
  4489. AD1882_MODELS
  4490. };
  4491. static const char * const ad1882_models[AD1986A_MODELS] = {
  4492. [AD1882_3STACK] = "3stack",
  4493. [AD1882_6STACK] = "6stack",
  4494. };
  4495. static int patch_ad1882(struct hda_codec *codec)
  4496. {
  4497. struct ad198x_spec *spec;
  4498. int err, board_config;
  4499. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  4500. if (spec == NULL)
  4501. return -ENOMEM;
  4502. codec->spec = spec;
  4503. err = snd_hda_attach_beep_device(codec, 0x10);
  4504. if (err < 0) {
  4505. ad198x_free(codec);
  4506. return err;
  4507. }
  4508. set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
  4509. spec->multiout.max_channels = 6;
  4510. spec->multiout.num_dacs = 3;
  4511. spec->multiout.dac_nids = ad1882_dac_nids;
  4512. spec->multiout.dig_out_nid = AD1882_SPDIF_OUT;
  4513. spec->num_adc_nids = ARRAY_SIZE(ad1882_adc_nids);
  4514. spec->adc_nids = ad1882_adc_nids;
  4515. spec->capsrc_nids = ad1882_capsrc_nids;
  4516. if (codec->vendor_id == 0x11d41882)
  4517. spec->input_mux = &ad1882_capture_source;
  4518. else
  4519. spec->input_mux = &ad1882a_capture_source;
  4520. spec->num_mixers = 2;
  4521. spec->mixers[0] = ad1882_base_mixers;
  4522. if (codec->vendor_id == 0x11d41882)
  4523. spec->mixers[1] = ad1882_loopback_mixers;
  4524. else
  4525. spec->mixers[1] = ad1882a_loopback_mixers;
  4526. spec->num_init_verbs = 1;
  4527. spec->init_verbs[0] = ad1882_init_verbs;
  4528. spec->spdif_route = 0;
  4529. #ifdef CONFIG_SND_HDA_POWER_SAVE
  4530. spec->loopback.amplist = ad1882_loopbacks;
  4531. #endif
  4532. spec->vmaster_nid = 0x04;
  4533. codec->patch_ops = ad198x_patch_ops;
  4534. /* override some parameters */
  4535. board_config = snd_hda_check_board_config(codec, AD1882_MODELS,
  4536. ad1882_models, NULL);
  4537. switch (board_config) {
  4538. default:
  4539. case AD1882_3STACK:
  4540. spec->num_mixers = 3;
  4541. spec->mixers[2] = ad1882_3stack_mixers;
  4542. spec->channel_mode = ad1882_modes;
  4543. spec->num_channel_mode = ARRAY_SIZE(ad1882_modes);
  4544. spec->need_dac_fix = 1;
  4545. spec->multiout.max_channels = 2;
  4546. spec->multiout.num_dacs = 1;
  4547. break;
  4548. case AD1882_6STACK:
  4549. spec->num_mixers = 3;
  4550. spec->mixers[2] = ad1882_6stack_mixers;
  4551. break;
  4552. }
  4553. codec->no_trigger_sense = 1;
  4554. codec->no_sticky_stream = 1;
  4555. return 0;
  4556. }
  4557. /*
  4558. * patch entries
  4559. */
  4560. static const struct hda_codec_preset snd_hda_preset_analog[] = {
  4561. { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
  4562. { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
  4563. { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
  4564. { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
  4565. { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
  4566. { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
  4567. { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
  4568. { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
  4569. { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
  4570. { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
  4571. { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
  4572. { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
  4573. { .id = 0x11d4882a, .name = "AD1882A", .patch = patch_ad1882 },
  4574. { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
  4575. { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
  4576. {} /* terminator */
  4577. };
  4578. MODULE_ALIAS("snd-hda-codec-id:11d4*");
  4579. MODULE_LICENSE("GPL");
  4580. MODULE_DESCRIPTION("Analog Devices HD-audio codec");
  4581. static struct hda_codec_preset_list analog_list = {
  4582. .preset = snd_hda_preset_analog,
  4583. .owner = THIS_MODULE,
  4584. };
  4585. static int __init patch_analog_init(void)
  4586. {
  4587. return snd_hda_add_codec_preset(&analog_list);
  4588. }
  4589. static void __exit patch_analog_exit(void)
  4590. {
  4591. snd_hda_delete_codec_preset(&analog_list);
  4592. }
  4593. module_init(patch_analog_init)
  4594. module_exit(patch_analog_exit)