patch_realtek.c 172 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for ALC 260/880/882 codecs
  5. *
  6. * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
  7. * PeiSen Hou <pshou@realtek.com.tw>
  8. * Takashi Iwai <tiwai@suse.de>
  9. * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
  10. *
  11. * This driver is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This driver is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <sound/driver.h>
  26. #include <linux/init.h>
  27. #include <linux/delay.h>
  28. #include <linux/slab.h>
  29. #include <linux/pci.h>
  30. #include <sound/core.h>
  31. #include "hda_codec.h"
  32. #include "hda_local.h"
  33. /* ALC880 board config type */
  34. enum {
  35. ALC880_3ST,
  36. ALC880_3ST_DIG,
  37. ALC880_5ST,
  38. ALC880_5ST_DIG,
  39. ALC880_W810,
  40. ALC880_Z71V,
  41. ALC880_6ST,
  42. ALC880_6ST_DIG,
  43. ALC880_F1734,
  44. ALC880_ASUS,
  45. ALC880_ASUS_DIG,
  46. ALC880_ASUS_W1V,
  47. ALC880_ASUS_DIG2,
  48. ALC880_UNIWILL_DIG,
  49. ALC880_CLEVO,
  50. ALC880_TCL_S700,
  51. #ifdef CONFIG_SND_DEBUG
  52. ALC880_TEST,
  53. #endif
  54. ALC880_AUTO,
  55. ALC880_MODEL_LAST /* last tag */
  56. };
  57. /* ALC260 models */
  58. enum {
  59. ALC260_BASIC,
  60. ALC260_HP,
  61. ALC260_HP_3013,
  62. ALC260_FUJITSU_S702X,
  63. #ifdef CONFIG_SND_DEBUG
  64. ALC260_TEST,
  65. #endif
  66. ALC260_AUTO,
  67. ALC260_MODEL_LAST /* last tag */
  68. };
  69. /* ALC262 models */
  70. enum {
  71. ALC262_BASIC,
  72. ALC262_AUTO,
  73. ALC262_MODEL_LAST /* last tag */
  74. };
  75. /* ALC861 models */
  76. enum {
  77. ALC861_3ST,
  78. ALC861_3ST_DIG,
  79. ALC861_6ST_DIG,
  80. ALC861_AUTO,
  81. ALC861_MODEL_LAST,
  82. };
  83. /* ALC882 models */
  84. enum {
  85. ALC882_3ST_DIG,
  86. ALC882_6ST_DIG,
  87. ALC882_AUTO,
  88. ALC882_MODEL_LAST,
  89. };
  90. /* for GPIO Poll */
  91. #define GPIO_MASK 0x03
  92. struct alc_spec {
  93. /* codec parameterization */
  94. struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
  95. unsigned int num_mixers;
  96. const struct hda_verb *init_verbs[5]; /* initialization verbs
  97. * don't forget NULL termination!
  98. */
  99. unsigned int num_init_verbs;
  100. char *stream_name_analog; /* analog PCM stream */
  101. struct hda_pcm_stream *stream_analog_playback;
  102. struct hda_pcm_stream *stream_analog_capture;
  103. char *stream_name_digital; /* digital PCM stream */
  104. struct hda_pcm_stream *stream_digital_playback;
  105. struct hda_pcm_stream *stream_digital_capture;
  106. /* playback */
  107. struct hda_multi_out multiout; /* playback set-up
  108. * max_channels, dacs must be set
  109. * dig_out_nid and hp_nid are optional
  110. */
  111. /* capture */
  112. unsigned int num_adc_nids;
  113. hda_nid_t *adc_nids;
  114. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  115. /* capture source */
  116. const struct hda_input_mux *input_mux;
  117. unsigned int cur_mux[3];
  118. /* channel model */
  119. const struct hda_channel_mode *channel_mode;
  120. int num_channel_mode;
  121. /* PCM information */
  122. struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
  123. /* dynamic controls, init_verbs and input_mux */
  124. struct auto_pin_cfg autocfg;
  125. unsigned int num_kctl_alloc, num_kctl_used;
  126. struct snd_kcontrol_new *kctl_alloc;
  127. struct hda_input_mux private_imux;
  128. hda_nid_t private_dac_nids[5];
  129. };
  130. /*
  131. * configuration template - to be copied to the spec instance
  132. */
  133. struct alc_config_preset {
  134. struct snd_kcontrol_new *mixers[5]; /* should be identical size with spec */
  135. const struct hda_verb *init_verbs[5];
  136. unsigned int num_dacs;
  137. hda_nid_t *dac_nids;
  138. hda_nid_t dig_out_nid; /* optional */
  139. hda_nid_t hp_nid; /* optional */
  140. unsigned int num_adc_nids;
  141. hda_nid_t *adc_nids;
  142. hda_nid_t dig_in_nid;
  143. unsigned int num_channel_mode;
  144. const struct hda_channel_mode *channel_mode;
  145. const struct hda_input_mux *input_mux;
  146. };
  147. /*
  148. * input MUX handling
  149. */
  150. static int alc_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  151. {
  152. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  153. struct alc_spec *spec = codec->spec;
  154. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  155. }
  156. static int alc_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  157. {
  158. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  159. struct alc_spec *spec = codec->spec;
  160. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  161. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  162. return 0;
  163. }
  164. static int alc_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  165. {
  166. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  167. struct alc_spec *spec = codec->spec;
  168. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  169. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  170. spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
  171. }
  172. /*
  173. * channel mode setting
  174. */
  175. static int alc_ch_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  176. {
  177. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  178. struct alc_spec *spec = codec->spec;
  179. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  180. spec->num_channel_mode);
  181. }
  182. static int alc_ch_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  183. {
  184. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  185. struct alc_spec *spec = codec->spec;
  186. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  187. spec->num_channel_mode, spec->multiout.max_channels);
  188. }
  189. static int alc_ch_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  190. {
  191. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  192. struct alc_spec *spec = codec->spec;
  193. return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  194. spec->num_channel_mode, &spec->multiout.max_channels);
  195. }
  196. /*
  197. * Control the mode of pin widget settings via the mixer. "pc" is used
  198. * instead of "%" to avoid consequences of accidently treating the % as
  199. * being part of a format specifier. Maximum allowed length of a value is
  200. * 63 characters plus NULL terminator.
  201. *
  202. * Note: some retasking pin complexes seem to ignore requests for input
  203. * states other than HiZ (eg: PIN_VREFxx) and revert to HiZ if any of these
  204. * are requested. Therefore order this list so that this behaviour will not
  205. * cause problems when mixer clients move through the enum sequentially.
  206. * NIDs 0x0f and 0x10 have been observed to have this behaviour.
  207. */
  208. static char *alc_pin_mode_names[] = {
  209. "Mic 50pc bias", "Mic 80pc bias",
  210. "Line in", "Line out", "Headphone out",
  211. };
  212. static unsigned char alc_pin_mode_values[] = {
  213. PIN_VREF50, PIN_VREF80, PIN_IN, PIN_OUT, PIN_HP,
  214. };
  215. /* The control can present all 5 options, or it can limit the options based
  216. * in the pin being assumed to be exclusively an input or an output pin.
  217. */
  218. #define ALC_PIN_DIR_IN 0x00
  219. #define ALC_PIN_DIR_OUT 0x01
  220. #define ALC_PIN_DIR_INOUT 0x02
  221. /* Info about the pin modes supported by the three different pin directions.
  222. * For each direction the minimum and maximum values are given.
  223. */
  224. static signed char alc_pin_mode_dir_info[3][2] = {
  225. { 0, 2 }, /* ALC_PIN_DIR_IN */
  226. { 3, 4 }, /* ALC_PIN_DIR_OUT */
  227. { 0, 4 }, /* ALC_PIN_DIR_INOUT */
  228. };
  229. #define alc_pin_mode_min(_dir) (alc_pin_mode_dir_info[_dir][0])
  230. #define alc_pin_mode_max(_dir) (alc_pin_mode_dir_info[_dir][1])
  231. #define alc_pin_mode_n_items(_dir) \
  232. (alc_pin_mode_max(_dir)-alc_pin_mode_min(_dir)+1)
  233. static int alc_pin_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  234. {
  235. unsigned int item_num = uinfo->value.enumerated.item;
  236. unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
  237. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  238. uinfo->count = 1;
  239. uinfo->value.enumerated.items = alc_pin_mode_n_items(dir);
  240. if (item_num<alc_pin_mode_min(dir) || item_num>alc_pin_mode_max(dir))
  241. item_num = alc_pin_mode_min(dir);
  242. strcpy(uinfo->value.enumerated.name, alc_pin_mode_names[item_num]);
  243. return 0;
  244. }
  245. static int alc_pin_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  246. {
  247. unsigned int i;
  248. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  249. hda_nid_t nid = kcontrol->private_value & 0xffff;
  250. unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
  251. long *valp = ucontrol->value.integer.value;
  252. unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
  253. /* Find enumerated value for current pinctl setting */
  254. i = alc_pin_mode_min(dir);
  255. while (alc_pin_mode_values[i]!=pinctl && i<=alc_pin_mode_max(dir))
  256. i++;
  257. *valp = i<=alc_pin_mode_max(dir)?i:alc_pin_mode_min(dir);
  258. return 0;
  259. }
  260. static int alc_pin_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  261. {
  262. signed int change;
  263. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  264. hda_nid_t nid = kcontrol->private_value & 0xffff;
  265. unsigned char dir = (kcontrol->private_value >> 16) & 0xff;
  266. long val = *ucontrol->value.integer.value;
  267. unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
  268. if (val<alc_pin_mode_min(dir) || val>alc_pin_mode_max(dir))
  269. val = alc_pin_mode_min(dir);
  270. change = pinctl != alc_pin_mode_values[val];
  271. if (change) {
  272. /* Set pin mode to that requested */
  273. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
  274. alc_pin_mode_values[val]);
  275. /* Also enable the retasking pin's input/output as required
  276. * for the requested pin mode. Enum values of 2 or less are
  277. * input modes.
  278. *
  279. * Dynamically switching the input/output buffers probably
  280. * reduces noise slightly, particularly on input. However,
  281. * havingboth input and output buffers enabled
  282. * simultaneously doesn't seem to be problematic.
  283. */
  284. if (val <= 2) {
  285. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
  286. AMP_OUT_MUTE);
  287. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
  288. AMP_IN_UNMUTE(0));
  289. } else {
  290. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
  291. AMP_IN_MUTE(0));
  292. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_AMP_GAIN_MUTE,
  293. AMP_OUT_UNMUTE);
  294. }
  295. }
  296. return change;
  297. }
  298. #define ALC_PIN_MODE(xname, nid, dir) \
  299. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  300. .info = alc_pin_mode_info, \
  301. .get = alc_pin_mode_get, \
  302. .put = alc_pin_mode_put, \
  303. .private_value = nid | (dir<<16) }
  304. /* A switch control for ALC260 GPIO pins. Multiple GPIOs can be ganged
  305. * together using a mask with more than one bit set. This control is
  306. * currently used only by the ALC260 test model. At this stage they are not
  307. * needed for any "production" models.
  308. */
  309. #ifdef CONFIG_SND_DEBUG
  310. static int alc_gpio_data_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  311. {
  312. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  313. uinfo->count = 1;
  314. uinfo->value.integer.min = 0;
  315. uinfo->value.integer.max = 1;
  316. return 0;
  317. }
  318. static int alc_gpio_data_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  319. {
  320. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  321. hda_nid_t nid = kcontrol->private_value & 0xffff;
  322. unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
  323. long *valp = ucontrol->value.integer.value;
  324. unsigned int val = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00);
  325. *valp = (val & mask) != 0;
  326. return 0;
  327. }
  328. static int alc_gpio_data_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  329. {
  330. signed int change;
  331. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  332. hda_nid_t nid = kcontrol->private_value & 0xffff;
  333. unsigned char mask = (kcontrol->private_value >> 16) & 0xff;
  334. long val = *ucontrol->value.integer.value;
  335. unsigned int gpio_data = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_GPIO_DATA,0x00);
  336. /* Set/unset the masked GPIO bit(s) as needed */
  337. change = (val==0?0:mask) != (gpio_data & mask);
  338. if (val==0)
  339. gpio_data &= ~mask;
  340. else
  341. gpio_data |= mask;
  342. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_GPIO_DATA,gpio_data);
  343. return change;
  344. }
  345. #define ALC_GPIO_DATA_SWITCH(xname, nid, mask) \
  346. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  347. .info = alc_gpio_data_info, \
  348. .get = alc_gpio_data_get, \
  349. .put = alc_gpio_data_put, \
  350. .private_value = nid | (mask<<16) }
  351. #endif /* CONFIG_SND_DEBUG */
  352. /*
  353. * set up from the preset table
  354. */
  355. static void setup_preset(struct alc_spec *spec, const struct alc_config_preset *preset)
  356. {
  357. int i;
  358. for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
  359. spec->mixers[spec->num_mixers++] = preset->mixers[i];
  360. for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i]; i++)
  361. spec->init_verbs[spec->num_init_verbs++] = preset->init_verbs[i];
  362. spec->channel_mode = preset->channel_mode;
  363. spec->num_channel_mode = preset->num_channel_mode;
  364. spec->multiout.max_channels = spec->channel_mode[0].channels;
  365. spec->multiout.num_dacs = preset->num_dacs;
  366. spec->multiout.dac_nids = preset->dac_nids;
  367. spec->multiout.dig_out_nid = preset->dig_out_nid;
  368. spec->multiout.hp_nid = preset->hp_nid;
  369. spec->input_mux = preset->input_mux;
  370. spec->num_adc_nids = preset->num_adc_nids;
  371. spec->adc_nids = preset->adc_nids;
  372. spec->dig_in_nid = preset->dig_in_nid;
  373. }
  374. /*
  375. * ALC880 3-stack model
  376. *
  377. * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
  378. * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18, F-Mic = 0x1b
  379. * HP = 0x19
  380. */
  381. static hda_nid_t alc880_dac_nids[4] = {
  382. /* front, rear, clfe, rear_surr */
  383. 0x02, 0x05, 0x04, 0x03
  384. };
  385. static hda_nid_t alc880_adc_nids[3] = {
  386. /* ADC0-2 */
  387. 0x07, 0x08, 0x09,
  388. };
  389. /* The datasheet says the node 0x07 is connected from inputs,
  390. * but it shows zero connection in the real implementation on some devices.
  391. * Note: this is a 915GAV bug, fixed on 915GLV
  392. */
  393. static hda_nid_t alc880_adc_nids_alt[2] = {
  394. /* ADC1-2 */
  395. 0x08, 0x09,
  396. };
  397. #define ALC880_DIGOUT_NID 0x06
  398. #define ALC880_DIGIN_NID 0x0a
  399. static struct hda_input_mux alc880_capture_source = {
  400. .num_items = 4,
  401. .items = {
  402. { "Mic", 0x0 },
  403. { "Front Mic", 0x3 },
  404. { "Line", 0x2 },
  405. { "CD", 0x4 },
  406. },
  407. };
  408. /* channel source setting (2/6 channel selection for 3-stack) */
  409. /* 2ch mode */
  410. static struct hda_verb alc880_threestack_ch2_init[] = {
  411. /* set line-in to input, mute it */
  412. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  413. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  414. /* set mic-in to input vref 80%, mute it */
  415. { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  416. { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  417. { } /* end */
  418. };
  419. /* 6ch mode */
  420. static struct hda_verb alc880_threestack_ch6_init[] = {
  421. /* set line-in to output, unmute it */
  422. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  423. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  424. /* set mic-in to output, unmute it */
  425. { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  426. { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  427. { } /* end */
  428. };
  429. static struct hda_channel_mode alc880_threestack_modes[2] = {
  430. { 2, alc880_threestack_ch2_init },
  431. { 6, alc880_threestack_ch6_init },
  432. };
  433. static struct snd_kcontrol_new alc880_three_stack_mixer[] = {
  434. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  435. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  436. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  437. HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
  438. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  439. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  440. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  441. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  442. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  443. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  444. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  445. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  446. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  447. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  448. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
  449. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
  450. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  451. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  452. HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
  453. {
  454. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  455. .name = "Channel Mode",
  456. .info = alc_ch_mode_info,
  457. .get = alc_ch_mode_get,
  458. .put = alc_ch_mode_put,
  459. },
  460. { } /* end */
  461. };
  462. /* capture mixer elements */
  463. static struct snd_kcontrol_new alc880_capture_mixer[] = {
  464. HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
  465. HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
  466. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
  467. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
  468. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
  469. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
  470. {
  471. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  472. /* The multiple "Capture Source" controls confuse alsamixer
  473. * So call somewhat different..
  474. * FIXME: the controls appear in the "playback" view!
  475. */
  476. /* .name = "Capture Source", */
  477. .name = "Input Source",
  478. .count = 3,
  479. .info = alc_mux_enum_info,
  480. .get = alc_mux_enum_get,
  481. .put = alc_mux_enum_put,
  482. },
  483. { } /* end */
  484. };
  485. /* capture mixer elements (in case NID 0x07 not available) */
  486. static struct snd_kcontrol_new alc880_capture_alt_mixer[] = {
  487. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  488. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  489. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
  490. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
  491. {
  492. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  493. /* The multiple "Capture Source" controls confuse alsamixer
  494. * So call somewhat different..
  495. * FIXME: the controls appear in the "playback" view!
  496. */
  497. /* .name = "Capture Source", */
  498. .name = "Input Source",
  499. .count = 2,
  500. .info = alc_mux_enum_info,
  501. .get = alc_mux_enum_get,
  502. .put = alc_mux_enum_put,
  503. },
  504. { } /* end */
  505. };
  506. /*
  507. * ALC880 5-stack model
  508. *
  509. * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d), Side = 0x02 (0xd)
  510. * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
  511. * Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
  512. */
  513. /* additional mixers to alc880_three_stack_mixer */
  514. static struct snd_kcontrol_new alc880_five_stack_mixer[] = {
  515. HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  516. HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
  517. { } /* end */
  518. };
  519. /* channel source setting (6/8 channel selection for 5-stack) */
  520. /* 6ch mode */
  521. static struct hda_verb alc880_fivestack_ch6_init[] = {
  522. /* set line-in to input, mute it */
  523. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  524. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  525. { } /* end */
  526. };
  527. /* 8ch mode */
  528. static struct hda_verb alc880_fivestack_ch8_init[] = {
  529. /* set line-in to output, unmute it */
  530. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  531. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  532. { } /* end */
  533. };
  534. static struct hda_channel_mode alc880_fivestack_modes[2] = {
  535. { 6, alc880_fivestack_ch6_init },
  536. { 8, alc880_fivestack_ch8_init },
  537. };
  538. /*
  539. * ALC880 6-stack model
  540. *
  541. * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e), Side = 0x05 (0x0f)
  542. * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
  543. * Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
  544. */
  545. static hda_nid_t alc880_6st_dac_nids[4] = {
  546. /* front, rear, clfe, rear_surr */
  547. 0x02, 0x03, 0x04, 0x05
  548. };
  549. static struct hda_input_mux alc880_6stack_capture_source = {
  550. .num_items = 4,
  551. .items = {
  552. { "Mic", 0x0 },
  553. { "Front Mic", 0x1 },
  554. { "Line", 0x2 },
  555. { "CD", 0x4 },
  556. },
  557. };
  558. /* fixed 8-channels */
  559. static struct hda_channel_mode alc880_sixstack_modes[1] = {
  560. { 8, NULL },
  561. };
  562. static struct snd_kcontrol_new alc880_six_stack_mixer[] = {
  563. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  564. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  565. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  566. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  567. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  568. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  569. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  570. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  571. HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  572. HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
  573. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  574. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  575. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  576. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  577. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  578. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  579. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
  580. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
  581. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  582. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  583. {
  584. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  585. .name = "Channel Mode",
  586. .info = alc_ch_mode_info,
  587. .get = alc_ch_mode_get,
  588. .put = alc_ch_mode_put,
  589. },
  590. { } /* end */
  591. };
  592. /*
  593. * ALC880 W810 model
  594. *
  595. * W810 has rear IO for:
  596. * Front (DAC 02)
  597. * Surround (DAC 03)
  598. * Center/LFE (DAC 04)
  599. * Digital out (06)
  600. *
  601. * The system also has a pair of internal speakers, and a headphone jack.
  602. * These are both connected to Line2 on the codec, hence to DAC 02.
  603. *
  604. * There is a variable resistor to control the speaker or headphone
  605. * volume. This is a hardware-only device without a software API.
  606. *
  607. * Plugging headphones in will disable the internal speakers. This is
  608. * implemented in hardware, not via the driver using jack sense. In
  609. * a similar fashion, plugging into the rear socket marked "front" will
  610. * disable both the speakers and headphones.
  611. *
  612. * For input, there's a microphone jack, and an "audio in" jack.
  613. * These may not do anything useful with this driver yet, because I
  614. * haven't setup any initialization verbs for these yet...
  615. */
  616. static hda_nid_t alc880_w810_dac_nids[3] = {
  617. /* front, rear/surround, clfe */
  618. 0x02, 0x03, 0x04
  619. };
  620. /* fixed 6 channels */
  621. static struct hda_channel_mode alc880_w810_modes[1] = {
  622. { 6, NULL }
  623. };
  624. /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
  625. static struct snd_kcontrol_new alc880_w810_base_mixer[] = {
  626. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  627. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  628. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  629. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  630. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  631. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  632. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  633. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  634. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  635. { } /* end */
  636. };
  637. /*
  638. * Z710V model
  639. *
  640. * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
  641. * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?), Line = 0x1a
  642. */
  643. static hda_nid_t alc880_z71v_dac_nids[1] = {
  644. 0x02
  645. };
  646. #define ALC880_Z71V_HP_DAC 0x03
  647. /* fixed 2 channels */
  648. static struct hda_channel_mode alc880_2_jack_modes[1] = {
  649. { 2, NULL }
  650. };
  651. static struct snd_kcontrol_new alc880_z71v_mixer[] = {
  652. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  653. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  654. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  655. HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
  656. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  657. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  658. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  659. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  660. { } /* end */
  661. };
  662. /* FIXME! */
  663. /*
  664. * ALC880 F1734 model
  665. *
  666. * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
  667. * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
  668. */
  669. static hda_nid_t alc880_f1734_dac_nids[1] = {
  670. 0x03
  671. };
  672. #define ALC880_F1734_HP_DAC 0x02
  673. static struct snd_kcontrol_new alc880_f1734_mixer[] = {
  674. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  675. HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
  676. HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  677. HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
  678. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  679. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  680. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  681. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  682. { } /* end */
  683. };
  684. /* FIXME! */
  685. /*
  686. * ALC880 ASUS model
  687. *
  688. * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
  689. * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
  690. * Mic = 0x18, Line = 0x1a
  691. */
  692. #define alc880_asus_dac_nids alc880_w810_dac_nids /* identical with w810 */
  693. #define alc880_asus_modes alc880_threestack_modes /* 2/6 channel mode */
  694. static struct snd_kcontrol_new alc880_asus_mixer[] = {
  695. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  696. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  697. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  698. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  699. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  700. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  701. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  702. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  703. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  704. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  705. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  706. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  707. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  708. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  709. {
  710. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  711. .name = "Channel Mode",
  712. .info = alc_ch_mode_info,
  713. .get = alc_ch_mode_get,
  714. .put = alc_ch_mode_put,
  715. },
  716. { } /* end */
  717. };
  718. /* FIXME! */
  719. /*
  720. * ALC880 ASUS W1V model
  721. *
  722. * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
  723. * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
  724. * Mic = 0x18, Line = 0x1a, Line2 = 0x1b
  725. */
  726. /* additional mixers to alc880_asus_mixer */
  727. static struct snd_kcontrol_new alc880_asus_w1v_mixer[] = {
  728. HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
  729. HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
  730. { } /* end */
  731. };
  732. /* additional mixers to alc880_asus_mixer */
  733. static struct snd_kcontrol_new alc880_pcbeep_mixer[] = {
  734. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  735. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  736. { } /* end */
  737. };
  738. /* TCL S700 */
  739. static struct snd_kcontrol_new alc880_tcl_s700_mixer[] = {
  740. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  741. HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  742. HDA_CODEC_MUTE("Headphone Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  743. HDA_CODEC_VOLUME("CD Playback Volume", 0x0B, 0x04, HDA_INPUT),
  744. HDA_CODEC_MUTE("CD Playback Switch", 0x0B, 0x04, HDA_INPUT),
  745. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0B, 0x0, HDA_INPUT),
  746. HDA_CODEC_MUTE("Mic Playback Switch", 0x0B, 0x0, HDA_INPUT),
  747. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  748. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  749. {
  750. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  751. /* The multiple "Capture Source" controls confuse alsamixer
  752. * So call somewhat different..
  753. * FIXME: the controls appear in the "playback" view!
  754. */
  755. /* .name = "Capture Source", */
  756. .name = "Input Source",
  757. .count = 1,
  758. .info = alc_mux_enum_info,
  759. .get = alc_mux_enum_get,
  760. .put = alc_mux_enum_put,
  761. },
  762. { } /* end */
  763. };
  764. /*
  765. * build control elements
  766. */
  767. static int alc_build_controls(struct hda_codec *codec)
  768. {
  769. struct alc_spec *spec = codec->spec;
  770. int err;
  771. int i;
  772. for (i = 0; i < spec->num_mixers; i++) {
  773. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  774. if (err < 0)
  775. return err;
  776. }
  777. if (spec->multiout.dig_out_nid) {
  778. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  779. if (err < 0)
  780. return err;
  781. }
  782. if (spec->dig_in_nid) {
  783. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  784. if (err < 0)
  785. return err;
  786. }
  787. return 0;
  788. }
  789. /*
  790. * initialize the codec volumes, etc
  791. */
  792. /*
  793. * generic initialization of ADC, input mixers and output mixers
  794. */
  795. static struct hda_verb alc880_volume_init_verbs[] = {
  796. /*
  797. * Unmute ADC0-2 and set the default input to mic-in
  798. */
  799. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  800. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  801. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  802. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  803. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  804. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  805. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  806. * mixer widget
  807. * Note: PASD motherboards uses the Line In 2 as the input for front panel
  808. * mic (mic 2)
  809. */
  810. /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
  811. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  812. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  813. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  814. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  815. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  816. /*
  817. * Set up output mixers (0x0c - 0x0f)
  818. */
  819. /* set vol=0 to output mixers */
  820. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  821. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  822. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  823. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  824. /* set up input amps for analog loopback */
  825. /* Amp Indices: DAC = 0, mixer = 1 */
  826. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  827. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  828. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  829. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  830. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  831. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  832. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  833. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  834. { }
  835. };
  836. /*
  837. * 3-stack pin configuration:
  838. * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
  839. */
  840. static struct hda_verb alc880_pin_3stack_init_verbs[] = {
  841. /*
  842. * preset connection lists of input pins
  843. * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
  844. */
  845. {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
  846. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
  847. {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
  848. /*
  849. * Set pin mode and muting
  850. */
  851. /* set front pin widgets 0x14 for output */
  852. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  853. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  854. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  855. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  856. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  857. /* Mic2 (as headphone out) for HP output */
  858. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  859. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  860. /* Line In pin widget for input */
  861. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  862. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  863. /* Line2 (as front mic) pin widget for input and vref at 80% */
  864. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  865. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  866. /* CD pin widget for input */
  867. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  868. { }
  869. };
  870. /*
  871. * 5-stack pin configuration:
  872. * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
  873. * line-in/side = 0x1a, f-mic = 0x1b
  874. */
  875. static struct hda_verb alc880_pin_5stack_init_verbs[] = {
  876. /*
  877. * preset connection lists of input pins
  878. * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
  879. */
  880. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
  881. {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
  882. /*
  883. * Set pin mode and muting
  884. */
  885. /* set pin widgets 0x14-0x17 for output */
  886. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  887. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  888. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  889. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  890. /* unmute pins for output (no gain on this amp) */
  891. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  892. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  893. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  894. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  895. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  896. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  897. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  898. /* Mic2 (as headphone out) for HP output */
  899. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  900. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  901. /* Line In pin widget for input */
  902. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  903. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  904. /* Line2 (as front mic) pin widget for input and vref at 80% */
  905. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  906. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  907. /* CD pin widget for input */
  908. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  909. { }
  910. };
  911. /*
  912. * W810 pin configuration:
  913. * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
  914. */
  915. static struct hda_verb alc880_pin_w810_init_verbs[] = {
  916. /* hphone/speaker input selector: front DAC */
  917. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  918. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  919. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  920. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  921. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  922. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  923. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  924. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  925. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  926. { }
  927. };
  928. /*
  929. * Z71V pin configuration:
  930. * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
  931. */
  932. static struct hda_verb alc880_pin_z71v_init_verbs[] = {
  933. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  934. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  935. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  936. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  937. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  938. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  939. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  940. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  941. { }
  942. };
  943. /*
  944. * 6-stack pin configuration:
  945. * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18, f-mic = 0x19,
  946. * line = 0x1a, HP = 0x1b
  947. */
  948. static struct hda_verb alc880_pin_6stack_init_verbs[] = {
  949. {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
  950. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  951. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  952. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  953. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  954. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  955. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  956. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  957. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  958. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  959. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  960. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  961. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  962. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  963. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  964. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  965. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  966. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  967. { }
  968. };
  969. /* FIXME! */
  970. /*
  971. * F1734 pin configuration:
  972. * HP = 0x14, speaker-out = 0x15, mic = 0x18
  973. */
  974. static struct hda_verb alc880_pin_f1734_init_verbs[] = {
  975. {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
  976. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
  977. {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
  978. {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
  979. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  980. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  981. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  982. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  983. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  984. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  985. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  986. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  987. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  988. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  989. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  990. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  991. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  992. { }
  993. };
  994. /* FIXME! */
  995. /*
  996. * ASUS pin configuration:
  997. * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
  998. */
  999. static struct hda_verb alc880_pin_asus_init_verbs[] = {
  1000. {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
  1001. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
  1002. {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
  1003. {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
  1004. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1005. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1006. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1007. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1008. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1009. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1010. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1011. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1012. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1013. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1014. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1015. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1016. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1017. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1018. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1019. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1020. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1021. { }
  1022. };
  1023. /* Enable GPIO mask and set output */
  1024. static struct hda_verb alc880_gpio1_init_verbs[] = {
  1025. {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
  1026. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  1027. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  1028. { }
  1029. };
  1030. /* Enable GPIO mask and set output */
  1031. static struct hda_verb alc880_gpio2_init_verbs[] = {
  1032. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  1033. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  1034. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  1035. { }
  1036. };
  1037. /* Clevo m520g init */
  1038. static struct hda_verb alc880_pin_clevo_init_verbs[] = {
  1039. /* headphone output */
  1040. {0x11, AC_VERB_SET_CONNECT_SEL, 0x01},
  1041. /* line-out */
  1042. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1043. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1044. /* Line-in */
  1045. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1046. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1047. /* CD */
  1048. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1049. {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1050. /* Mic1 (rear panel) */
  1051. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1052. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1053. /* Mic2 (front panel) */
  1054. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1055. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1056. /* headphone */
  1057. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1058. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1059. /* change to EAPD mode */
  1060. {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
  1061. {0x20, AC_VERB_SET_PROC_COEF, 0x3060},
  1062. { }
  1063. };
  1064. static struct hda_verb alc880_pin_tcl_S700_init_verbs[] = {
  1065. /* Headphone output */
  1066. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1067. /* Front output*/
  1068. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1069. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1070. /* Line In pin widget for input */
  1071. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1072. /* CD pin widget for input */
  1073. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1074. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  1075. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1076. /* change to EAPD mode */
  1077. {0x20, AC_VERB_SET_COEF_INDEX, 0x07},
  1078. {0x20, AC_VERB_SET_PROC_COEF, 0x3070},
  1079. { }
  1080. };
  1081. /*
  1082. */
  1083. static int alc_init(struct hda_codec *codec)
  1084. {
  1085. struct alc_spec *spec = codec->spec;
  1086. unsigned int i;
  1087. for (i = 0; i < spec->num_init_verbs; i++)
  1088. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  1089. return 0;
  1090. }
  1091. #ifdef CONFIG_PM
  1092. /*
  1093. * resume
  1094. */
  1095. static int alc_resume(struct hda_codec *codec)
  1096. {
  1097. struct alc_spec *spec = codec->spec;
  1098. int i;
  1099. alc_init(codec);
  1100. for (i = 0; i < spec->num_mixers; i++)
  1101. snd_hda_resume_ctls(codec, spec->mixers[i]);
  1102. if (spec->multiout.dig_out_nid)
  1103. snd_hda_resume_spdif_out(codec);
  1104. if (spec->dig_in_nid)
  1105. snd_hda_resume_spdif_in(codec);
  1106. return 0;
  1107. }
  1108. #endif
  1109. /*
  1110. * Analog playback callbacks
  1111. */
  1112. static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1113. struct hda_codec *codec,
  1114. struct snd_pcm_substream *substream)
  1115. {
  1116. struct alc_spec *spec = codec->spec;
  1117. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  1118. }
  1119. static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1120. struct hda_codec *codec,
  1121. unsigned int stream_tag,
  1122. unsigned int format,
  1123. struct snd_pcm_substream *substream)
  1124. {
  1125. struct alc_spec *spec = codec->spec;
  1126. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  1127. format, substream);
  1128. }
  1129. static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1130. struct hda_codec *codec,
  1131. struct snd_pcm_substream *substream)
  1132. {
  1133. struct alc_spec *spec = codec->spec;
  1134. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1135. }
  1136. /*
  1137. * Digital out
  1138. */
  1139. static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1140. struct hda_codec *codec,
  1141. struct snd_pcm_substream *substream)
  1142. {
  1143. struct alc_spec *spec = codec->spec;
  1144. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1145. }
  1146. static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1147. struct hda_codec *codec,
  1148. struct snd_pcm_substream *substream)
  1149. {
  1150. struct alc_spec *spec = codec->spec;
  1151. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1152. }
  1153. /*
  1154. * Analog capture
  1155. */
  1156. static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1157. struct hda_codec *codec,
  1158. unsigned int stream_tag,
  1159. unsigned int format,
  1160. struct snd_pcm_substream *substream)
  1161. {
  1162. struct alc_spec *spec = codec->spec;
  1163. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1164. stream_tag, 0, format);
  1165. return 0;
  1166. }
  1167. static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1168. struct hda_codec *codec,
  1169. struct snd_pcm_substream *substream)
  1170. {
  1171. struct alc_spec *spec = codec->spec;
  1172. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  1173. return 0;
  1174. }
  1175. /*
  1176. */
  1177. static struct hda_pcm_stream alc880_pcm_analog_playback = {
  1178. .substreams = 1,
  1179. .channels_min = 2,
  1180. .channels_max = 8,
  1181. /* NID is set in alc_build_pcms */
  1182. .ops = {
  1183. .open = alc880_playback_pcm_open,
  1184. .prepare = alc880_playback_pcm_prepare,
  1185. .cleanup = alc880_playback_pcm_cleanup
  1186. },
  1187. };
  1188. static struct hda_pcm_stream alc880_pcm_analog_capture = {
  1189. .substreams = 2,
  1190. .channels_min = 2,
  1191. .channels_max = 2,
  1192. /* NID is set in alc_build_pcms */
  1193. .ops = {
  1194. .prepare = alc880_capture_pcm_prepare,
  1195. .cleanup = alc880_capture_pcm_cleanup
  1196. },
  1197. };
  1198. static struct hda_pcm_stream alc880_pcm_digital_playback = {
  1199. .substreams = 1,
  1200. .channels_min = 2,
  1201. .channels_max = 2,
  1202. /* NID is set in alc_build_pcms */
  1203. .ops = {
  1204. .open = alc880_dig_playback_pcm_open,
  1205. .close = alc880_dig_playback_pcm_close
  1206. },
  1207. };
  1208. static struct hda_pcm_stream alc880_pcm_digital_capture = {
  1209. .substreams = 1,
  1210. .channels_min = 2,
  1211. .channels_max = 2,
  1212. /* NID is set in alc_build_pcms */
  1213. };
  1214. /* Used by alc_build_pcms to flag that a PCM has no playback stream */
  1215. static struct hda_pcm_stream alc_pcm_null_playback = {
  1216. .substreams = 0,
  1217. .channels_min = 0,
  1218. .channels_max = 0,
  1219. };
  1220. static int alc_build_pcms(struct hda_codec *codec)
  1221. {
  1222. struct alc_spec *spec = codec->spec;
  1223. struct hda_pcm *info = spec->pcm_rec;
  1224. int i;
  1225. codec->num_pcms = 1;
  1226. codec->pcm_info = info;
  1227. info->name = spec->stream_name_analog;
  1228. if (spec->stream_analog_playback) {
  1229. snd_assert(spec->multiout.dac_nids, return -EINVAL);
  1230. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
  1231. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  1232. }
  1233. if (spec->stream_analog_capture) {
  1234. snd_assert(spec->adc_nids, return -EINVAL);
  1235. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  1236. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1237. }
  1238. if (spec->channel_mode) {
  1239. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
  1240. for (i = 0; i < spec->num_channel_mode; i++) {
  1241. if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
  1242. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
  1243. }
  1244. }
  1245. }
  1246. /* If the use of more than one ADC is requested for the current
  1247. * model, configure a second analog capture-only PCM.
  1248. */
  1249. if (spec->num_adc_nids > 1) {
  1250. codec->num_pcms++;
  1251. info++;
  1252. info->name = spec->stream_name_analog;
  1253. /* No playback stream for second PCM */
  1254. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = alc_pcm_null_playback;
  1255. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
  1256. if (spec->stream_analog_capture) {
  1257. snd_assert(spec->adc_nids, return -EINVAL);
  1258. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  1259. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[1];
  1260. }
  1261. }
  1262. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1263. codec->num_pcms++;
  1264. info++;
  1265. info->name = spec->stream_name_digital;
  1266. if (spec->multiout.dig_out_nid &&
  1267. spec->stream_digital_playback) {
  1268. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
  1269. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  1270. }
  1271. if (spec->dig_in_nid &&
  1272. spec->stream_digital_capture) {
  1273. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
  1274. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  1275. }
  1276. }
  1277. return 0;
  1278. }
  1279. static void alc_free(struct hda_codec *codec)
  1280. {
  1281. struct alc_spec *spec = codec->spec;
  1282. unsigned int i;
  1283. if (! spec)
  1284. return;
  1285. if (spec->kctl_alloc) {
  1286. for (i = 0; i < spec->num_kctl_used; i++)
  1287. kfree(spec->kctl_alloc[i].name);
  1288. kfree(spec->kctl_alloc);
  1289. }
  1290. kfree(spec);
  1291. }
  1292. /*
  1293. */
  1294. static struct hda_codec_ops alc_patch_ops = {
  1295. .build_controls = alc_build_controls,
  1296. .build_pcms = alc_build_pcms,
  1297. .init = alc_init,
  1298. .free = alc_free,
  1299. #ifdef CONFIG_PM
  1300. .resume = alc_resume,
  1301. #endif
  1302. };
  1303. /*
  1304. * Test configuration for debugging
  1305. *
  1306. * Almost all inputs/outputs are enabled. I/O pins can be configured via
  1307. * enum controls.
  1308. */
  1309. #ifdef CONFIG_SND_DEBUG
  1310. static hda_nid_t alc880_test_dac_nids[4] = {
  1311. 0x02, 0x03, 0x04, 0x05
  1312. };
  1313. static struct hda_input_mux alc880_test_capture_source = {
  1314. .num_items = 5,
  1315. .items = {
  1316. { "In-1", 0x0 },
  1317. { "In-2", 0x1 },
  1318. { "In-3", 0x2 },
  1319. { "In-4", 0x3 },
  1320. { "CD", 0x4 },
  1321. },
  1322. };
  1323. static struct hda_channel_mode alc880_test_modes[4] = {
  1324. { 2, NULL },
  1325. { 4, NULL },
  1326. { 6, NULL },
  1327. { 8, NULL },
  1328. };
  1329. static int alc_test_pin_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1330. {
  1331. static char *texts[] = {
  1332. "N/A", "Line Out", "HP Out",
  1333. "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
  1334. };
  1335. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1336. uinfo->count = 1;
  1337. uinfo->value.enumerated.items = 8;
  1338. if (uinfo->value.enumerated.item >= 8)
  1339. uinfo->value.enumerated.item = 7;
  1340. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1341. return 0;
  1342. }
  1343. static int alc_test_pin_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1344. {
  1345. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1346. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1347. unsigned int pin_ctl, item = 0;
  1348. pin_ctl = snd_hda_codec_read(codec, nid, 0,
  1349. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1350. if (pin_ctl & AC_PINCTL_OUT_EN) {
  1351. if (pin_ctl & AC_PINCTL_HP_EN)
  1352. item = 2;
  1353. else
  1354. item = 1;
  1355. } else if (pin_ctl & AC_PINCTL_IN_EN) {
  1356. switch (pin_ctl & AC_PINCTL_VREFEN) {
  1357. case AC_PINCTL_VREF_HIZ: item = 3; break;
  1358. case AC_PINCTL_VREF_50: item = 4; break;
  1359. case AC_PINCTL_VREF_GRD: item = 5; break;
  1360. case AC_PINCTL_VREF_80: item = 6; break;
  1361. case AC_PINCTL_VREF_100: item = 7; break;
  1362. }
  1363. }
  1364. ucontrol->value.enumerated.item[0] = item;
  1365. return 0;
  1366. }
  1367. static int alc_test_pin_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1368. {
  1369. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1370. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1371. static unsigned int ctls[] = {
  1372. 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
  1373. AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
  1374. AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
  1375. AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
  1376. AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
  1377. AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
  1378. };
  1379. unsigned int old_ctl, new_ctl;
  1380. old_ctl = snd_hda_codec_read(codec, nid, 0,
  1381. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1382. new_ctl = ctls[ucontrol->value.enumerated.item[0]];
  1383. if (old_ctl != new_ctl) {
  1384. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
  1385. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1386. ucontrol->value.enumerated.item[0] >= 3 ? 0xb080 : 0xb000);
  1387. return 1;
  1388. }
  1389. return 0;
  1390. }
  1391. static int alc_test_pin_src_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  1392. {
  1393. static char *texts[] = {
  1394. "Front", "Surround", "CLFE", "Side"
  1395. };
  1396. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1397. uinfo->count = 1;
  1398. uinfo->value.enumerated.items = 4;
  1399. if (uinfo->value.enumerated.item >= 4)
  1400. uinfo->value.enumerated.item = 3;
  1401. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1402. return 0;
  1403. }
  1404. static int alc_test_pin_src_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1405. {
  1406. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1407. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1408. unsigned int sel;
  1409. sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1410. ucontrol->value.enumerated.item[0] = sel & 3;
  1411. return 0;
  1412. }
  1413. static int alc_test_pin_src_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1414. {
  1415. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1416. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1417. unsigned int sel;
  1418. sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
  1419. if (ucontrol->value.enumerated.item[0] != sel) {
  1420. sel = ucontrol->value.enumerated.item[0] & 3;
  1421. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
  1422. return 1;
  1423. }
  1424. return 0;
  1425. }
  1426. #define PIN_CTL_TEST(xname,nid) { \
  1427. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1428. .name = xname, \
  1429. .info = alc_test_pin_ctl_info, \
  1430. .get = alc_test_pin_ctl_get, \
  1431. .put = alc_test_pin_ctl_put, \
  1432. .private_value = nid \
  1433. }
  1434. #define PIN_SRC_TEST(xname,nid) { \
  1435. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1436. .name = xname, \
  1437. .info = alc_test_pin_src_info, \
  1438. .get = alc_test_pin_src_get, \
  1439. .put = alc_test_pin_src_put, \
  1440. .private_value = nid \
  1441. }
  1442. static struct snd_kcontrol_new alc880_test_mixer[] = {
  1443. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  1444. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  1445. HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
  1446. HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  1447. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  1448. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  1449. HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
  1450. HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
  1451. PIN_CTL_TEST("Front Pin Mode", 0x14),
  1452. PIN_CTL_TEST("Surround Pin Mode", 0x15),
  1453. PIN_CTL_TEST("CLFE Pin Mode", 0x16),
  1454. PIN_CTL_TEST("Side Pin Mode", 0x17),
  1455. PIN_CTL_TEST("In-1 Pin Mode", 0x18),
  1456. PIN_CTL_TEST("In-2 Pin Mode", 0x19),
  1457. PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
  1458. PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
  1459. PIN_SRC_TEST("In-1 Pin Source", 0x18),
  1460. PIN_SRC_TEST("In-2 Pin Source", 0x19),
  1461. PIN_SRC_TEST("In-3 Pin Source", 0x1a),
  1462. PIN_SRC_TEST("In-4 Pin Source", 0x1b),
  1463. HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
  1464. HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
  1465. HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
  1466. HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
  1467. HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
  1468. HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
  1469. HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
  1470. HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
  1471. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
  1472. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
  1473. {
  1474. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1475. .name = "Channel Mode",
  1476. .info = alc_ch_mode_info,
  1477. .get = alc_ch_mode_get,
  1478. .put = alc_ch_mode_put,
  1479. },
  1480. { } /* end */
  1481. };
  1482. static struct hda_verb alc880_test_init_verbs[] = {
  1483. /* Unmute inputs of 0x0c - 0x0f */
  1484. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1485. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1486. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1487. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1488. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1489. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1490. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1491. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1492. /* Vol output for 0x0c-0x0f */
  1493. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1494. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1495. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1496. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1497. /* Set output pins 0x14-0x17 */
  1498. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1499. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1500. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1501. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1502. /* Unmute output pins 0x14-0x17 */
  1503. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1504. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1505. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1506. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1507. /* Set input pins 0x18-0x1c */
  1508. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1509. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1510. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1511. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1512. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1513. /* Mute input pins 0x18-0x1b */
  1514. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1515. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1516. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1517. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1518. /* ADC set up */
  1519. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1520. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  1521. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1522. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  1523. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1524. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  1525. /* Analog input/passthru */
  1526. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1527. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1528. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1529. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1530. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1531. { }
  1532. };
  1533. #endif
  1534. /*
  1535. */
  1536. static struct hda_board_config alc880_cfg_tbl[] = {
  1537. /* Back 3 jack, front 2 jack */
  1538. { .modelname = "3stack", .config = ALC880_3ST },
  1539. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe200, .config = ALC880_3ST },
  1540. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe201, .config = ALC880_3ST },
  1541. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe202, .config = ALC880_3ST },
  1542. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe203, .config = ALC880_3ST },
  1543. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe204, .config = ALC880_3ST },
  1544. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe205, .config = ALC880_3ST },
  1545. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe206, .config = ALC880_3ST },
  1546. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe207, .config = ALC880_3ST },
  1547. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe208, .config = ALC880_3ST },
  1548. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe209, .config = ALC880_3ST },
  1549. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20a, .config = ALC880_3ST },
  1550. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20b, .config = ALC880_3ST },
  1551. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20c, .config = ALC880_3ST },
  1552. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20d, .config = ALC880_3ST },
  1553. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20e, .config = ALC880_3ST },
  1554. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20f, .config = ALC880_3ST },
  1555. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe210, .config = ALC880_3ST },
  1556. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe211, .config = ALC880_3ST },
  1557. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe214, .config = ALC880_3ST },
  1558. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe302, .config = ALC880_3ST },
  1559. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe303, .config = ALC880_3ST },
  1560. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe304, .config = ALC880_3ST },
  1561. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe306, .config = ALC880_3ST },
  1562. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe307, .config = ALC880_3ST },
  1563. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe404, .config = ALC880_3ST },
  1564. { .pci_subvendor = 0x8086, .pci_subdevice = 0xa101, .config = ALC880_3ST },
  1565. { .pci_subvendor = 0x107b, .pci_subdevice = 0x3031, .config = ALC880_3ST },
  1566. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4036, .config = ALC880_3ST },
  1567. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4037, .config = ALC880_3ST },
  1568. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4038, .config = ALC880_3ST },
  1569. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4040, .config = ALC880_3ST },
  1570. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4041, .config = ALC880_3ST },
  1571. /* TCL S700 */
  1572. { .pci_subvendor = 0x19db, .pci_subdevice = 0x4188, .config = ALC880_TCL_S700 },
  1573. /* Back 3 jack, front 2 jack (Internal add Aux-In) */
  1574. { .pci_subvendor = 0x1025, .pci_subdevice = 0xe310, .config = ALC880_3ST },
  1575. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST },
  1576. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81a0, .config = ALC880_3ST },
  1577. /* Back 3 jack plus 1 SPDIF out jack, front 2 jack */
  1578. { .modelname = "3stack-digout", .config = ALC880_3ST_DIG },
  1579. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe308, .config = ALC880_3ST_DIG },
  1580. { .pci_subvendor = 0x1025, .pci_subdevice = 0x0070, .config = ALC880_3ST_DIG },
  1581. /* Clevo m520G NB */
  1582. { .pci_subvendor = 0x1558, .pci_subdevice = 0x0520, .config = ALC880_CLEVO },
  1583. /* Back 3 jack plus 1 SPDIF out jack, front 2 jack (Internal add Aux-In)*/
  1584. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe305, .config = ALC880_3ST_DIG },
  1585. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd402, .config = ALC880_3ST_DIG },
  1586. { .pci_subvendor = 0x1025, .pci_subdevice = 0xe309, .config = ALC880_3ST_DIG },
  1587. /* Back 5 jack, front 2 jack */
  1588. { .modelname = "5stack", .config = ALC880_5ST },
  1589. { .pci_subvendor = 0x107b, .pci_subdevice = 0x3033, .config = ALC880_5ST },
  1590. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4039, .config = ALC880_5ST },
  1591. { .pci_subvendor = 0x107b, .pci_subdevice = 0x3032, .config = ALC880_5ST },
  1592. { .pci_subvendor = 0x103c, .pci_subdevice = 0x2a09, .config = ALC880_5ST },
  1593. { .pci_subvendor = 0x1043, .pci_subdevice = 0x814e, .config = ALC880_5ST },
  1594. /* Back 5 jack plus 1 SPDIF out jack, front 2 jack */
  1595. { .modelname = "5stack-digout", .config = ALC880_5ST_DIG },
  1596. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe224, .config = ALC880_5ST_DIG },
  1597. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe400, .config = ALC880_5ST_DIG },
  1598. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe401, .config = ALC880_5ST_DIG },
  1599. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe402, .config = ALC880_5ST_DIG },
  1600. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd400, .config = ALC880_5ST_DIG },
  1601. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd401, .config = ALC880_5ST_DIG },
  1602. { .pci_subvendor = 0x8086, .pci_subdevice = 0xa100, .config = ALC880_5ST_DIG },
  1603. { .pci_subvendor = 0x1565, .pci_subdevice = 0x8202, .config = ALC880_5ST_DIG },
  1604. { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
  1605. /* { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_5ST_DIG }, */ /* conflict with 6stack */
  1606. { .pci_subvendor = 0x1695, .pci_subdevice = 0x400d, .config = ALC880_5ST_DIG },
  1607. /* note subvendor = 0 below */
  1608. /* { .pci_subvendor = 0x0000, .pci_subdevice = 0x8086, .config = ALC880_5ST_DIG }, */
  1609. { .modelname = "w810", .config = ALC880_W810 },
  1610. { .pci_subvendor = 0x161f, .pci_subdevice = 0x203d, .config = ALC880_W810 },
  1611. { .modelname = "z71v", .config = ALC880_Z71V },
  1612. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_Z71V },
  1613. { .modelname = "6stack", .config = ALC880_6ST },
  1614. { .pci_subvendor = 0x1043, .pci_subdevice = 0x8196, .config = ALC880_6ST }, /* ASUS P5GD1-HVM */
  1615. { .pci_subvendor = 0x1043, .pci_subdevice = 0x81b4, .config = ALC880_6ST },
  1616. { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_6ST }, /* Acer APFV */
  1617. { .pci_subvendor = 0x1458, .pci_subdevice = 0xa102, .config = ALC880_6ST }, /* Gigabyte K8N51 */
  1618. { .modelname = "6stack-digout", .config = ALC880_6ST_DIG },
  1619. { .pci_subvendor = 0x2668, .pci_subdevice = 0x8086, .config = ALC880_6ST_DIG },
  1620. { .pci_subvendor = 0x8086, .pci_subdevice = 0x2668, .config = ALC880_6ST_DIG },
  1621. { .pci_subvendor = 0x1462, .pci_subdevice = 0x1150, .config = ALC880_6ST_DIG },
  1622. { .pci_subvendor = 0xe803, .pci_subdevice = 0x1019, .config = ALC880_6ST_DIG },
  1623. { .pci_subvendor = 0x1039, .pci_subdevice = 0x1234, .config = ALC880_6ST_DIG },
  1624. { .pci_subvendor = 0x1025, .pci_subdevice = 0x0077, .config = ALC880_6ST_DIG },
  1625. { .pci_subvendor = 0x1025, .pci_subdevice = 0x0078, .config = ALC880_6ST_DIG },
  1626. { .pci_subvendor = 0x1025, .pci_subdevice = 0x0087, .config = ALC880_6ST_DIG },
  1627. { .pci_subvendor = 0x1297, .pci_subdevice = 0xc790, .config = ALC880_6ST_DIG }, /* Shuttle ST20G5 */
  1628. { .modelname = "asus", .config = ALC880_ASUS },
  1629. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_ASUS_DIG },
  1630. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1973, .config = ALC880_ASUS_DIG },
  1631. { .pci_subvendor = 0x1043, .pci_subdevice = 0x19b3, .config = ALC880_ASUS_DIG },
  1632. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1113, .config = ALC880_ASUS_DIG },
  1633. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1173, .config = ALC880_ASUS_DIG },
  1634. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1993, .config = ALC880_ASUS },
  1635. { .pci_subvendor = 0x1043, .pci_subdevice = 0x10c3, .config = ALC880_ASUS_DIG },
  1636. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1133, .config = ALC880_ASUS },
  1637. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1123, .config = ALC880_ASUS_DIG },
  1638. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1143, .config = ALC880_ASUS },
  1639. { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
  1640. { .pci_subvendor = 0x1558, .pci_subdevice = 0x5401, .config = ALC880_ASUS_DIG2 },
  1641. { .modelname = "uniwill", .config = ALC880_UNIWILL_DIG },
  1642. { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },
  1643. { .modelname = "F1734", .config = ALC880_F1734 },
  1644. { .pci_subvendor = 0x1734, .pci_subdevice = 0x107c, .config = ALC880_F1734 },
  1645. { .pci_subvendor = 0x1584, .pci_subdevice = 0x9054, .config = ALC880_F1734 },
  1646. #ifdef CONFIG_SND_DEBUG
  1647. { .modelname = "test", .config = ALC880_TEST },
  1648. #endif
  1649. { .modelname = "auto", .config = ALC880_AUTO },
  1650. {}
  1651. };
  1652. /*
  1653. * ALC880 codec presets
  1654. */
  1655. static struct alc_config_preset alc880_presets[] = {
  1656. [ALC880_3ST] = {
  1657. .mixers = { alc880_three_stack_mixer },
  1658. .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
  1659. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1660. .dac_nids = alc880_dac_nids,
  1661. .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
  1662. .channel_mode = alc880_threestack_modes,
  1663. .input_mux = &alc880_capture_source,
  1664. },
  1665. [ALC880_3ST_DIG] = {
  1666. .mixers = { alc880_three_stack_mixer },
  1667. .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
  1668. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1669. .dac_nids = alc880_dac_nids,
  1670. .dig_out_nid = ALC880_DIGOUT_NID,
  1671. .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
  1672. .channel_mode = alc880_threestack_modes,
  1673. .input_mux = &alc880_capture_source,
  1674. },
  1675. [ALC880_TCL_S700] = {
  1676. .mixers = { alc880_tcl_s700_mixer },
  1677. .init_verbs = { alc880_volume_init_verbs,
  1678. alc880_pin_tcl_S700_init_verbs,
  1679. alc880_gpio2_init_verbs },
  1680. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1681. .dac_nids = alc880_dac_nids,
  1682. .hp_nid = 0x03,
  1683. .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
  1684. .channel_mode = alc880_2_jack_modes,
  1685. .input_mux = &alc880_capture_source,
  1686. },
  1687. [ALC880_5ST] = {
  1688. .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer},
  1689. .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
  1690. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1691. .dac_nids = alc880_dac_nids,
  1692. .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
  1693. .channel_mode = alc880_fivestack_modes,
  1694. .input_mux = &alc880_capture_source,
  1695. },
  1696. [ALC880_5ST_DIG] = {
  1697. .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer },
  1698. .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
  1699. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1700. .dac_nids = alc880_dac_nids,
  1701. .dig_out_nid = ALC880_DIGOUT_NID,
  1702. .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
  1703. .channel_mode = alc880_fivestack_modes,
  1704. .input_mux = &alc880_capture_source,
  1705. },
  1706. [ALC880_6ST] = {
  1707. .mixers = { alc880_six_stack_mixer },
  1708. .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
  1709. .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
  1710. .dac_nids = alc880_6st_dac_nids,
  1711. .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
  1712. .channel_mode = alc880_sixstack_modes,
  1713. .input_mux = &alc880_6stack_capture_source,
  1714. },
  1715. [ALC880_6ST_DIG] = {
  1716. .mixers = { alc880_six_stack_mixer },
  1717. .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
  1718. .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
  1719. .dac_nids = alc880_6st_dac_nids,
  1720. .dig_out_nid = ALC880_DIGOUT_NID,
  1721. .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
  1722. .channel_mode = alc880_sixstack_modes,
  1723. .input_mux = &alc880_6stack_capture_source,
  1724. },
  1725. [ALC880_W810] = {
  1726. .mixers = { alc880_w810_base_mixer },
  1727. .init_verbs = { alc880_volume_init_verbs, alc880_pin_w810_init_verbs,
  1728. alc880_gpio2_init_verbs },
  1729. .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
  1730. .dac_nids = alc880_w810_dac_nids,
  1731. .dig_out_nid = ALC880_DIGOUT_NID,
  1732. .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
  1733. .channel_mode = alc880_w810_modes,
  1734. .input_mux = &alc880_capture_source,
  1735. },
  1736. [ALC880_Z71V] = {
  1737. .mixers = { alc880_z71v_mixer },
  1738. .init_verbs = { alc880_volume_init_verbs, alc880_pin_z71v_init_verbs },
  1739. .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
  1740. .dac_nids = alc880_z71v_dac_nids,
  1741. .dig_out_nid = ALC880_DIGOUT_NID,
  1742. .hp_nid = 0x03,
  1743. .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
  1744. .channel_mode = alc880_2_jack_modes,
  1745. .input_mux = &alc880_capture_source,
  1746. },
  1747. [ALC880_F1734] = {
  1748. .mixers = { alc880_f1734_mixer },
  1749. .init_verbs = { alc880_volume_init_verbs, alc880_pin_f1734_init_verbs },
  1750. .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
  1751. .dac_nids = alc880_f1734_dac_nids,
  1752. .hp_nid = 0x02,
  1753. .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
  1754. .channel_mode = alc880_2_jack_modes,
  1755. .input_mux = &alc880_capture_source,
  1756. },
  1757. [ALC880_ASUS] = {
  1758. .mixers = { alc880_asus_mixer },
  1759. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1760. alc880_gpio1_init_verbs },
  1761. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1762. .dac_nids = alc880_asus_dac_nids,
  1763. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1764. .channel_mode = alc880_asus_modes,
  1765. .input_mux = &alc880_capture_source,
  1766. },
  1767. [ALC880_ASUS_DIG] = {
  1768. .mixers = { alc880_asus_mixer },
  1769. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1770. alc880_gpio1_init_verbs },
  1771. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1772. .dac_nids = alc880_asus_dac_nids,
  1773. .dig_out_nid = ALC880_DIGOUT_NID,
  1774. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1775. .channel_mode = alc880_asus_modes,
  1776. .input_mux = &alc880_capture_source,
  1777. },
  1778. [ALC880_ASUS_DIG2] = {
  1779. .mixers = { alc880_asus_mixer },
  1780. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1781. alc880_gpio2_init_verbs }, /* use GPIO2 */
  1782. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1783. .dac_nids = alc880_asus_dac_nids,
  1784. .dig_out_nid = ALC880_DIGOUT_NID,
  1785. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1786. .channel_mode = alc880_asus_modes,
  1787. .input_mux = &alc880_capture_source,
  1788. },
  1789. [ALC880_ASUS_W1V] = {
  1790. .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
  1791. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1792. alc880_gpio1_init_verbs },
  1793. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1794. .dac_nids = alc880_asus_dac_nids,
  1795. .dig_out_nid = ALC880_DIGOUT_NID,
  1796. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1797. .channel_mode = alc880_asus_modes,
  1798. .input_mux = &alc880_capture_source,
  1799. },
  1800. [ALC880_UNIWILL_DIG] = {
  1801. .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
  1802. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs },
  1803. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1804. .dac_nids = alc880_asus_dac_nids,
  1805. .dig_out_nid = ALC880_DIGOUT_NID,
  1806. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1807. .channel_mode = alc880_asus_modes,
  1808. .input_mux = &alc880_capture_source,
  1809. },
  1810. [ALC880_CLEVO] = {
  1811. .mixers = { alc880_three_stack_mixer },
  1812. .init_verbs = { alc880_volume_init_verbs,
  1813. alc880_pin_clevo_init_verbs },
  1814. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1815. .dac_nids = alc880_dac_nids,
  1816. .hp_nid = 0x03,
  1817. .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
  1818. .channel_mode = alc880_threestack_modes,
  1819. .input_mux = &alc880_capture_source,
  1820. },
  1821. #ifdef CONFIG_SND_DEBUG
  1822. [ALC880_TEST] = {
  1823. .mixers = { alc880_test_mixer },
  1824. .init_verbs = { alc880_test_init_verbs },
  1825. .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
  1826. .dac_nids = alc880_test_dac_nids,
  1827. .dig_out_nid = ALC880_DIGOUT_NID,
  1828. .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
  1829. .channel_mode = alc880_test_modes,
  1830. .input_mux = &alc880_test_capture_source,
  1831. },
  1832. #endif
  1833. };
  1834. /*
  1835. * Automatic parse of I/O pins from the BIOS configuration
  1836. */
  1837. #define NUM_CONTROL_ALLOC 32
  1838. #define NUM_VERB_ALLOC 32
  1839. enum {
  1840. ALC_CTL_WIDGET_VOL,
  1841. ALC_CTL_WIDGET_MUTE,
  1842. ALC_CTL_BIND_MUTE,
  1843. };
  1844. static struct snd_kcontrol_new alc880_control_templates[] = {
  1845. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  1846. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  1847. HDA_BIND_MUTE(NULL, 0, 0, 0),
  1848. };
  1849. /* add dynamic controls */
  1850. static int add_control(struct alc_spec *spec, int type, const char *name, unsigned long val)
  1851. {
  1852. struct snd_kcontrol_new *knew;
  1853. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  1854. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  1855. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  1856. if (! knew)
  1857. return -ENOMEM;
  1858. if (spec->kctl_alloc) {
  1859. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1860. kfree(spec->kctl_alloc);
  1861. }
  1862. spec->kctl_alloc = knew;
  1863. spec->num_kctl_alloc = num;
  1864. }
  1865. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1866. *knew = alc880_control_templates[type];
  1867. knew->name = kstrdup(name, GFP_KERNEL);
  1868. if (! knew->name)
  1869. return -ENOMEM;
  1870. knew->private_value = val;
  1871. spec->num_kctl_used++;
  1872. return 0;
  1873. }
  1874. #define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
  1875. #define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
  1876. #define alc880_is_multi_pin(nid) ((nid) >= 0x18)
  1877. #define alc880_multi_pin_idx(nid) ((nid) - 0x18)
  1878. #define alc880_is_input_pin(nid) ((nid) >= 0x18)
  1879. #define alc880_input_pin_idx(nid) ((nid) - 0x18)
  1880. #define alc880_idx_to_dac(nid) ((nid) + 0x02)
  1881. #define alc880_dac_to_idx(nid) ((nid) - 0x02)
  1882. #define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
  1883. #define alc880_idx_to_selector(nid) ((nid) + 0x10)
  1884. #define ALC880_PIN_CD_NID 0x1c
  1885. /* fill in the dac_nids table from the parsed pin configuration */
  1886. static int alc880_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  1887. {
  1888. hda_nid_t nid;
  1889. int assigned[4];
  1890. int i, j;
  1891. memset(assigned, 0, sizeof(assigned));
  1892. spec->multiout.dac_nids = spec->private_dac_nids;
  1893. /* check the pins hardwired to audio widget */
  1894. for (i = 0; i < cfg->line_outs; i++) {
  1895. nid = cfg->line_out_pins[i];
  1896. if (alc880_is_fixed_pin(nid)) {
  1897. int idx = alc880_fixed_pin_idx(nid);
  1898. spec->multiout.dac_nids[i] = alc880_idx_to_dac(idx);
  1899. assigned[idx] = 1;
  1900. }
  1901. }
  1902. /* left pins can be connect to any audio widget */
  1903. for (i = 0; i < cfg->line_outs; i++) {
  1904. nid = cfg->line_out_pins[i];
  1905. if (alc880_is_fixed_pin(nid))
  1906. continue;
  1907. /* search for an empty channel */
  1908. for (j = 0; j < cfg->line_outs; j++) {
  1909. if (! assigned[j]) {
  1910. spec->multiout.dac_nids[i] = alc880_idx_to_dac(j);
  1911. assigned[j] = 1;
  1912. break;
  1913. }
  1914. }
  1915. }
  1916. spec->multiout.num_dacs = cfg->line_outs;
  1917. return 0;
  1918. }
  1919. /* add playback controls from the parsed DAC table */
  1920. static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec,
  1921. const struct auto_pin_cfg *cfg)
  1922. {
  1923. char name[32];
  1924. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  1925. hda_nid_t nid;
  1926. int i, err;
  1927. for (i = 0; i < cfg->line_outs; i++) {
  1928. if (! spec->multiout.dac_nids[i])
  1929. continue;
  1930. nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
  1931. if (i == 2) {
  1932. /* Center/LFE */
  1933. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Center Playback Volume",
  1934. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  1935. return err;
  1936. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "LFE Playback Volume",
  1937. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  1938. return err;
  1939. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
  1940. HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT))) < 0)
  1941. return err;
  1942. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
  1943. HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT))) < 0)
  1944. return err;
  1945. } else {
  1946. sprintf(name, "%s Playback Volume", chname[i]);
  1947. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
  1948. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  1949. return err;
  1950. sprintf(name, "%s Playback Switch", chname[i]);
  1951. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
  1952. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  1953. return err;
  1954. }
  1955. }
  1956. return 0;
  1957. }
  1958. /* add playback controls for speaker and HP outputs */
  1959. static int alc880_auto_create_extra_out(struct alc_spec *spec, hda_nid_t pin,
  1960. const char *pfx)
  1961. {
  1962. hda_nid_t nid;
  1963. int err;
  1964. char name[32];
  1965. if (! pin)
  1966. return 0;
  1967. if (alc880_is_fixed_pin(pin)) {
  1968. nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
  1969. if (! spec->multiout.dac_nids[0]) {
  1970. /* use this as the primary output */
  1971. spec->multiout.dac_nids[0] = nid;
  1972. if (! spec->multiout.num_dacs)
  1973. spec->multiout.num_dacs = 1;
  1974. } else
  1975. /* specify the DAC as the extra output */
  1976. spec->multiout.hp_nid = nid;
  1977. /* control HP volume/switch on the output mixer amp */
  1978. nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
  1979. sprintf(name, "%s Playback Volume", pfx);
  1980. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
  1981. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  1982. return err;
  1983. sprintf(name, "%s Playback Switch", pfx);
  1984. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
  1985. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  1986. return err;
  1987. } else if (alc880_is_multi_pin(pin)) {
  1988. /* set manual connection */
  1989. if (! spec->multiout.dac_nids[0]) {
  1990. /* use this as the primary output */
  1991. spec->multiout.dac_nids[0] = alc880_idx_to_dac(alc880_multi_pin_idx(pin));
  1992. if (! spec->multiout.num_dacs)
  1993. spec->multiout.num_dacs = 1;
  1994. }
  1995. /* we have only a switch on HP-out PIN */
  1996. sprintf(name, "%s Playback Switch", pfx);
  1997. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
  1998. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT))) < 0)
  1999. return err;
  2000. }
  2001. return 0;
  2002. }
  2003. /* create input playback/capture controls for the given pin */
  2004. static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, const char *ctlname,
  2005. int idx, hda_nid_t mix_nid)
  2006. {
  2007. char name[32];
  2008. int err;
  2009. sprintf(name, "%s Playback Volume", ctlname);
  2010. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
  2011. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT))) < 0)
  2012. return err;
  2013. sprintf(name, "%s Playback Switch", ctlname);
  2014. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
  2015. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT))) < 0)
  2016. return err;
  2017. return 0;
  2018. }
  2019. /* create playback/capture controls for input pins */
  2020. static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
  2021. const struct auto_pin_cfg *cfg)
  2022. {
  2023. struct hda_input_mux *imux = &spec->private_imux;
  2024. int i, err, idx;
  2025. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2026. if (alc880_is_input_pin(cfg->input_pins[i])) {
  2027. idx = alc880_input_pin_idx(cfg->input_pins[i]);
  2028. err = new_analog_input(spec, cfg->input_pins[i],
  2029. auto_pin_cfg_labels[i],
  2030. idx, 0x0b);
  2031. if (err < 0)
  2032. return err;
  2033. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  2034. imux->items[imux->num_items].index = alc880_input_pin_idx(cfg->input_pins[i]);
  2035. imux->num_items++;
  2036. }
  2037. }
  2038. return 0;
  2039. }
  2040. static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
  2041. hda_nid_t nid, int pin_type,
  2042. int dac_idx)
  2043. {
  2044. /* set as output */
  2045. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  2046. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  2047. /* need the manual connection? */
  2048. if (alc880_is_multi_pin(nid)) {
  2049. struct alc_spec *spec = codec->spec;
  2050. int idx = alc880_multi_pin_idx(nid);
  2051. snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
  2052. AC_VERB_SET_CONNECT_SEL,
  2053. alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
  2054. }
  2055. }
  2056. static void alc880_auto_init_multi_out(struct hda_codec *codec)
  2057. {
  2058. struct alc_spec *spec = codec->spec;
  2059. int i;
  2060. for (i = 0; i < spec->autocfg.line_outs; i++) {
  2061. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  2062. alc880_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  2063. }
  2064. }
  2065. static void alc880_auto_init_extra_out(struct hda_codec *codec)
  2066. {
  2067. struct alc_spec *spec = codec->spec;
  2068. hda_nid_t pin;
  2069. pin = spec->autocfg.speaker_pin;
  2070. if (pin) /* connect to front */
  2071. alc880_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
  2072. pin = spec->autocfg.hp_pin;
  2073. if (pin) /* connect to front */
  2074. alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  2075. }
  2076. static void alc880_auto_init_analog_input(struct hda_codec *codec)
  2077. {
  2078. struct alc_spec *spec = codec->spec;
  2079. int i;
  2080. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2081. hda_nid_t nid = spec->autocfg.input_pins[i];
  2082. if (alc880_is_input_pin(nid)) {
  2083. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  2084. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  2085. if (nid != ALC880_PIN_CD_NID)
  2086. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2087. AMP_OUT_MUTE);
  2088. }
  2089. }
  2090. }
  2091. /* parse the BIOS configuration and set up the alc_spec */
  2092. /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  2093. static int alc880_parse_auto_config(struct hda_codec *codec)
  2094. {
  2095. struct alc_spec *spec = codec->spec;
  2096. int err;
  2097. static hda_nid_t alc880_ignore[] = { 0x1d, 0 };
  2098. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
  2099. alc880_ignore)) < 0)
  2100. return err;
  2101. if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
  2102. ! spec->autocfg.hp_pin)
  2103. return 0; /* can't find valid BIOS pin config */
  2104. if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
  2105. (err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  2106. (err = alc880_auto_create_extra_out(spec, spec->autocfg.speaker_pin,
  2107. "Speaker")) < 0 ||
  2108. (err = alc880_auto_create_extra_out(spec, spec->autocfg.speaker_pin,
  2109. "Headphone")) < 0 ||
  2110. (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  2111. return err;
  2112. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2113. if (spec->autocfg.dig_out_pin)
  2114. spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
  2115. if (spec->autocfg.dig_in_pin)
  2116. spec->dig_in_nid = ALC880_DIGIN_NID;
  2117. if (spec->kctl_alloc)
  2118. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  2119. spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
  2120. spec->input_mux = &spec->private_imux;
  2121. return 1;
  2122. }
  2123. /* init callback for auto-configuration model -- overriding the default init */
  2124. static int alc880_auto_init(struct hda_codec *codec)
  2125. {
  2126. alc_init(codec);
  2127. alc880_auto_init_multi_out(codec);
  2128. alc880_auto_init_extra_out(codec);
  2129. alc880_auto_init_analog_input(codec);
  2130. return 0;
  2131. }
  2132. /*
  2133. * OK, here we have finally the patch for ALC880
  2134. */
  2135. static int patch_alc880(struct hda_codec *codec)
  2136. {
  2137. struct alc_spec *spec;
  2138. int board_config;
  2139. int err;
  2140. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2141. if (spec == NULL)
  2142. return -ENOMEM;
  2143. codec->spec = spec;
  2144. board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
  2145. if (board_config < 0 || board_config >= ALC880_MODEL_LAST) {
  2146. printk(KERN_INFO "hda_codec: Unknown model for ALC880, trying auto-probe from BIOS...\n");
  2147. board_config = ALC880_AUTO;
  2148. }
  2149. if (board_config == ALC880_AUTO) {
  2150. /* automatic parse from the BIOS config */
  2151. err = alc880_parse_auto_config(codec);
  2152. if (err < 0) {
  2153. alc_free(codec);
  2154. return err;
  2155. } else if (! err) {
  2156. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 3-stack mode...\n");
  2157. board_config = ALC880_3ST;
  2158. }
  2159. }
  2160. if (board_config != ALC880_AUTO)
  2161. setup_preset(spec, &alc880_presets[board_config]);
  2162. spec->stream_name_analog = "ALC880 Analog";
  2163. spec->stream_analog_playback = &alc880_pcm_analog_playback;
  2164. spec->stream_analog_capture = &alc880_pcm_analog_capture;
  2165. spec->stream_name_digital = "ALC880 Digital";
  2166. spec->stream_digital_playback = &alc880_pcm_digital_playback;
  2167. spec->stream_digital_capture = &alc880_pcm_digital_capture;
  2168. if (! spec->adc_nids && spec->input_mux) {
  2169. /* check whether NID 0x07 is valid */
  2170. unsigned int wcap = get_wcaps(codec, alc880_adc_nids[0]);
  2171. wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
  2172. if (wcap != AC_WID_AUD_IN) {
  2173. spec->adc_nids = alc880_adc_nids_alt;
  2174. spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
  2175. spec->mixers[spec->num_mixers] = alc880_capture_alt_mixer;
  2176. spec->num_mixers++;
  2177. } else {
  2178. spec->adc_nids = alc880_adc_nids;
  2179. spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
  2180. spec->mixers[spec->num_mixers] = alc880_capture_mixer;
  2181. spec->num_mixers++;
  2182. }
  2183. }
  2184. codec->patch_ops = alc_patch_ops;
  2185. if (board_config == ALC880_AUTO)
  2186. codec->patch_ops.init = alc880_auto_init;
  2187. return 0;
  2188. }
  2189. /*
  2190. * ALC260 support
  2191. */
  2192. static hda_nid_t alc260_dac_nids[1] = {
  2193. /* front */
  2194. 0x02,
  2195. };
  2196. static hda_nid_t alc260_adc_nids[1] = {
  2197. /* ADC0 */
  2198. 0x04,
  2199. };
  2200. static hda_nid_t alc260_adc_nids_alt[1] = {
  2201. /* ADC1 */
  2202. 0x05,
  2203. };
  2204. static hda_nid_t alc260_hp_adc_nids[2] = {
  2205. /* ADC1, 0 */
  2206. 0x05, 0x04
  2207. };
  2208. /* NIDs used when simultaneous access to both ADCs makes sense. Note that
  2209. * alc260_capture_mixer assumes ADC0 (nid 0x04) is the first ADC.
  2210. */
  2211. static hda_nid_t alc260_dual_adc_nids[2] = {
  2212. /* ADC0, ADC1 */
  2213. 0x04, 0x05
  2214. };
  2215. #define ALC260_DIGOUT_NID 0x03
  2216. #define ALC260_DIGIN_NID 0x06
  2217. static struct hda_input_mux alc260_capture_source = {
  2218. .num_items = 4,
  2219. .items = {
  2220. { "Mic", 0x0 },
  2221. { "Front Mic", 0x1 },
  2222. { "Line", 0x2 },
  2223. { "CD", 0x4 },
  2224. },
  2225. };
  2226. /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack,
  2227. * headphone jack and the internal CD lines.
  2228. */
  2229. static struct hda_input_mux alc260_fujitsu_capture_source = {
  2230. .num_items = 3,
  2231. .items = {
  2232. { "Mic/Line", 0x0 },
  2233. { "CD", 0x4 },
  2234. { "Headphone", 0x2 },
  2235. },
  2236. };
  2237. /*
  2238. * This is just place-holder, so there's something for alc_build_pcms to look
  2239. * at when it calculates the maximum number of channels. ALC260 has no mixer
  2240. * element which allows changing the channel mode, so the verb list is
  2241. * never used.
  2242. */
  2243. static struct hda_channel_mode alc260_modes[1] = {
  2244. { 2, NULL },
  2245. };
  2246. /* Mixer combinations
  2247. *
  2248. * basic: base_output + input + pc_beep + capture
  2249. * HP: base_output + input + capture_alt
  2250. * HP_3013: hp_3013 + input + capture
  2251. * fujitsu: fujitsu + capture
  2252. */
  2253. static struct snd_kcontrol_new alc260_base_output_mixer[] = {
  2254. HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  2255. HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
  2256. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  2257. HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
  2258. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  2259. HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
  2260. { } /* end */
  2261. };
  2262. static struct snd_kcontrol_new alc260_input_mixer[] = {
  2263. HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
  2264. HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
  2265. HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
  2266. HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
  2267. HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
  2268. HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
  2269. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
  2270. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
  2271. { } /* end */
  2272. };
  2273. static struct snd_kcontrol_new alc260_pc_beep_mixer[] = {
  2274. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
  2275. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
  2276. { } /* end */
  2277. };
  2278. static struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
  2279. HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  2280. HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  2281. HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
  2282. HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
  2283. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  2284. HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  2285. HDA_CODEC_VOLUME_MONO("iSpeaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  2286. HDA_CODEC_MUTE_MONO("iSpeaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
  2287. { } /* end */
  2288. };
  2289. static struct snd_kcontrol_new alc260_fujitsu_mixer[] = {
  2290. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  2291. HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
  2292. ALC_PIN_MODE("Headphone Jack Mode", 0x14, ALC_PIN_DIR_INOUT),
  2293. HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
  2294. HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
  2295. HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
  2296. HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
  2297. ALC_PIN_MODE("Mic/Line Jack Mode", 0x12, ALC_PIN_DIR_IN),
  2298. HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
  2299. HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
  2300. HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  2301. HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
  2302. { } /* end */
  2303. };
  2304. /* capture mixer elements */
  2305. static struct snd_kcontrol_new alc260_capture_mixer[] = {
  2306. HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
  2307. HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
  2308. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x05, 0x0, HDA_INPUT),
  2309. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x05, 0x0, HDA_INPUT),
  2310. {
  2311. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2312. /* The multiple "Capture Source" controls confuse alsamixer
  2313. * So call somewhat different..
  2314. * FIXME: the controls appear in the "playback" view!
  2315. */
  2316. /* .name = "Capture Source", */
  2317. .name = "Input Source",
  2318. .count = 2,
  2319. .info = alc_mux_enum_info,
  2320. .get = alc_mux_enum_get,
  2321. .put = alc_mux_enum_put,
  2322. },
  2323. { } /* end */
  2324. };
  2325. static struct snd_kcontrol_new alc260_capture_alt_mixer[] = {
  2326. HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
  2327. HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
  2328. {
  2329. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2330. /* The multiple "Capture Source" controls confuse alsamixer
  2331. * So call somewhat different..
  2332. * FIXME: the controls appear in the "playback" view!
  2333. */
  2334. /* .name = "Capture Source", */
  2335. .name = "Input Source",
  2336. .count = 1,
  2337. .info = alc_mux_enum_info,
  2338. .get = alc_mux_enum_get,
  2339. .put = alc_mux_enum_put,
  2340. },
  2341. { } /* end */
  2342. };
  2343. /*
  2344. * initialization verbs
  2345. */
  2346. static struct hda_verb alc260_init_verbs[] = {
  2347. /* Line In pin widget for input */
  2348. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2349. /* CD pin widget for input */
  2350. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2351. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  2352. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2353. /* Mic2 (front panel) pin widget for input and vref at 80% */
  2354. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2355. /* LINE-2 is used for line-out in rear */
  2356. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2357. /* select line-out */
  2358. {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
  2359. /* LINE-OUT pin */
  2360. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2361. /* enable HP */
  2362. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2363. /* enable Mono */
  2364. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2365. /* mute capture amp left and right */
  2366. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2367. /* set connection select to line in (default select for this ADC) */
  2368. {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
  2369. /* mute capture amp left and right */
  2370. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2371. /* set connection select to line in (default select for this ADC) */
  2372. {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
  2373. /* set vol=0 Line-Out mixer amp left and right */
  2374. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2375. /* unmute pin widget amp left and right (no gain on this amp) */
  2376. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2377. /* set vol=0 HP mixer amp left and right */
  2378. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2379. /* unmute pin widget amp left and right (no gain on this amp) */
  2380. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2381. /* set vol=0 Mono mixer amp left and right */
  2382. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2383. /* unmute pin widget amp left and right (no gain on this amp) */
  2384. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2385. /* unmute LINE-2 out pin */
  2386. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2387. /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
  2388. /* mute CD */
  2389. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2390. /* mute Line In */
  2391. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2392. /* mute Mic */
  2393. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2394. /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
  2395. /* mute Front out path */
  2396. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2397. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2398. /* mute Headphone out path */
  2399. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2400. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2401. /* mute Mono out path */
  2402. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2403. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2404. { }
  2405. };
  2406. static struct hda_verb alc260_hp_init_verbs[] = {
  2407. /* Headphone and output */
  2408. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
  2409. /* mono output */
  2410. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2411. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  2412. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
  2413. /* Mic2 (front panel) pin widget for input and vref at 80% */
  2414. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
  2415. /* Line In pin widget for input */
  2416. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2417. /* Line-2 pin widget for output */
  2418. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2419. /* CD pin widget for input */
  2420. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2421. /* unmute amp left and right */
  2422. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
  2423. /* set connection select to line in (default select for this ADC) */
  2424. {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
  2425. /* unmute Line-Out mixer amp left and right (volume = 0) */
  2426. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  2427. /* mute pin widget amp left and right (no gain on this amp) */
  2428. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  2429. /* unmute HP mixer amp left and right (volume = 0) */
  2430. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  2431. /* mute pin widget amp left and right (no gain on this amp) */
  2432. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  2433. /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
  2434. /* unmute CD */
  2435. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
  2436. /* unmute Line In */
  2437. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
  2438. /* unmute Mic */
  2439. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2440. /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
  2441. /* Unmute Front out path */
  2442. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2443. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
  2444. /* Unmute Headphone out path */
  2445. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2446. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
  2447. /* Unmute Mono out path */
  2448. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2449. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
  2450. { }
  2451. };
  2452. static struct hda_verb alc260_hp_3013_init_verbs[] = {
  2453. /* Line out and output */
  2454. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2455. /* mono output */
  2456. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2457. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  2458. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
  2459. /* Mic2 (front panel) pin widget for input and vref at 80% */
  2460. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
  2461. /* Line In pin widget for input */
  2462. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2463. /* Headphone pin widget for output */
  2464. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
  2465. /* CD pin widget for input */
  2466. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2467. /* unmute amp left and right */
  2468. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
  2469. /* set connection select to line in (default select for this ADC) */
  2470. {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
  2471. /* unmute Line-Out mixer amp left and right (volume = 0) */
  2472. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  2473. /* mute pin widget amp left and right (no gain on this amp) */
  2474. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  2475. /* unmute HP mixer amp left and right (volume = 0) */
  2476. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  2477. /* mute pin widget amp left and right (no gain on this amp) */
  2478. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  2479. /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
  2480. /* unmute CD */
  2481. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
  2482. /* unmute Line In */
  2483. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
  2484. /* unmute Mic */
  2485. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2486. /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
  2487. /* Unmute Front out path */
  2488. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2489. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
  2490. /* Unmute Headphone out path */
  2491. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2492. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
  2493. /* Unmute Mono out path */
  2494. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  2495. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
  2496. { }
  2497. };
  2498. /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
  2499. * laptops.
  2500. */
  2501. static struct hda_verb alc260_fujitsu_init_verbs[] = {
  2502. /* Disable all GPIOs */
  2503. {0x01, AC_VERB_SET_GPIO_MASK, 0},
  2504. /* Internal speaker is connected to headphone pin */
  2505. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2506. /* Headphone/Line-out jack connects to Line1 pin; make it an output */
  2507. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2508. /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
  2509. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2510. /* Ensure all other unused pins are disabled and muted.
  2511. * Note: trying to set widget 0x15 to anything blocks all audio
  2512. * output for some reason, so just leave that at the default.
  2513. */
  2514. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2515. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2516. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2517. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2518. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2519. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2520. /* Disable digital (SPDIF) pins */
  2521. {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
  2522. {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
  2523. /* Ensure Line1 pin widget takes its input from the OUT1 sum bus
  2524. * when acting as an output.
  2525. */
  2526. {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
  2527. /* Start with output sum widgets muted and their output gains at min */
  2528. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2529. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2530. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2531. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2532. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2533. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2534. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2535. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2536. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2537. /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
  2538. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2539. /* Unmute Line1 pin widget output buffer since it starts as an output.
  2540. * If the pin mode is changed by the user the pin mode control will
  2541. * take care of enabling the pin's input/output buffers as needed.
  2542. * Therefore there's no need to enable the input buffer at this
  2543. * stage.
  2544. */
  2545. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2546. /* Unmute input buffer of pin widget used for Line-in (no equiv
  2547. * mixer ctrl)
  2548. */
  2549. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2550. /* Mute capture amp left and right */
  2551. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2552. /* Set ADC connection select to match default mixer setting - line
  2553. * in (on mic1 pin)
  2554. */
  2555. {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
  2556. /* Do the same for the second ADC: mute capture input amp and
  2557. * set ADC connection to line in
  2558. */
  2559. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2560. {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
  2561. /* Mute all inputs to mixer widget (even unconnected ones) */
  2562. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  2563. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  2564. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  2565. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  2566. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  2567. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  2568. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  2569. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  2570. { }
  2571. };
  2572. /* Test configuration for debugging, modelled after the ALC880 test
  2573. * configuration.
  2574. */
  2575. #ifdef CONFIG_SND_DEBUG
  2576. static hda_nid_t alc260_test_dac_nids[1] = {
  2577. 0x02,
  2578. };
  2579. static hda_nid_t alc260_test_adc_nids[2] = {
  2580. 0x04, 0x05,
  2581. };
  2582. /* This is a bit messy since the two input muxes in the ALC260 have slight
  2583. * variations in their signal assignments. The ideal way to deal with this
  2584. * is to extend alc_spec.input_mux to allow a different input MUX for each
  2585. * ADC. For the purposes of the test model it's sufficient to just list
  2586. * both options for affected signal indices. The separate input mux
  2587. * functionality only needs to be considered if a model comes along which
  2588. * actually uses signals 0x5, 0x6 and 0x7 for something which makes sense to
  2589. * record.
  2590. */
  2591. static struct hda_input_mux alc260_test_capture_source = {
  2592. .num_items = 8,
  2593. .items = {
  2594. { "MIC1 pin", 0x0 },
  2595. { "MIC2 pin", 0x1 },
  2596. { "LINE1 pin", 0x2 },
  2597. { "LINE2 pin", 0x3 },
  2598. { "CD pin", 0x4 },
  2599. { "LINE-OUT pin (cap1), Mixer (cap2)", 0x5 },
  2600. { "HP-OUT pin (cap1), LINE-OUT pin (cap2)", 0x6 },
  2601. { "HP-OUT pin (cap2 only)", 0x7 },
  2602. },
  2603. };
  2604. static struct snd_kcontrol_new alc260_test_mixer[] = {
  2605. /* Output driver widgets */
  2606. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  2607. HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
  2608. HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  2609. HDA_BIND_MUTE("LOUT2 Playback Switch", 0x09, 2, HDA_INPUT),
  2610. HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  2611. HDA_BIND_MUTE("LOUT1 Playback Switch", 0x08, 2, HDA_INPUT),
  2612. /* Modes for retasking pin widgets */
  2613. ALC_PIN_MODE("HP-OUT pin mode", 0x10, ALC_PIN_DIR_INOUT),
  2614. ALC_PIN_MODE("LINE-OUT pin mode", 0x0f, ALC_PIN_DIR_INOUT),
  2615. ALC_PIN_MODE("LINE2 pin mode", 0x15, ALC_PIN_DIR_INOUT),
  2616. ALC_PIN_MODE("LINE1 pin mode", 0x14, ALC_PIN_DIR_INOUT),
  2617. ALC_PIN_MODE("MIC2 pin mode", 0x13, ALC_PIN_DIR_INOUT),
  2618. ALC_PIN_MODE("MIC1 pin mode", 0x12, ALC_PIN_DIR_INOUT),
  2619. /* Loopback mixer controls */
  2620. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x07, 0x00, HDA_INPUT),
  2621. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x07, 0x00, HDA_INPUT),
  2622. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x07, 0x01, HDA_INPUT),
  2623. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x07, 0x01, HDA_INPUT),
  2624. HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x07, 0x02, HDA_INPUT),
  2625. HDA_CODEC_MUTE("LINE1 Playback Switch", 0x07, 0x02, HDA_INPUT),
  2626. HDA_CODEC_VOLUME("LINE2 Playback Volume", 0x07, 0x03, HDA_INPUT),
  2627. HDA_CODEC_MUTE("LINE2 Playback Switch", 0x07, 0x03, HDA_INPUT),
  2628. HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
  2629. HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
  2630. HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
  2631. HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
  2632. HDA_CODEC_VOLUME("LINE-OUT loopback Playback Volume", 0x07, 0x06, HDA_INPUT),
  2633. HDA_CODEC_MUTE("LINE-OUT loopback Playback Switch", 0x07, 0x06, HDA_INPUT),
  2634. HDA_CODEC_VOLUME("HP-OUT loopback Playback Volume", 0x07, 0x7, HDA_INPUT),
  2635. HDA_CODEC_MUTE("HP-OUT loopback Playback Switch", 0x07, 0x7, HDA_INPUT),
  2636. /* Controls for GPIO pins, assuming they are configured as outputs */
  2637. ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
  2638. ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
  2639. ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
  2640. ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
  2641. { } /* end */
  2642. };
  2643. static struct hda_verb alc260_test_init_verbs[] = {
  2644. /* Enable all GPIOs as outputs with an initial value of 0 */
  2645. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x0f},
  2646. {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
  2647. {0x01, AC_VERB_SET_GPIO_MASK, 0x0f},
  2648. /* Enable retasking pins as output, initially without power amp */
  2649. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2650. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2651. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2652. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2653. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2654. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2655. /* Disable digital (SPDIF) pins for now */
  2656. {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
  2657. {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
  2658. /* Ensure mic1, mic2, line1 and line2 pin widget take input from the
  2659. * OUT1 sum bus when acting as an output.
  2660. */
  2661. {0x0b, AC_VERB_SET_CONNECT_SEL, 0},
  2662. {0x0c, AC_VERB_SET_CONNECT_SEL, 0},
  2663. {0x0d, AC_VERB_SET_CONNECT_SEL, 0},
  2664. {0x0e, AC_VERB_SET_CONNECT_SEL, 0},
  2665. /* Start with output sum widgets muted and their output gains at min */
  2666. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2667. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2668. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2669. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2670. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2671. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2672. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2673. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2674. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2675. /* Unmute retasking pin widget output buffers since the default
  2676. * state appears to be output. As the pin mode is changed by the
  2677. * user the pin mode control will take care of enabling the pin's
  2678. * input/output buffers as needed.
  2679. */
  2680. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2681. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2682. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2683. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2684. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2685. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2686. /* Also unmute the mono-out pin widget */
  2687. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2688. /* Mute capture amp left and right */
  2689. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2690. /* Set ADC connection select to match default mixer setting - line
  2691. * in (on mic1 pin)
  2692. */
  2693. {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
  2694. /* Do the same for the second ADC: mute capture input amp and
  2695. * set ADC connection to line in
  2696. */
  2697. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2698. {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
  2699. /* Mute all inputs to mixer widget (even unconnected ones) */
  2700. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  2701. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  2702. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  2703. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  2704. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  2705. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  2706. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  2707. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  2708. { }
  2709. };
  2710. #endif
  2711. static struct hda_pcm_stream alc260_pcm_analog_playback = {
  2712. .substreams = 1,
  2713. .channels_min = 2,
  2714. .channels_max = 2,
  2715. };
  2716. static struct hda_pcm_stream alc260_pcm_analog_capture = {
  2717. .substreams = 1,
  2718. .channels_min = 2,
  2719. .channels_max = 2,
  2720. };
  2721. #define alc260_pcm_digital_playback alc880_pcm_digital_playback
  2722. #define alc260_pcm_digital_capture alc880_pcm_digital_capture
  2723. /*
  2724. * for BIOS auto-configuration
  2725. */
  2726. static int alc260_add_playback_controls(struct alc_spec *spec, hda_nid_t nid,
  2727. const char *pfx)
  2728. {
  2729. hda_nid_t nid_vol;
  2730. unsigned long vol_val, sw_val;
  2731. char name[32];
  2732. int err;
  2733. if (nid >= 0x0f && nid < 0x11) {
  2734. nid_vol = nid - 0x7;
  2735. vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
  2736. sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2737. } else if (nid == 0x11) {
  2738. nid_vol = nid - 0x7;
  2739. vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0, HDA_OUTPUT);
  2740. sw_val = HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT);
  2741. } else if (nid >= 0x12 && nid <= 0x15) {
  2742. nid_vol = 0x08;
  2743. vol_val = HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0, HDA_OUTPUT);
  2744. sw_val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
  2745. } else
  2746. return 0; /* N/A */
  2747. snprintf(name, sizeof(name), "%s Playback Volume", pfx);
  2748. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name, vol_val)) < 0)
  2749. return err;
  2750. snprintf(name, sizeof(name), "%s Playback Switch", pfx);
  2751. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name, sw_val)) < 0)
  2752. return err;
  2753. return 1;
  2754. }
  2755. /* add playback controls from the parsed DAC table */
  2756. static int alc260_auto_create_multi_out_ctls(struct alc_spec *spec,
  2757. const struct auto_pin_cfg *cfg)
  2758. {
  2759. hda_nid_t nid;
  2760. int err;
  2761. spec->multiout.num_dacs = 1;
  2762. spec->multiout.dac_nids = spec->private_dac_nids;
  2763. spec->multiout.dac_nids[0] = 0x02;
  2764. nid = cfg->line_out_pins[0];
  2765. if (nid) {
  2766. err = alc260_add_playback_controls(spec, nid, "Front");
  2767. if (err < 0)
  2768. return err;
  2769. }
  2770. nid = cfg->speaker_pin;
  2771. if (nid) {
  2772. err = alc260_add_playback_controls(spec, nid, "Speaker");
  2773. if (err < 0)
  2774. return err;
  2775. }
  2776. nid = cfg->hp_pin;
  2777. if (nid) {
  2778. err = alc260_add_playback_controls(spec, nid, "Headphone");
  2779. if (err < 0)
  2780. return err;
  2781. }
  2782. return 0;
  2783. }
  2784. /* create playback/capture controls for input pins */
  2785. static int alc260_auto_create_analog_input_ctls(struct alc_spec *spec,
  2786. const struct auto_pin_cfg *cfg)
  2787. {
  2788. struct hda_input_mux *imux = &spec->private_imux;
  2789. int i, err, idx;
  2790. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2791. if (cfg->input_pins[i] >= 0x12) {
  2792. idx = cfg->input_pins[i] - 0x12;
  2793. err = new_analog_input(spec, cfg->input_pins[i],
  2794. auto_pin_cfg_labels[i], idx, 0x07);
  2795. if (err < 0)
  2796. return err;
  2797. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  2798. imux->items[imux->num_items].index = idx;
  2799. imux->num_items++;
  2800. }
  2801. if ((cfg->input_pins[i] >= 0x0f) && (cfg->input_pins[i] <= 0x10)){
  2802. idx = cfg->input_pins[i] - 0x09;
  2803. err = new_analog_input(spec, cfg->input_pins[i],
  2804. auto_pin_cfg_labels[i], idx, 0x07);
  2805. if (err < 0)
  2806. return err;
  2807. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  2808. imux->items[imux->num_items].index = idx;
  2809. imux->num_items++;
  2810. }
  2811. }
  2812. return 0;
  2813. }
  2814. static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
  2815. hda_nid_t nid, int pin_type,
  2816. int sel_idx)
  2817. {
  2818. /* set as output */
  2819. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  2820. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  2821. /* need the manual connection? */
  2822. if (nid >= 0x12) {
  2823. int idx = nid - 0x12;
  2824. snd_hda_codec_write(codec, idx + 0x0b, 0,
  2825. AC_VERB_SET_CONNECT_SEL, sel_idx);
  2826. }
  2827. }
  2828. static void alc260_auto_init_multi_out(struct hda_codec *codec)
  2829. {
  2830. struct alc_spec *spec = codec->spec;
  2831. hda_nid_t nid;
  2832. nid = spec->autocfg.line_out_pins[0];
  2833. if (nid)
  2834. alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
  2835. nid = spec->autocfg.speaker_pin;
  2836. if (nid)
  2837. alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
  2838. nid = spec->autocfg.hp_pin;
  2839. if (nid)
  2840. alc260_auto_set_output_and_unmute(codec, nid, PIN_OUT, 0);
  2841. }
  2842. #define ALC260_PIN_CD_NID 0x16
  2843. static void alc260_auto_init_analog_input(struct hda_codec *codec)
  2844. {
  2845. struct alc_spec *spec = codec->spec;
  2846. int i;
  2847. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2848. hda_nid_t nid = spec->autocfg.input_pins[i];
  2849. if (nid >= 0x12) {
  2850. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  2851. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  2852. if (nid != ALC260_PIN_CD_NID)
  2853. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2854. AMP_OUT_MUTE);
  2855. }
  2856. }
  2857. }
  2858. /*
  2859. * generic initialization of ADC, input mixers and output mixers
  2860. */
  2861. static struct hda_verb alc260_volume_init_verbs[] = {
  2862. /*
  2863. * Unmute ADC0-1 and set the default input to mic-in
  2864. */
  2865. {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
  2866. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2867. {0x05, AC_VERB_SET_CONNECT_SEL, 0x00},
  2868. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2869. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2870. * mixer widget
  2871. * Note: PASD motherboards uses the Line In 2 as the input for front panel
  2872. * mic (mic 2)
  2873. */
  2874. /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
  2875. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2876. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2877. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2878. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2879. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2880. /*
  2881. * Set up output mixers (0x08 - 0x0a)
  2882. */
  2883. /* set vol=0 to output mixers */
  2884. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2885. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2886. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2887. /* set up input amps for analog loopback */
  2888. /* Amp Indices: DAC = 0, mixer = 1 */
  2889. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2890. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2891. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2892. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2893. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2894. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2895. { }
  2896. };
  2897. static int alc260_parse_auto_config(struct hda_codec *codec)
  2898. {
  2899. struct alc_spec *spec = codec->spec;
  2900. unsigned int wcap;
  2901. int err;
  2902. static hda_nid_t alc260_ignore[] = { 0x17, 0 };
  2903. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
  2904. alc260_ignore)) < 0)
  2905. return err;
  2906. if ((err = alc260_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0)
  2907. return err;
  2908. if (! spec->kctl_alloc)
  2909. return 0; /* can't find valid BIOS pin config */
  2910. if ((err = alc260_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  2911. return err;
  2912. spec->multiout.max_channels = 2;
  2913. if (spec->autocfg.dig_out_pin)
  2914. spec->multiout.dig_out_nid = ALC260_DIGOUT_NID;
  2915. if (spec->kctl_alloc)
  2916. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  2917. spec->init_verbs[spec->num_init_verbs++] = alc260_volume_init_verbs;
  2918. spec->input_mux = &spec->private_imux;
  2919. /* check whether NID 0x04 is valid */
  2920. wcap = get_wcaps(codec, 0x04);
  2921. wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
  2922. if (wcap != AC_WID_AUD_IN) {
  2923. spec->adc_nids = alc260_adc_nids_alt;
  2924. spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
  2925. spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
  2926. } else {
  2927. spec->adc_nids = alc260_adc_nids;
  2928. spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
  2929. spec->mixers[spec->num_mixers] = alc260_capture_mixer;
  2930. }
  2931. spec->num_mixers++;
  2932. return 1;
  2933. }
  2934. /* init callback for auto-configuration model -- overriding the default init */
  2935. static int alc260_auto_init(struct hda_codec *codec)
  2936. {
  2937. alc_init(codec);
  2938. alc260_auto_init_multi_out(codec);
  2939. alc260_auto_init_analog_input(codec);
  2940. return 0;
  2941. }
  2942. /*
  2943. * ALC260 configurations
  2944. */
  2945. static struct hda_board_config alc260_cfg_tbl[] = {
  2946. { .modelname = "basic", .config = ALC260_BASIC },
  2947. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81bb,
  2948. .config = ALC260_BASIC }, /* Sony VAIO */
  2949. { .modelname = "hp", .config = ALC260_HP },
  2950. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3010, .config = ALC260_HP },
  2951. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3011, .config = ALC260_HP },
  2952. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3012, .config = ALC260_HP },
  2953. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3013, .config = ALC260_HP_3013 },
  2954. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3014, .config = ALC260_HP },
  2955. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3015, .config = ALC260_HP },
  2956. { .pci_subvendor = 0x103c, .pci_subdevice = 0x3016, .config = ALC260_HP },
  2957. { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702X },
  2958. { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702X },
  2959. #ifdef CONFIG_SND_DEBUG
  2960. { .modelname = "test", .config = ALC260_TEST },
  2961. #endif
  2962. { .modelname = "auto", .config = ALC260_AUTO },
  2963. {}
  2964. };
  2965. static struct alc_config_preset alc260_presets[] = {
  2966. [ALC260_BASIC] = {
  2967. .mixers = { alc260_base_output_mixer,
  2968. alc260_input_mixer,
  2969. alc260_pc_beep_mixer,
  2970. alc260_capture_mixer },
  2971. .init_verbs = { alc260_init_verbs },
  2972. .num_dacs = ARRAY_SIZE(alc260_dac_nids),
  2973. .dac_nids = alc260_dac_nids,
  2974. .num_adc_nids = ARRAY_SIZE(alc260_adc_nids),
  2975. .adc_nids = alc260_adc_nids,
  2976. .num_channel_mode = ARRAY_SIZE(alc260_modes),
  2977. .channel_mode = alc260_modes,
  2978. .input_mux = &alc260_capture_source,
  2979. },
  2980. [ALC260_HP] = {
  2981. .mixers = { alc260_base_output_mixer,
  2982. alc260_input_mixer,
  2983. alc260_capture_alt_mixer },
  2984. .init_verbs = { alc260_hp_init_verbs },
  2985. .num_dacs = ARRAY_SIZE(alc260_dac_nids),
  2986. .dac_nids = alc260_dac_nids,
  2987. .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
  2988. .adc_nids = alc260_hp_adc_nids,
  2989. .num_channel_mode = ARRAY_SIZE(alc260_modes),
  2990. .channel_mode = alc260_modes,
  2991. .input_mux = &alc260_capture_source,
  2992. },
  2993. [ALC260_HP_3013] = {
  2994. .mixers = { alc260_hp_3013_mixer,
  2995. alc260_input_mixer,
  2996. alc260_capture_alt_mixer },
  2997. .init_verbs = { alc260_hp_3013_init_verbs },
  2998. .num_dacs = ARRAY_SIZE(alc260_dac_nids),
  2999. .dac_nids = alc260_dac_nids,
  3000. .num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids),
  3001. .adc_nids = alc260_hp_adc_nids,
  3002. .num_channel_mode = ARRAY_SIZE(alc260_modes),
  3003. .channel_mode = alc260_modes,
  3004. .input_mux = &alc260_capture_source,
  3005. },
  3006. [ALC260_FUJITSU_S702X] = {
  3007. .mixers = { alc260_fujitsu_mixer,
  3008. alc260_capture_mixer },
  3009. .init_verbs = { alc260_fujitsu_init_verbs },
  3010. .num_dacs = ARRAY_SIZE(alc260_dac_nids),
  3011. .dac_nids = alc260_dac_nids,
  3012. .num_adc_nids = ARRAY_SIZE(alc260_dual_adc_nids),
  3013. .adc_nids = alc260_dual_adc_nids,
  3014. .num_channel_mode = ARRAY_SIZE(alc260_modes),
  3015. .channel_mode = alc260_modes,
  3016. .input_mux = &alc260_fujitsu_capture_source,
  3017. },
  3018. #ifdef CONFIG_SND_DEBUG
  3019. [ALC260_TEST] = {
  3020. .mixers = { alc260_test_mixer,
  3021. alc260_capture_mixer },
  3022. .init_verbs = { alc260_test_init_verbs },
  3023. .num_dacs = ARRAY_SIZE(alc260_test_dac_nids),
  3024. .dac_nids = alc260_test_dac_nids,
  3025. .num_adc_nids = ARRAY_SIZE(alc260_test_adc_nids),
  3026. .adc_nids = alc260_test_adc_nids,
  3027. .num_channel_mode = ARRAY_SIZE(alc260_modes),
  3028. .channel_mode = alc260_modes,
  3029. .input_mux = &alc260_test_capture_source,
  3030. },
  3031. #endif
  3032. };
  3033. static int patch_alc260(struct hda_codec *codec)
  3034. {
  3035. struct alc_spec *spec;
  3036. int err, board_config;
  3037. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3038. if (spec == NULL)
  3039. return -ENOMEM;
  3040. codec->spec = spec;
  3041. board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
  3042. if (board_config < 0 || board_config >= ALC260_MODEL_LAST) {
  3043. snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260\n");
  3044. board_config = ALC260_AUTO;
  3045. }
  3046. if (board_config == ALC260_AUTO) {
  3047. /* automatic parse from the BIOS config */
  3048. err = alc260_parse_auto_config(codec);
  3049. if (err < 0) {
  3050. alc_free(codec);
  3051. return err;
  3052. } else if (! err) {
  3053. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using base mode...\n");
  3054. board_config = ALC260_BASIC;
  3055. }
  3056. }
  3057. if (board_config != ALC260_AUTO)
  3058. setup_preset(spec, &alc260_presets[board_config]);
  3059. spec->stream_name_analog = "ALC260 Analog";
  3060. spec->stream_analog_playback = &alc260_pcm_analog_playback;
  3061. spec->stream_analog_capture = &alc260_pcm_analog_capture;
  3062. spec->stream_name_digital = "ALC260 Digital";
  3063. spec->stream_digital_playback = &alc260_pcm_digital_playback;
  3064. spec->stream_digital_capture = &alc260_pcm_digital_capture;
  3065. codec->patch_ops = alc_patch_ops;
  3066. if (board_config == ALC260_AUTO)
  3067. codec->patch_ops.init = alc260_auto_init;
  3068. return 0;
  3069. }
  3070. /*
  3071. * ALC882 support
  3072. *
  3073. * ALC882 is almost identical with ALC880 but has cleaner and more flexible
  3074. * configuration. Each pin widget can choose any input DACs and a mixer.
  3075. * Each ADC is connected from a mixer of all inputs. This makes possible
  3076. * 6-channel independent captures.
  3077. *
  3078. * In addition, an independent DAC for the multi-playback (not used in this
  3079. * driver yet).
  3080. */
  3081. #define ALC882_DIGOUT_NID 0x06
  3082. #define ALC882_DIGIN_NID 0x0a
  3083. static struct hda_channel_mode alc882_ch_modes[1] = {
  3084. { 8, NULL }
  3085. };
  3086. static hda_nid_t alc882_dac_nids[4] = {
  3087. /* front, rear, clfe, rear_surr */
  3088. 0x02, 0x03, 0x04, 0x05
  3089. };
  3090. /* identical with ALC880 */
  3091. #define alc882_adc_nids alc880_adc_nids
  3092. #define alc882_adc_nids_alt alc880_adc_nids_alt
  3093. /* input MUX */
  3094. /* FIXME: should be a matrix-type input source selection */
  3095. static struct hda_input_mux alc882_capture_source = {
  3096. .num_items = 4,
  3097. .items = {
  3098. { "Mic", 0x0 },
  3099. { "Front Mic", 0x1 },
  3100. { "Line", 0x2 },
  3101. { "CD", 0x4 },
  3102. },
  3103. };
  3104. #define alc882_mux_enum_info alc_mux_enum_info
  3105. #define alc882_mux_enum_get alc_mux_enum_get
  3106. static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  3107. {
  3108. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3109. struct alc_spec *spec = codec->spec;
  3110. const struct hda_input_mux *imux = spec->input_mux;
  3111. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  3112. static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
  3113. hda_nid_t nid = capture_mixers[adc_idx];
  3114. unsigned int *cur_val = &spec->cur_mux[adc_idx];
  3115. unsigned int i, idx;
  3116. idx = ucontrol->value.enumerated.item[0];
  3117. if (idx >= imux->num_items)
  3118. idx = imux->num_items - 1;
  3119. if (*cur_val == idx && ! codec->in_resume)
  3120. return 0;
  3121. for (i = 0; i < imux->num_items; i++) {
  3122. unsigned int v = (i == idx) ? 0x7000 : 0x7080;
  3123. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3124. v | (imux->items[i].index << 8));
  3125. }
  3126. *cur_val = idx;
  3127. return 1;
  3128. }
  3129. /*
  3130. * 6ch mode
  3131. */
  3132. static struct hda_verb alc882_sixstack_ch6_init[] = {
  3133. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
  3134. { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3135. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3136. { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3137. { } /* end */
  3138. };
  3139. /*
  3140. * 8ch mode
  3141. */
  3142. static struct hda_verb alc882_sixstack_ch8_init[] = {
  3143. { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3144. { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3145. { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3146. { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  3147. { } /* end */
  3148. };
  3149. static struct hda_channel_mode alc882_sixstack_modes[2] = {
  3150. { 6, alc882_sixstack_ch6_init },
  3151. { 8, alc882_sixstack_ch8_init },
  3152. };
  3153. /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
  3154. * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
  3155. */
  3156. static struct snd_kcontrol_new alc882_base_mixer[] = {
  3157. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  3158. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  3159. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  3160. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  3161. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  3162. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  3163. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  3164. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  3165. HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  3166. HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
  3167. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  3168. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  3169. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  3170. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  3171. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  3172. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  3173. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  3174. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
  3175. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
  3176. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  3177. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  3178. HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
  3179. HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
  3180. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
  3181. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
  3182. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
  3183. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
  3184. {
  3185. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3186. /* .name = "Capture Source", */
  3187. .name = "Input Source",
  3188. .count = 3,
  3189. .info = alc882_mux_enum_info,
  3190. .get = alc882_mux_enum_get,
  3191. .put = alc882_mux_enum_put,
  3192. },
  3193. { } /* end */
  3194. };
  3195. static struct snd_kcontrol_new alc882_chmode_mixer[] = {
  3196. {
  3197. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3198. .name = "Channel Mode",
  3199. .info = alc_ch_mode_info,
  3200. .get = alc_ch_mode_get,
  3201. .put = alc_ch_mode_put,
  3202. },
  3203. { } /* end */
  3204. };
  3205. static struct hda_verb alc882_init_verbs[] = {
  3206. /* Front mixer: unmute input/output amp left and right (volume = 0) */
  3207. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3208. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3209. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3210. /* Rear mixer */
  3211. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3212. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3213. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3214. /* CLFE mixer */
  3215. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3216. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3217. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3218. /* Side mixer */
  3219. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3220. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3221. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  3222. /* Front Pin: output 0 (0x0c) */
  3223. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3224. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3225. {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
  3226. /* Rear Pin: output 1 (0x0d) */
  3227. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3228. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3229. {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
  3230. /* CLFE Pin: output 2 (0x0e) */
  3231. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3232. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3233. {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
  3234. /* Side Pin: output 3 (0x0f) */
  3235. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  3236. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3237. {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
  3238. /* Mic (rear) pin: input vref at 80% */
  3239. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3240. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3241. /* Front Mic pin: input vref at 80% */
  3242. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  3243. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3244. /* Line In pin: input */
  3245. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3246. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  3247. /* Line-2 In: Headphone output (output 0 - 0x0c) */
  3248. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  3249. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  3250. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  3251. /* CD pin widget for input */
  3252. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  3253. /* FIXME: use matrix-type input source selection */
  3254. /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
  3255. /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
  3256. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3257. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3258. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3259. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3260. /* Input mixer2 */
  3261. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3262. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3263. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3264. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3265. /* Input mixer3 */
  3266. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3267. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  3268. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  3269. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  3270. /* ADC1: mute amp left and right */
  3271. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3272. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  3273. /* ADC2: mute amp left and right */
  3274. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3275. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  3276. /* ADC3: mute amp left and right */
  3277. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  3278. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  3279. { }
  3280. };
  3281. /*
  3282. * generic initialization of ADC, input mixers and output mixers
  3283. */
  3284. static struct hda_verb alc882_auto_init_verbs[] = {
  3285. /*
  3286. * Unmute ADC0-2 and set the default input to mic-in
  3287. */
  3288. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  3289. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3290. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  3291. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3292. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  3293. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3294. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3295. * mixer widget
  3296. * Note: PASD motherboards uses the Line In 2 as the input for front panel
  3297. * mic (mic 2)
  3298. */
  3299. /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
  3300. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3301. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3302. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3303. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3304. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  3305. /*
  3306. * Set up output mixers (0x0c - 0x0f)
  3307. */
  3308. /* set vol=0 to output mixers */
  3309. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3310. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3311. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3312. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3313. /* set up input amps for analog loopback */
  3314. /* Amp Indices: DAC = 0, mixer = 1 */
  3315. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3316. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3317. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3318. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3319. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3320. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3321. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3322. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3323. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3324. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3325. /* FIXME: use matrix-type input source selection */
  3326. /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
  3327. /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
  3328. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3329. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3330. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3331. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3332. /* Input mixer2 */
  3333. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3334. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3335. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3336. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3337. /* Input mixer3 */
  3338. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3339. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3340. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3341. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3342. { }
  3343. };
  3344. /* capture mixer elements */
  3345. static struct snd_kcontrol_new alc882_capture_alt_mixer[] = {
  3346. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  3347. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  3348. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
  3349. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
  3350. {
  3351. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3352. /* The multiple "Capture Source" controls confuse alsamixer
  3353. * So call somewhat different..
  3354. * FIXME: the controls appear in the "playback" view!
  3355. */
  3356. /* .name = "Capture Source", */
  3357. .name = "Input Source",
  3358. .count = 2,
  3359. .info = alc882_mux_enum_info,
  3360. .get = alc882_mux_enum_get,
  3361. .put = alc882_mux_enum_put,
  3362. },
  3363. { } /* end */
  3364. };
  3365. static struct snd_kcontrol_new alc882_capture_mixer[] = {
  3366. HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
  3367. HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
  3368. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
  3369. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
  3370. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
  3371. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
  3372. {
  3373. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3374. /* The multiple "Capture Source" controls confuse alsamixer
  3375. * So call somewhat different..
  3376. * FIXME: the controls appear in the "playback" view!
  3377. */
  3378. /* .name = "Capture Source", */
  3379. .name = "Input Source",
  3380. .count = 3,
  3381. .info = alc882_mux_enum_info,
  3382. .get = alc882_mux_enum_get,
  3383. .put = alc882_mux_enum_put,
  3384. },
  3385. { } /* end */
  3386. };
  3387. /* pcm configuration: identiacal with ALC880 */
  3388. #define alc882_pcm_analog_playback alc880_pcm_analog_playback
  3389. #define alc882_pcm_analog_capture alc880_pcm_analog_capture
  3390. #define alc882_pcm_digital_playback alc880_pcm_digital_playback
  3391. #define alc882_pcm_digital_capture alc880_pcm_digital_capture
  3392. /*
  3393. * configuration and preset
  3394. */
  3395. static struct hda_board_config alc882_cfg_tbl[] = {
  3396. { .modelname = "3stack-dig", .config = ALC882_3ST_DIG },
  3397. { .modelname = "6stack-dig", .config = ALC882_6ST_DIG },
  3398. { .pci_subvendor = 0x1462, .pci_subdevice = 0x6668, .config = ALC882_6ST_DIG }, /* MSI */
  3399. { .pci_subvendor = 0x105b, .pci_subdevice = 0x6668, .config = ALC882_6ST_DIG }, /* Foxconn */
  3400. { .pci_subvendor = 0x1019, .pci_subdevice = 0x6668, .config = ALC882_6ST_DIG }, /* ECS */
  3401. { .modelname = "auto", .config = ALC882_AUTO },
  3402. {}
  3403. };
  3404. static struct alc_config_preset alc882_presets[] = {
  3405. [ALC882_3ST_DIG] = {
  3406. .mixers = { alc882_base_mixer },
  3407. .init_verbs = { alc882_init_verbs },
  3408. .num_dacs = ARRAY_SIZE(alc882_dac_nids),
  3409. .dac_nids = alc882_dac_nids,
  3410. .dig_out_nid = ALC882_DIGOUT_NID,
  3411. .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
  3412. .adc_nids = alc882_adc_nids,
  3413. .dig_in_nid = ALC882_DIGIN_NID,
  3414. .num_channel_mode = ARRAY_SIZE(alc882_ch_modes),
  3415. .channel_mode = alc882_ch_modes,
  3416. .input_mux = &alc882_capture_source,
  3417. },
  3418. [ALC882_6ST_DIG] = {
  3419. .mixers = { alc882_base_mixer, alc882_chmode_mixer },
  3420. .init_verbs = { alc882_init_verbs },
  3421. .num_dacs = ARRAY_SIZE(alc882_dac_nids),
  3422. .dac_nids = alc882_dac_nids,
  3423. .dig_out_nid = ALC882_DIGOUT_NID,
  3424. .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
  3425. .adc_nids = alc882_adc_nids,
  3426. .dig_in_nid = ALC882_DIGIN_NID,
  3427. .num_channel_mode = ARRAY_SIZE(alc882_sixstack_modes),
  3428. .channel_mode = alc882_sixstack_modes,
  3429. .input_mux = &alc882_capture_source,
  3430. },
  3431. };
  3432. /*
  3433. * BIOS auto configuration
  3434. */
  3435. static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
  3436. hda_nid_t nid, int pin_type,
  3437. int dac_idx)
  3438. {
  3439. /* set as output */
  3440. struct alc_spec *spec = codec->spec;
  3441. int idx;
  3442. if (spec->multiout.dac_nids[dac_idx] == 0x25)
  3443. idx = 4;
  3444. else
  3445. idx = spec->multiout.dac_nids[dac_idx] - 2;
  3446. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  3447. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  3448. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
  3449. }
  3450. static void alc882_auto_init_multi_out(struct hda_codec *codec)
  3451. {
  3452. struct alc_spec *spec = codec->spec;
  3453. int i;
  3454. for (i = 0; i <= HDA_SIDE; i++) {
  3455. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  3456. if (nid)
  3457. alc882_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  3458. }
  3459. }
  3460. static void alc882_auto_init_hp_out(struct hda_codec *codec)
  3461. {
  3462. struct alc_spec *spec = codec->spec;
  3463. hda_nid_t pin;
  3464. pin = spec->autocfg.hp_pin;
  3465. if (pin) /* connect to front */
  3466. alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); /* use dac 0 */
  3467. }
  3468. #define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
  3469. #define ALC882_PIN_CD_NID ALC880_PIN_CD_NID
  3470. static void alc882_auto_init_analog_input(struct hda_codec *codec)
  3471. {
  3472. struct alc_spec *spec = codec->spec;
  3473. int i;
  3474. for (i = 0; i < AUTO_PIN_LAST; i++) {
  3475. hda_nid_t nid = spec->autocfg.input_pins[i];
  3476. if (alc882_is_input_pin(nid)) {
  3477. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  3478. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  3479. if (nid != ALC882_PIN_CD_NID)
  3480. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3481. AMP_OUT_MUTE);
  3482. }
  3483. }
  3484. }
  3485. /* almost identical with ALC880 parser... */
  3486. static int alc882_parse_auto_config(struct hda_codec *codec)
  3487. {
  3488. struct alc_spec *spec = codec->spec;
  3489. int err = alc880_parse_auto_config(codec);
  3490. if (err < 0)
  3491. return err;
  3492. else if (err > 0)
  3493. /* hack - override the init verbs */
  3494. spec->init_verbs[0] = alc882_auto_init_verbs;
  3495. return err;
  3496. }
  3497. /* init callback for auto-configuration model -- overriding the default init */
  3498. static int alc882_auto_init(struct hda_codec *codec)
  3499. {
  3500. alc_init(codec);
  3501. alc882_auto_init_multi_out(codec);
  3502. alc882_auto_init_hp_out(codec);
  3503. alc882_auto_init_analog_input(codec);
  3504. return 0;
  3505. }
  3506. /*
  3507. * ALC882 Headphone poll in 3.5.1a or 3.5.2
  3508. */
  3509. static int patch_alc882(struct hda_codec *codec)
  3510. {
  3511. struct alc_spec *spec;
  3512. int err, board_config;
  3513. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3514. if (spec == NULL)
  3515. return -ENOMEM;
  3516. codec->spec = spec;
  3517. board_config = snd_hda_check_board_config(codec, alc882_cfg_tbl);
  3518. if (board_config < 0 || board_config >= ALC882_MODEL_LAST) {
  3519. printk(KERN_INFO "hda_codec: Unknown model for ALC882, trying auto-probe from BIOS...\n");
  3520. board_config = ALC882_AUTO;
  3521. }
  3522. if (board_config == ALC882_AUTO) {
  3523. /* automatic parse from the BIOS config */
  3524. err = alc882_parse_auto_config(codec);
  3525. if (err < 0) {
  3526. alc_free(codec);
  3527. return err;
  3528. } else if (! err) {
  3529. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using base mode...\n");
  3530. board_config = ALC882_3ST_DIG;
  3531. }
  3532. }
  3533. if (board_config != ALC882_AUTO)
  3534. setup_preset(spec, &alc882_presets[board_config]);
  3535. spec->stream_name_analog = "ALC882 Analog";
  3536. spec->stream_analog_playback = &alc882_pcm_analog_playback;
  3537. spec->stream_analog_capture = &alc882_pcm_analog_capture;
  3538. spec->stream_name_digital = "ALC882 Digital";
  3539. spec->stream_digital_playback = &alc882_pcm_digital_playback;
  3540. spec->stream_digital_capture = &alc882_pcm_digital_capture;
  3541. if (! spec->adc_nids && spec->input_mux) {
  3542. /* check whether NID 0x07 is valid */
  3543. unsigned int wcap = get_wcaps(codec, 0x07);
  3544. wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
  3545. if (wcap != AC_WID_AUD_IN) {
  3546. spec->adc_nids = alc882_adc_nids_alt;
  3547. spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
  3548. spec->mixers[spec->num_mixers] = alc882_capture_alt_mixer;
  3549. spec->num_mixers++;
  3550. } else {
  3551. spec->adc_nids = alc882_adc_nids;
  3552. spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
  3553. spec->mixers[spec->num_mixers] = alc882_capture_mixer;
  3554. spec->num_mixers++;
  3555. }
  3556. }
  3557. codec->patch_ops = alc_patch_ops;
  3558. if (board_config == ALC882_AUTO)
  3559. codec->patch_ops.init = alc882_auto_init;
  3560. return 0;
  3561. }
  3562. /*
  3563. * ALC262 support
  3564. */
  3565. #define ALC262_DIGOUT_NID ALC880_DIGOUT_NID
  3566. #define ALC262_DIGIN_NID ALC880_DIGIN_NID
  3567. #define alc262_dac_nids alc260_dac_nids
  3568. #define alc262_adc_nids alc882_adc_nids
  3569. #define alc262_adc_nids_alt alc882_adc_nids_alt
  3570. #define alc262_modes alc260_modes
  3571. #define alc262_capture_source alc882_capture_source
  3572. static struct snd_kcontrol_new alc262_base_mixer[] = {
  3573. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  3574. HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  3575. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  3576. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  3577. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  3578. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  3579. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  3580. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  3581. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
  3582. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
  3583. /* HDA_CODEC_VOLUME("PC Beep Playback Volume", 0x0b, 0x05, HDA_INPUT),
  3584. HDA_CODEC_MUTE("PC Beelp Playback Switch", 0x0b, 0x05, HDA_INPUT), */
  3585. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0D, 0x0, HDA_OUTPUT),
  3586. HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  3587. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  3588. HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
  3589. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  3590. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  3591. {
  3592. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3593. .name = "Capture Source",
  3594. .count = 1,
  3595. .info = alc882_mux_enum_info,
  3596. .get = alc882_mux_enum_get,
  3597. .put = alc882_mux_enum_put,
  3598. },
  3599. { } /* end */
  3600. };
  3601. #define alc262_capture_mixer alc882_capture_mixer
  3602. #define alc262_capture_alt_mixer alc882_capture_alt_mixer
  3603. /*
  3604. * generic initialization of ADC, input mixers and output mixers
  3605. */
  3606. static struct hda_verb alc262_init_verbs[] = {
  3607. /*
  3608. * Unmute ADC0-2 and set the default input to mic-in
  3609. */
  3610. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  3611. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3612. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  3613. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3614. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  3615. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3616. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3617. * mixer widget
  3618. * Note: PASD motherboards uses the Line In 2 as the input for front panel
  3619. * mic (mic 2)
  3620. */
  3621. /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
  3622. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3623. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3624. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3625. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3626. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  3627. /*
  3628. * Set up output mixers (0x0c - 0x0e)
  3629. */
  3630. /* set vol=0 to output mixers */
  3631. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3632. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3633. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3634. /* set up input amps for analog loopback */
  3635. /* Amp Indices: DAC = 0, mixer = 1 */
  3636. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3637. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3638. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3639. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3640. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3641. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3642. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3643. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
  3644. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  3645. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
  3646. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  3647. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  3648. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  3649. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  3650. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  3651. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  3652. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
  3653. {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
  3654. {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
  3655. /* FIXME: use matrix-type input source selection */
  3656. /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
  3657. /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
  3658. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3659. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3660. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3661. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3662. /* Input mixer2 */
  3663. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3664. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3665. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3666. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3667. /* Input mixer3 */
  3668. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3669. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3670. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3671. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3672. { }
  3673. };
  3674. /* add playback controls from the parsed DAC table */
  3675. static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  3676. {
  3677. hda_nid_t nid;
  3678. int err;
  3679. spec->multiout.num_dacs = 1; /* only use one dac */
  3680. spec->multiout.dac_nids = spec->private_dac_nids;
  3681. spec->multiout.dac_nids[0] = 2;
  3682. nid = cfg->line_out_pins[0];
  3683. if (nid) {
  3684. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Front Playback Volume",
  3685. HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT))) < 0)
  3686. return err;
  3687. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Front Playback Switch",
  3688. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  3689. return err;
  3690. }
  3691. nid = cfg->speaker_pin;
  3692. if (nid) {
  3693. if (nid == 0x16) {
  3694. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Speaker Playback Volume",
  3695. HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
  3696. return err;
  3697. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
  3698. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  3699. return err;
  3700. } else {
  3701. if (! cfg->line_out_pins[0])
  3702. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Speaker Playback Volume",
  3703. HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT))) < 0)
  3704. return err;
  3705. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Speaker Playback Switch",
  3706. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  3707. return err;
  3708. }
  3709. }
  3710. nid = cfg->hp_pin;
  3711. if (nid) {
  3712. /* spec->multiout.hp_nid = 2; */
  3713. if (nid == 0x16) {
  3714. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
  3715. HDA_COMPOSE_AMP_VAL(0x0e, 2, 0, HDA_OUTPUT))) < 0)
  3716. return err;
  3717. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
  3718. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  3719. return err;
  3720. } else {
  3721. if (! cfg->line_out_pins[0])
  3722. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
  3723. HDA_COMPOSE_AMP_VAL(0x0c, 3, 0, HDA_OUTPUT))) < 0)
  3724. return err;
  3725. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
  3726. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  3727. return err;
  3728. }
  3729. }
  3730. return 0;
  3731. }
  3732. /* identical with ALC880 */
  3733. #define alc262_auto_create_analog_input_ctls alc880_auto_create_analog_input_ctls
  3734. /*
  3735. * generic initialization of ADC, input mixers and output mixers
  3736. */
  3737. static struct hda_verb alc262_volume_init_verbs[] = {
  3738. /*
  3739. * Unmute ADC0-2 and set the default input to mic-in
  3740. */
  3741. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  3742. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3743. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  3744. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3745. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  3746. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3747. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  3748. * mixer widget
  3749. * Note: PASD motherboards uses the Line In 2 as the input for front panel
  3750. * mic (mic 2)
  3751. */
  3752. /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
  3753. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3754. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3755. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  3756. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  3757. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  3758. /*
  3759. * Set up output mixers (0x0c - 0x0f)
  3760. */
  3761. /* set vol=0 to output mixers */
  3762. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3763. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3764. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  3765. /* set up input amps for analog loopback */
  3766. /* Amp Indices: DAC = 0, mixer = 1 */
  3767. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3768. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3769. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3770. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3771. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  3772. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  3773. /* FIXME: use matrix-type input source selection */
  3774. /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
  3775. /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
  3776. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3777. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3778. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3779. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3780. /* Input mixer2 */
  3781. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3782. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3783. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3784. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3785. /* Input mixer3 */
  3786. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
  3787. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
  3788. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
  3789. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
  3790. { }
  3791. };
  3792. /* pcm configuration: identiacal with ALC880 */
  3793. #define alc262_pcm_analog_playback alc880_pcm_analog_playback
  3794. #define alc262_pcm_analog_capture alc880_pcm_analog_capture
  3795. #define alc262_pcm_digital_playback alc880_pcm_digital_playback
  3796. #define alc262_pcm_digital_capture alc880_pcm_digital_capture
  3797. /*
  3798. * BIOS auto configuration
  3799. */
  3800. static int alc262_parse_auto_config(struct hda_codec *codec)
  3801. {
  3802. struct alc_spec *spec = codec->spec;
  3803. int err;
  3804. static hda_nid_t alc262_ignore[] = { 0x1d, 0 };
  3805. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
  3806. alc262_ignore)) < 0)
  3807. return err;
  3808. if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
  3809. ! spec->autocfg.hp_pin)
  3810. return 0; /* can't find valid BIOS pin config */
  3811. if ((err = alc262_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  3812. (err = alc262_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  3813. return err;
  3814. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  3815. if (spec->autocfg.dig_out_pin)
  3816. spec->multiout.dig_out_nid = ALC262_DIGOUT_NID;
  3817. if (spec->autocfg.dig_in_pin)
  3818. spec->dig_in_nid = ALC262_DIGIN_NID;
  3819. if (spec->kctl_alloc)
  3820. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  3821. spec->init_verbs[spec->num_init_verbs++] = alc262_volume_init_verbs;
  3822. spec->input_mux = &spec->private_imux;
  3823. return 1;
  3824. }
  3825. #define alc262_auto_init_multi_out alc882_auto_init_multi_out
  3826. #define alc262_auto_init_hp_out alc882_auto_init_hp_out
  3827. #define alc262_auto_init_analog_input alc882_auto_init_analog_input
  3828. /* init callback for auto-configuration model -- overriding the default init */
  3829. static int alc262_auto_init(struct hda_codec *codec)
  3830. {
  3831. alc_init(codec);
  3832. alc262_auto_init_multi_out(codec);
  3833. alc262_auto_init_hp_out(codec);
  3834. alc262_auto_init_analog_input(codec);
  3835. return 0;
  3836. }
  3837. /*
  3838. * configuration and preset
  3839. */
  3840. static struct hda_board_config alc262_cfg_tbl[] = {
  3841. { .modelname = "basic", .config = ALC262_BASIC },
  3842. { .modelname = "auto", .config = ALC262_AUTO },
  3843. {}
  3844. };
  3845. static struct alc_config_preset alc262_presets[] = {
  3846. [ALC262_BASIC] = {
  3847. .mixers = { alc262_base_mixer },
  3848. .init_verbs = { alc262_init_verbs },
  3849. .num_dacs = ARRAY_SIZE(alc262_dac_nids),
  3850. .dac_nids = alc262_dac_nids,
  3851. .hp_nid = 0x03,
  3852. .num_channel_mode = ARRAY_SIZE(alc262_modes),
  3853. .channel_mode = alc262_modes,
  3854. .input_mux = &alc262_capture_source,
  3855. },
  3856. };
  3857. static int patch_alc262(struct hda_codec *codec)
  3858. {
  3859. struct alc_spec *spec;
  3860. int board_config;
  3861. int err;
  3862. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  3863. if (spec == NULL)
  3864. return -ENOMEM;
  3865. codec->spec = spec;
  3866. #if 0
  3867. /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is under-run */
  3868. {
  3869. int tmp;
  3870. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  3871. tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
  3872. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
  3873. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
  3874. }
  3875. #endif
  3876. board_config = snd_hda_check_board_config(codec, alc262_cfg_tbl);
  3877. if (board_config < 0 || board_config >= ALC262_MODEL_LAST) {
  3878. printk(KERN_INFO "hda_codec: Unknown model for ALC262, trying auto-probe from BIOS...\n");
  3879. board_config = ALC262_AUTO;
  3880. }
  3881. if (board_config == ALC262_AUTO) {
  3882. /* automatic parse from the BIOS config */
  3883. err = alc262_parse_auto_config(codec);
  3884. if (err < 0) {
  3885. alc_free(codec);
  3886. return err;
  3887. } else if (! err) {
  3888. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using base mode...\n");
  3889. board_config = ALC262_BASIC;
  3890. }
  3891. }
  3892. if (board_config != ALC262_AUTO)
  3893. setup_preset(spec, &alc262_presets[board_config]);
  3894. spec->stream_name_analog = "ALC262 Analog";
  3895. spec->stream_analog_playback = &alc262_pcm_analog_playback;
  3896. spec->stream_analog_capture = &alc262_pcm_analog_capture;
  3897. spec->stream_name_digital = "ALC262 Digital";
  3898. spec->stream_digital_playback = &alc262_pcm_digital_playback;
  3899. spec->stream_digital_capture = &alc262_pcm_digital_capture;
  3900. if (! spec->adc_nids && spec->input_mux) {
  3901. /* check whether NID 0x07 is valid */
  3902. unsigned int wcap = get_wcaps(codec, 0x07);
  3903. wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
  3904. if (wcap != AC_WID_AUD_IN) {
  3905. spec->adc_nids = alc262_adc_nids_alt;
  3906. spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
  3907. spec->mixers[spec->num_mixers] = alc262_capture_alt_mixer;
  3908. spec->num_mixers++;
  3909. } else {
  3910. spec->adc_nids = alc262_adc_nids;
  3911. spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
  3912. spec->mixers[spec->num_mixers] = alc262_capture_mixer;
  3913. spec->num_mixers++;
  3914. }
  3915. }
  3916. codec->patch_ops = alc_patch_ops;
  3917. if (board_config == ALC262_AUTO)
  3918. codec->patch_ops.init = alc262_auto_init;
  3919. return 0;
  3920. }
  3921. /*
  3922. * ALC861 channel source setting (2/6 channel selection for 3-stack)
  3923. */
  3924. /*
  3925. * set the path ways for 2 channel output
  3926. * need to set the codec line out and mic 1 pin widgets to inputs
  3927. */
  3928. static struct hda_verb alc861_threestack_ch2_init[] = {
  3929. /* set pin widget 1Ah (line in) for input */
  3930. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  3931. /* set pin widget 18h (mic1/2) for input, for mic also enable the vref */
  3932. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  3933. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
  3934. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, //mic
  3935. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, //line in
  3936. { } /* end */
  3937. };
  3938. /*
  3939. * 6ch mode
  3940. * need to set the codec line out and mic 1 pin widgets to outputs
  3941. */
  3942. static struct hda_verb alc861_threestack_ch6_init[] = {
  3943. /* set pin widget 1Ah (line in) for output (Back Surround)*/
  3944. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  3945. /* set pin widget 18h (mic1) for output (CLFE)*/
  3946. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  3947. { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
  3948. { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
  3949. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
  3950. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, //mic
  3951. { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, //line in
  3952. { } /* end */
  3953. };
  3954. static struct hda_channel_mode alc861_threestack_modes[2] = {
  3955. { 2, alc861_threestack_ch2_init },
  3956. { 6, alc861_threestack_ch6_init },
  3957. };
  3958. /* patch-ALC861 */
  3959. static struct snd_kcontrol_new alc861_base_mixer[] = {
  3960. /* output mixer control */
  3961. HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  3962. HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  3963. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
  3964. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
  3965. HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
  3966. /*Input mixer control */
  3967. /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  3968. HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
  3969. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
  3970. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
  3971. HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
  3972. HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
  3973. HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
  3974. HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
  3975. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
  3976. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
  3977. /* Capture mixer control */
  3978. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  3979. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  3980. {
  3981. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3982. .name = "Capture Source",
  3983. .count = 1,
  3984. .info = alc_mux_enum_info,
  3985. .get = alc_mux_enum_get,
  3986. .put = alc_mux_enum_put,
  3987. },
  3988. { } /* end */
  3989. };
  3990. static struct snd_kcontrol_new alc861_3ST_mixer[] = {
  3991. /* output mixer control */
  3992. HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
  3993. HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
  3994. HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
  3995. HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
  3996. /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
  3997. /* Input mixer control */
  3998. /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  3999. HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
  4000. HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
  4001. HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
  4002. HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
  4003. HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
  4004. HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
  4005. HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
  4006. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
  4007. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
  4008. /* Capture mixer control */
  4009. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  4010. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  4011. {
  4012. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4013. .name = "Capture Source",
  4014. .count = 1,
  4015. .info = alc_mux_enum_info,
  4016. .get = alc_mux_enum_get,
  4017. .put = alc_mux_enum_put,
  4018. },
  4019. {
  4020. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4021. .name = "Channel Mode",
  4022. .info = alc_ch_mode_info,
  4023. .get = alc_ch_mode_get,
  4024. .put = alc_ch_mode_put,
  4025. .private_value = ARRAY_SIZE(alc861_threestack_modes),
  4026. },
  4027. { } /* end */
  4028. };
  4029. /*
  4030. * generic initialization of ADC, input mixers and output mixers
  4031. */
  4032. static struct hda_verb alc861_base_init_verbs[] = {
  4033. /*
  4034. * Unmute ADC0 and set the default input to mic-in
  4035. */
  4036. /* port-A for surround (rear panel) */
  4037. { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  4038. { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
  4039. /* port-B for mic-in (rear panel) with vref */
  4040. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  4041. /* port-C for line-in (rear panel) */
  4042. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  4043. /* port-D for Front */
  4044. { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  4045. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
  4046. /* port-E for HP out (front panel) */
  4047. { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  4048. /* route front PCM to HP */
  4049. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01 },
  4050. /* port-F for mic-in (front panel) with vref */
  4051. { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  4052. /* port-G for CLFE (rear panel) */
  4053. { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  4054. { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
  4055. /* port-H for side (rear panel) */
  4056. { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  4057. { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
  4058. /* CD-in */
  4059. { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  4060. /* route front mic to ADC1*/
  4061. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  4062. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4063. /* Unmute DAC0~3 & spdif out*/
  4064. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4065. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4066. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4067. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4068. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4069. /* Unmute Mixer 14 (mic) 1c (Line in)*/
  4070. {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4071. {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4072. {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4073. {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4074. /* Unmute Stereo Mixer 15 */
  4075. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4076. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4077. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4078. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c }, //Output 0~12 step
  4079. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4080. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4081. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4082. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4083. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4084. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4085. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4086. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4087. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
  4088. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4089. { }
  4090. };
  4091. static struct hda_verb alc861_threestack_init_verbs[] = {
  4092. /*
  4093. * Unmute ADC0 and set the default input to mic-in
  4094. */
  4095. /* port-A for surround (rear panel) */
  4096. { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
  4097. /* port-B for mic-in (rear panel) with vref */
  4098. { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  4099. /* port-C for line-in (rear panel) */
  4100. { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  4101. /* port-D for Front */
  4102. { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
  4103. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
  4104. /* port-E for HP out (front panel) */
  4105. { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
  4106. /* route front PCM to HP */
  4107. { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x01 },
  4108. /* port-F for mic-in (front panel) with vref */
  4109. { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
  4110. /* port-G for CLFE (rear panel) */
  4111. { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
  4112. /* port-H for side (rear panel) */
  4113. { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
  4114. /* CD-in */
  4115. { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
  4116. /* route front mic to ADC1*/
  4117. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  4118. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4119. /* Unmute DAC0~3 & spdif out*/
  4120. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4121. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4122. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4123. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4124. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4125. /* Unmute Mixer 14 (mic) 1c (Line in)*/
  4126. {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4127. {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4128. {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4129. {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4130. /* Unmute Stereo Mixer 15 */
  4131. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4132. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4133. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4134. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c }, //Output 0~12 step
  4135. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4136. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4137. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4138. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4139. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4140. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4141. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4142. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4143. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)}, // hp used DAC 3 (Front)
  4144. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4145. { }
  4146. };
  4147. /*
  4148. * generic initialization of ADC, input mixers and output mixers
  4149. */
  4150. static struct hda_verb alc861_auto_init_verbs[] = {
  4151. /*
  4152. * Unmute ADC0 and set the default input to mic-in
  4153. */
  4154. // {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  4155. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4156. /* Unmute DAC0~3 & spdif out*/
  4157. {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4158. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4159. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4160. {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  4161. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  4162. /* Unmute Mixer 14 (mic) 1c (Line in)*/
  4163. {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4164. {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4165. {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4166. {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4167. /* Unmute Stereo Mixer 15 */
  4168. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4169. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4170. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4171. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c},
  4172. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4173. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4174. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4175. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4176. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4177. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4178. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  4179. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  4180. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4181. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4182. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4183. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  4184. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  4185. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  4186. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  4187. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  4188. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00}, // set Mic 1
  4189. { }
  4190. };
  4191. /* pcm configuration: identiacal with ALC880 */
  4192. #define alc861_pcm_analog_playback alc880_pcm_analog_playback
  4193. #define alc861_pcm_analog_capture alc880_pcm_analog_capture
  4194. #define alc861_pcm_digital_playback alc880_pcm_digital_playback
  4195. #define alc861_pcm_digital_capture alc880_pcm_digital_capture
  4196. #define ALC861_DIGOUT_NID 0x07
  4197. static struct hda_channel_mode alc861_8ch_modes[1] = {
  4198. { 8, NULL }
  4199. };
  4200. static hda_nid_t alc861_dac_nids[4] = {
  4201. /* front, surround, clfe, side */
  4202. 0x03, 0x06, 0x05, 0x04
  4203. };
  4204. static hda_nid_t alc861_adc_nids[1] = {
  4205. /* ADC0-2 */
  4206. 0x08,
  4207. };
  4208. static struct hda_input_mux alc861_capture_source = {
  4209. .num_items = 5,
  4210. .items = {
  4211. { "Mic", 0x0 },
  4212. { "Front Mic", 0x3 },
  4213. { "Line", 0x1 },
  4214. { "CD", 0x4 },
  4215. { "Mixer", 0x5 },
  4216. },
  4217. };
  4218. /* fill in the dac_nids table from the parsed pin configuration */
  4219. static int alc861_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  4220. {
  4221. int i;
  4222. hda_nid_t nid;
  4223. spec->multiout.dac_nids = spec->private_dac_nids;
  4224. for (i = 0; i < cfg->line_outs; i++) {
  4225. nid = cfg->line_out_pins[i];
  4226. if (nid) {
  4227. if (i >= ARRAY_SIZE(alc861_dac_nids))
  4228. continue;
  4229. spec->multiout.dac_nids[i] = alc861_dac_nids[i];
  4230. }
  4231. }
  4232. spec->multiout.num_dacs = cfg->line_outs;
  4233. return 0;
  4234. }
  4235. /* add playback controls from the parsed DAC table */
  4236. static int alc861_auto_create_multi_out_ctls(struct alc_spec *spec,
  4237. const struct auto_pin_cfg *cfg)
  4238. {
  4239. char name[32];
  4240. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  4241. hda_nid_t nid;
  4242. int i, idx, err;
  4243. for (i = 0; i < cfg->line_outs; i++) {
  4244. nid = spec->multiout.dac_nids[i];
  4245. if (! nid)
  4246. continue;
  4247. if (nid == 0x05) {
  4248. /* Center/LFE */
  4249. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
  4250. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  4251. return err;
  4252. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
  4253. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  4254. return err;
  4255. } else {
  4256. for (idx = 0; idx < ARRAY_SIZE(alc861_dac_nids) - 1; idx++)
  4257. if (nid == alc861_dac_nids[idx])
  4258. break;
  4259. sprintf(name, "%s Playback Switch", chname[idx]);
  4260. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
  4261. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  4262. return err;
  4263. }
  4264. }
  4265. return 0;
  4266. }
  4267. static int alc861_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
  4268. {
  4269. int err;
  4270. hda_nid_t nid;
  4271. if (! pin)
  4272. return 0;
  4273. if ((pin >= 0x0b && pin <= 0x10) || pin == 0x1f || pin == 0x20) {
  4274. nid = 0x03;
  4275. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
  4276. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  4277. return err;
  4278. spec->multiout.hp_nid = nid;
  4279. }
  4280. return 0;
  4281. }
  4282. /* create playback/capture controls for input pins */
  4283. static int alc861_auto_create_analog_input_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  4284. {
  4285. struct hda_input_mux *imux = &spec->private_imux;
  4286. int i, err, idx, idx1;
  4287. for (i = 0; i < AUTO_PIN_LAST; i++) {
  4288. switch(cfg->input_pins[i]) {
  4289. case 0x0c:
  4290. idx1 = 1;
  4291. idx = 2; // Line In
  4292. break;
  4293. case 0x0f:
  4294. idx1 = 2;
  4295. idx = 2; // Line In
  4296. break;
  4297. case 0x0d:
  4298. idx1 = 0;
  4299. idx = 1; // Mic In
  4300. break;
  4301. case 0x10:
  4302. idx1 = 3;
  4303. idx = 1; // Mic In
  4304. break;
  4305. case 0x11:
  4306. idx1 = 4;
  4307. idx = 0; // CD
  4308. break;
  4309. default:
  4310. continue;
  4311. }
  4312. err = new_analog_input(spec, cfg->input_pins[i],
  4313. auto_pin_cfg_labels[i], idx, 0x15);
  4314. if (err < 0)
  4315. return err;
  4316. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  4317. imux->items[imux->num_items].index = idx1;
  4318. imux->num_items++;
  4319. }
  4320. return 0;
  4321. }
  4322. static struct snd_kcontrol_new alc861_capture_mixer[] = {
  4323. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  4324. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  4325. {
  4326. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  4327. /* The multiple "Capture Source" controls confuse alsamixer
  4328. * So call somewhat different..
  4329. *FIXME: the controls appear in the "playback" view!
  4330. */
  4331. /* .name = "Capture Source", */
  4332. .name = "Input Source",
  4333. .count = 1,
  4334. .info = alc_mux_enum_info,
  4335. .get = alc_mux_enum_get,
  4336. .put = alc_mux_enum_put,
  4337. },
  4338. { } /* end */
  4339. };
  4340. static void alc861_auto_set_output_and_unmute(struct hda_codec *codec, hda_nid_t nid,
  4341. int pin_type, int dac_idx)
  4342. {
  4343. /* set as output */
  4344. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  4345. snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  4346. }
  4347. static void alc861_auto_init_multi_out(struct hda_codec *codec)
  4348. {
  4349. struct alc_spec *spec = codec->spec;
  4350. int i;
  4351. for (i = 0; i < spec->autocfg.line_outs; i++) {
  4352. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  4353. if (nid)
  4354. alc861_auto_set_output_and_unmute(codec, nid, PIN_OUT, spec->multiout.dac_nids[i]);
  4355. }
  4356. }
  4357. static void alc861_auto_init_hp_out(struct hda_codec *codec)
  4358. {
  4359. struct alc_spec *spec = codec->spec;
  4360. hda_nid_t pin;
  4361. pin = spec->autocfg.hp_pin;
  4362. if (pin) /* connect to front */
  4363. alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, spec->multiout.dac_nids[0]);
  4364. }
  4365. static void alc861_auto_init_analog_input(struct hda_codec *codec)
  4366. {
  4367. struct alc_spec *spec = codec->spec;
  4368. int i;
  4369. for (i = 0; i < AUTO_PIN_LAST; i++) {
  4370. hda_nid_t nid = spec->autocfg.input_pins[i];
  4371. if ((nid>=0x0c) && (nid <=0x11)) {
  4372. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  4373. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  4374. }
  4375. }
  4376. }
  4377. /* parse the BIOS configuration and set up the alc_spec */
  4378. /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  4379. static int alc861_parse_auto_config(struct hda_codec *codec)
  4380. {
  4381. struct alc_spec *spec = codec->spec;
  4382. int err;
  4383. static hda_nid_t alc861_ignore[] = { 0x1d, 0 };
  4384. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg,
  4385. alc861_ignore)) < 0)
  4386. return err;
  4387. if (! spec->autocfg.line_outs && ! spec->autocfg.speaker_pin &&
  4388. ! spec->autocfg.hp_pin)
  4389. return 0; /* can't find valid BIOS pin config */
  4390. if ((err = alc861_auto_fill_dac_nids(spec, &spec->autocfg)) < 0 ||
  4391. (err = alc861_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  4392. (err = alc861_auto_create_hp_ctls(spec, spec->autocfg.hp_pin)) < 0 ||
  4393. (err = alc861_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  4394. return err;
  4395. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  4396. if (spec->autocfg.dig_out_pin)
  4397. spec->multiout.dig_out_nid = ALC861_DIGOUT_NID;
  4398. if (spec->kctl_alloc)
  4399. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  4400. spec->init_verbs[spec->num_init_verbs++] = alc861_auto_init_verbs;
  4401. spec->input_mux = &spec->private_imux;
  4402. spec->adc_nids = alc861_adc_nids;
  4403. spec->num_adc_nids = ARRAY_SIZE(alc861_adc_nids);
  4404. spec->mixers[spec->num_mixers] = alc861_capture_mixer;
  4405. spec->num_mixers++;
  4406. return 1;
  4407. }
  4408. /* init callback for auto-configuration model -- overriding the default init */
  4409. static int alc861_auto_init(struct hda_codec *codec)
  4410. {
  4411. alc_init(codec);
  4412. alc861_auto_init_multi_out(codec);
  4413. alc861_auto_init_hp_out(codec);
  4414. alc861_auto_init_analog_input(codec);
  4415. return 0;
  4416. }
  4417. /*
  4418. * configuration and preset
  4419. */
  4420. static struct hda_board_config alc861_cfg_tbl[] = {
  4421. { .modelname = "3stack", .config = ALC861_3ST },
  4422. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd600, .config = ALC861_3ST },
  4423. { .modelname = "3stack-dig", .config = ALC861_3ST_DIG },
  4424. { .modelname = "6stack-dig", .config = ALC861_6ST_DIG },
  4425. { .modelname = "auto", .config = ALC861_AUTO },
  4426. {}
  4427. };
  4428. static struct alc_config_preset alc861_presets[] = {
  4429. [ALC861_3ST] = {
  4430. .mixers = { alc861_3ST_mixer },
  4431. .init_verbs = { alc861_threestack_init_verbs },
  4432. .num_dacs = ARRAY_SIZE(alc861_dac_nids),
  4433. .dac_nids = alc861_dac_nids,
  4434. .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
  4435. .channel_mode = alc861_threestack_modes,
  4436. .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
  4437. .adc_nids = alc861_adc_nids,
  4438. .input_mux = &alc861_capture_source,
  4439. },
  4440. [ALC861_3ST_DIG] = {
  4441. .mixers = { alc861_base_mixer },
  4442. .init_verbs = { alc861_threestack_init_verbs },
  4443. .num_dacs = ARRAY_SIZE(alc861_dac_nids),
  4444. .dac_nids = alc861_dac_nids,
  4445. .dig_out_nid = ALC861_DIGOUT_NID,
  4446. .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
  4447. .channel_mode = alc861_threestack_modes,
  4448. .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
  4449. .adc_nids = alc861_adc_nids,
  4450. .input_mux = &alc861_capture_source,
  4451. },
  4452. [ALC861_6ST_DIG] = {
  4453. .mixers = { alc861_base_mixer },
  4454. .init_verbs = { alc861_base_init_verbs },
  4455. .num_dacs = ARRAY_SIZE(alc861_dac_nids),
  4456. .dac_nids = alc861_dac_nids,
  4457. .dig_out_nid = ALC861_DIGOUT_NID,
  4458. .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
  4459. .channel_mode = alc861_8ch_modes,
  4460. .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
  4461. .adc_nids = alc861_adc_nids,
  4462. .input_mux = &alc861_capture_source,
  4463. },
  4464. };
  4465. static int patch_alc861(struct hda_codec *codec)
  4466. {
  4467. struct alc_spec *spec;
  4468. int board_config;
  4469. int err;
  4470. spec = kcalloc(1, sizeof(*spec), GFP_KERNEL);
  4471. if (spec == NULL)
  4472. return -ENOMEM;
  4473. codec->spec = spec;
  4474. board_config = snd_hda_check_board_config(codec, alc861_cfg_tbl);
  4475. if (board_config < 0 || board_config >= ALC861_MODEL_LAST) {
  4476. printk(KERN_INFO "hda_codec: Unknown model for ALC861, trying auto-probe from BIOS...\n");
  4477. board_config = ALC861_AUTO;
  4478. }
  4479. if (board_config == ALC861_AUTO) {
  4480. /* automatic parse from the BIOS config */
  4481. err = alc861_parse_auto_config(codec);
  4482. if (err < 0) {
  4483. alc_free(codec);
  4484. return err;
  4485. } else if (! err) {
  4486. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using base mode...\n");
  4487. board_config = ALC861_3ST_DIG;
  4488. }
  4489. }
  4490. if (board_config != ALC861_AUTO)
  4491. setup_preset(spec, &alc861_presets[board_config]);
  4492. spec->stream_name_analog = "ALC861 Analog";
  4493. spec->stream_analog_playback = &alc861_pcm_analog_playback;
  4494. spec->stream_analog_capture = &alc861_pcm_analog_capture;
  4495. spec->stream_name_digital = "ALC861 Digital";
  4496. spec->stream_digital_playback = &alc861_pcm_digital_playback;
  4497. spec->stream_digital_capture = &alc861_pcm_digital_capture;
  4498. codec->patch_ops = alc_patch_ops;
  4499. if (board_config == ALC861_AUTO)
  4500. codec->patch_ops.init = alc861_auto_init;
  4501. return 0;
  4502. }
  4503. /*
  4504. * patch entries
  4505. */
  4506. struct hda_codec_preset snd_hda_preset_realtek[] = {
  4507. { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
  4508. { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
  4509. { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
  4510. { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
  4511. { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
  4512. { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
  4513. { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
  4514. {} /* terminator */
  4515. };