patch_realtek.c 177 KB

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