patch_via.c 106 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT17xx/VT18xx/VT20xx codec
  5. *
  6. * (C) 2006-2009 VIA Technology, Inc.
  7. * (C) 2006-2008 Takashi Iwai <tiwai@suse.de>
  8. *
  9. * This driver is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This driver is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. /* * * * * * * * * * * * * * Release History * * * * * * * * * * * * * * * * */
  24. /* */
  25. /* 2006-03-03 Lydia Wang Create the basic patch to support VT1708 codec */
  26. /* 2006-03-14 Lydia Wang Modify hard code for some pin widget nid */
  27. /* 2006-08-02 Lydia Wang Add support to VT1709 codec */
  28. /* 2006-09-08 Lydia Wang Fix internal loopback recording source select bug */
  29. /* 2007-09-12 Lydia Wang Add EAPD enable during driver initialization */
  30. /* 2007-09-17 Lydia Wang Add VT1708B codec support */
  31. /* 2007-11-14 Lydia Wang Add VT1708A codec HP and CD pin connect config */
  32. /* 2008-02-03 Lydia Wang Fix Rear channels and Back channels inverse issue */
  33. /* 2008-03-06 Lydia Wang Add VT1702 codec and VT1708S codec support */
  34. /* 2008-04-09 Lydia Wang Add mute front speaker when HP plugin */
  35. /* 2008-04-09 Lydia Wang Add Independent HP feature */
  36. /* 2008-05-28 Lydia Wang Add second S/PDIF Out support for VT1702 */
  37. /* 2008-09-15 Logan Li Add VT1708S Mic Boost workaround/backdoor */
  38. /* 2009-02-16 Logan Li Add support for VT1718S */
  39. /* 2009-03-13 Logan Li Add support for VT1716S */
  40. /* 2009-04-14 Lydai Wang Add support for VT1828S and VT2020 */
  41. /* 2009-07-08 Lydia Wang Add support for VT2002P */
  42. /* 2009-07-21 Lydia Wang Add support for VT1812 */
  43. /* 2009-09-19 Lydia Wang Add support for VT1818S */
  44. /* */
  45. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  46. #include <linux/init.h>
  47. #include <linux/delay.h>
  48. #include <linux/slab.h>
  49. #include <sound/core.h>
  50. #include <sound/asoundef.h>
  51. #include "hda_codec.h"
  52. #include "hda_local.h"
  53. /* Pin Widget NID */
  54. #define VT1708_HP_PIN_NID 0x20
  55. #define VT1708_CD_PIN_NID 0x24
  56. enum VIA_HDA_CODEC {
  57. UNKNOWN = -1,
  58. VT1708,
  59. VT1709_10CH,
  60. VT1709_6CH,
  61. VT1708B_8CH,
  62. VT1708B_4CH,
  63. VT1708S,
  64. VT1708BCE,
  65. VT1702,
  66. VT1718S,
  67. VT1716S,
  68. VT2002P,
  69. VT1812,
  70. VT1802,
  71. CODEC_TYPES,
  72. };
  73. #define VT2002P_COMPATIBLE(spec) \
  74. ((spec)->codec_type == VT2002P ||\
  75. (spec)->codec_type == VT1812 ||\
  76. (spec)->codec_type == VT1802)
  77. #define MAX_NID_PATH_DEPTH 5
  78. /* output-path: DAC -> ... -> pin
  79. * idx[] contains the source index number of the next widget;
  80. * e.g. idx[0] is the index of the DAC selected by path[1] widget
  81. * multi[] indicates whether it's a selector widget with multi-connectors
  82. * (i.e. the connection selection is mandatory)
  83. * vol_ctl and mute_ctl contains the NIDs for the assigned mixers
  84. */
  85. struct nid_path {
  86. int depth;
  87. hda_nid_t path[MAX_NID_PATH_DEPTH];
  88. unsigned char idx[MAX_NID_PATH_DEPTH];
  89. unsigned char multi[MAX_NID_PATH_DEPTH];
  90. unsigned int vol_ctl;
  91. unsigned int mute_ctl;
  92. };
  93. /* input-path */
  94. struct via_input {
  95. hda_nid_t pin; /* input-pin or aa-mix */
  96. int adc_idx; /* ADC index to be used */
  97. int mux_idx; /* MUX index (if any) */
  98. const char *label; /* input-source label */
  99. };
  100. #define VIA_MAX_ADCS 3
  101. enum {
  102. STREAM_MULTI_OUT = (1 << 0),
  103. STREAM_INDEP_HP = (1 << 1),
  104. };
  105. struct via_spec {
  106. /* codec parameterization */
  107. const struct snd_kcontrol_new *mixers[6];
  108. unsigned int num_mixers;
  109. const struct hda_verb *init_verbs[5];
  110. unsigned int num_iverbs;
  111. char stream_name_analog[32];
  112. char stream_name_hp[32];
  113. const struct hda_pcm_stream *stream_analog_playback;
  114. const struct hda_pcm_stream *stream_analog_capture;
  115. char stream_name_digital[32];
  116. const struct hda_pcm_stream *stream_digital_playback;
  117. const struct hda_pcm_stream *stream_digital_capture;
  118. /* playback */
  119. struct hda_multi_out multiout;
  120. hda_nid_t slave_dig_outs[2];
  121. hda_nid_t hp_dac_nid;
  122. hda_nid_t speaker_dac_nid;
  123. int hp_indep_shared; /* indep HP-DAC is shared with side ch */
  124. int opened_streams; /* STREAM_* bits */
  125. int active_streams; /* STREAM_* bits */
  126. int aamix_mode; /* loopback is enabled for output-path? */
  127. /* Output-paths:
  128. * There are different output-paths depending on the setup.
  129. * out_path, hp_path and speaker_path are primary paths. If both
  130. * direct DAC and aa-loopback routes are available, these contain
  131. * the former paths. Meanwhile *_mix_path contain the paths with
  132. * loopback mixer. (Since the loopback is only for front channel,
  133. * no out_mix_path for surround channels.)
  134. * The HP output has another path, hp_indep_path, which is used in
  135. * the independent-HP mode.
  136. */
  137. struct nid_path out_path[HDA_SIDE + 1];
  138. struct nid_path out_mix_path;
  139. struct nid_path hp_path;
  140. struct nid_path hp_mix_path;
  141. struct nid_path hp_indep_path;
  142. struct nid_path speaker_path;
  143. struct nid_path speaker_mix_path;
  144. /* capture */
  145. unsigned int num_adc_nids;
  146. hda_nid_t adc_nids[VIA_MAX_ADCS];
  147. hda_nid_t mux_nids[VIA_MAX_ADCS];
  148. hda_nid_t aa_mix_nid;
  149. hda_nid_t dig_in_nid;
  150. /* capture source */
  151. bool dyn_adc_switch;
  152. int num_inputs;
  153. struct via_input inputs[AUTO_CFG_MAX_INS + 1];
  154. unsigned int cur_mux[VIA_MAX_ADCS];
  155. /* dynamic DAC switching */
  156. unsigned int cur_dac_stream_tag;
  157. unsigned int cur_dac_format;
  158. unsigned int cur_hp_stream_tag;
  159. unsigned int cur_hp_format;
  160. /* dynamic ADC switching */
  161. hda_nid_t cur_adc;
  162. unsigned int cur_adc_stream_tag;
  163. unsigned int cur_adc_format;
  164. /* PCM information */
  165. struct hda_pcm pcm_rec[3];
  166. /* dynamic controls, init_verbs and input_mux */
  167. struct auto_pin_cfg autocfg;
  168. struct snd_array kctls;
  169. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  170. /* HP mode source */
  171. unsigned int hp_independent_mode;
  172. unsigned int dmic_enabled;
  173. unsigned int no_pin_power_ctl;
  174. enum VIA_HDA_CODEC codec_type;
  175. /* smart51 setup */
  176. unsigned int smart51_nums;
  177. hda_nid_t smart51_pins[2];
  178. int smart51_idxs[2];
  179. const char *smart51_labels[2];
  180. unsigned int smart51_enabled;
  181. /* work to check hp jack state */
  182. struct hda_codec *codec;
  183. struct delayed_work vt1708_hp_work;
  184. int vt1708_jack_detect;
  185. int vt1708_hp_present;
  186. void (*set_widgets_power_state)(struct hda_codec *codec);
  187. struct hda_loopback_check loopback;
  188. int num_loopbacks;
  189. struct hda_amp_list loopback_list[8];
  190. /* bind capture-volume */
  191. struct hda_bind_ctls *bind_cap_vol;
  192. struct hda_bind_ctls *bind_cap_sw;
  193. struct mutex config_mutex;
  194. };
  195. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec);
  196. static struct via_spec * via_new_spec(struct hda_codec *codec)
  197. {
  198. struct via_spec *spec;
  199. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  200. if (spec == NULL)
  201. return NULL;
  202. mutex_init(&spec->config_mutex);
  203. codec->spec = spec;
  204. spec->codec = codec;
  205. spec->codec_type = get_codec_type(codec);
  206. /* VT1708BCE & VT1708S are almost same */
  207. if (spec->codec_type == VT1708BCE)
  208. spec->codec_type = VT1708S;
  209. return spec;
  210. }
  211. static enum VIA_HDA_CODEC get_codec_type(struct hda_codec *codec)
  212. {
  213. u32 vendor_id = codec->vendor_id;
  214. u16 ven_id = vendor_id >> 16;
  215. u16 dev_id = vendor_id & 0xffff;
  216. enum VIA_HDA_CODEC codec_type;
  217. /* get codec type */
  218. if (ven_id != 0x1106)
  219. codec_type = UNKNOWN;
  220. else if (dev_id >= 0x1708 && dev_id <= 0x170b)
  221. codec_type = VT1708;
  222. else if (dev_id >= 0xe710 && dev_id <= 0xe713)
  223. codec_type = VT1709_10CH;
  224. else if (dev_id >= 0xe714 && dev_id <= 0xe717)
  225. codec_type = VT1709_6CH;
  226. else if (dev_id >= 0xe720 && dev_id <= 0xe723) {
  227. codec_type = VT1708B_8CH;
  228. if (snd_hda_param_read(codec, 0x16, AC_PAR_CONNLIST_LEN) == 0x7)
  229. codec_type = VT1708BCE;
  230. } else if (dev_id >= 0xe724 && dev_id <= 0xe727)
  231. codec_type = VT1708B_4CH;
  232. else if ((dev_id & 0xfff) == 0x397
  233. && (dev_id >> 12) < 8)
  234. codec_type = VT1708S;
  235. else if ((dev_id & 0xfff) == 0x398
  236. && (dev_id >> 12) < 8)
  237. codec_type = VT1702;
  238. else if ((dev_id & 0xfff) == 0x428
  239. && (dev_id >> 12) < 8)
  240. codec_type = VT1718S;
  241. else if (dev_id == 0x0433 || dev_id == 0xa721)
  242. codec_type = VT1716S;
  243. else if (dev_id == 0x0441 || dev_id == 0x4441)
  244. codec_type = VT1718S;
  245. else if (dev_id == 0x0438 || dev_id == 0x4438)
  246. codec_type = VT2002P;
  247. else if (dev_id == 0x0448)
  248. codec_type = VT1812;
  249. else if (dev_id == 0x0440)
  250. codec_type = VT1708S;
  251. else if ((dev_id & 0xfff) == 0x446)
  252. codec_type = VT1802;
  253. else
  254. codec_type = UNKNOWN;
  255. return codec_type;
  256. };
  257. #define VIA_JACK_EVENT 0x20
  258. #define VIA_HP_EVENT 0x01
  259. #define VIA_GPIO_EVENT 0x02
  260. #define VIA_LINE_EVENT 0x03
  261. enum {
  262. VIA_CTL_WIDGET_VOL,
  263. VIA_CTL_WIDGET_MUTE,
  264. VIA_CTL_WIDGET_ANALOG_MUTE,
  265. };
  266. static void analog_low_current_mode(struct hda_codec *codec);
  267. static bool is_aa_path_mute(struct hda_codec *codec);
  268. static void vt1708_start_hp_work(struct via_spec *spec)
  269. {
  270. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  271. return;
  272. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
  273. !spec->vt1708_jack_detect);
  274. if (!delayed_work_pending(&spec->vt1708_hp_work))
  275. schedule_delayed_work(&spec->vt1708_hp_work,
  276. msecs_to_jiffies(100));
  277. }
  278. static void vt1708_stop_hp_work(struct via_spec *spec)
  279. {
  280. if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
  281. return;
  282. if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1
  283. && !is_aa_path_mute(spec->codec))
  284. return;
  285. snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81,
  286. !spec->vt1708_jack_detect);
  287. cancel_delayed_work_sync(&spec->vt1708_hp_work);
  288. }
  289. static void set_widgets_power_state(struct hda_codec *codec)
  290. {
  291. struct via_spec *spec = codec->spec;
  292. if (spec->set_widgets_power_state)
  293. spec->set_widgets_power_state(codec);
  294. }
  295. static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
  296. struct snd_ctl_elem_value *ucontrol)
  297. {
  298. int change = snd_hda_mixer_amp_switch_put(kcontrol, ucontrol);
  299. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  300. set_widgets_power_state(codec);
  301. analog_low_current_mode(snd_kcontrol_chip(kcontrol));
  302. if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) {
  303. if (is_aa_path_mute(codec))
  304. vt1708_start_hp_work(codec->spec);
  305. else
  306. vt1708_stop_hp_work(codec->spec);
  307. }
  308. return change;
  309. }
  310. /* modify .put = snd_hda_mixer_amp_switch_put */
  311. #define ANALOG_INPUT_MUTE \
  312. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  313. .name = NULL, \
  314. .index = 0, \
  315. .info = snd_hda_mixer_amp_switch_info, \
  316. .get = snd_hda_mixer_amp_switch_get, \
  317. .put = analog_input_switch_put, \
  318. .private_value = HDA_COMPOSE_AMP_VAL(0, 3, 0, 0) }
  319. static const struct snd_kcontrol_new via_control_templates[] = {
  320. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  321. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  322. ANALOG_INPUT_MUTE,
  323. };
  324. /* add dynamic controls */
  325. static struct snd_kcontrol_new *__via_clone_ctl(struct via_spec *spec,
  326. const struct snd_kcontrol_new *tmpl,
  327. const char *name)
  328. {
  329. struct snd_kcontrol_new *knew;
  330. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  331. knew = snd_array_new(&spec->kctls);
  332. if (!knew)
  333. return NULL;
  334. *knew = *tmpl;
  335. if (!name)
  336. name = tmpl->name;
  337. if (name) {
  338. knew->name = kstrdup(name, GFP_KERNEL);
  339. if (!knew->name)
  340. return NULL;
  341. }
  342. return knew;
  343. }
  344. static int __via_add_control(struct via_spec *spec, int type, const char *name,
  345. int idx, unsigned long val)
  346. {
  347. struct snd_kcontrol_new *knew;
  348. knew = __via_clone_ctl(spec, &via_control_templates[type], name);
  349. if (!knew)
  350. return -ENOMEM;
  351. knew->index = idx;
  352. if (get_amp_nid_(val))
  353. knew->subdevice = HDA_SUBDEV_AMP_FLAG;
  354. knew->private_value = val;
  355. return 0;
  356. }
  357. #define via_add_control(spec, type, name, val) \
  358. __via_add_control(spec, type, name, 0, val)
  359. #define via_clone_control(spec, tmpl) __via_clone_ctl(spec, tmpl, NULL)
  360. static void via_free_kctls(struct hda_codec *codec)
  361. {
  362. struct via_spec *spec = codec->spec;
  363. if (spec->kctls.list) {
  364. struct snd_kcontrol_new *kctl = spec->kctls.list;
  365. int i;
  366. for (i = 0; i < spec->kctls.used; i++)
  367. kfree(kctl[i].name);
  368. }
  369. snd_array_free(&spec->kctls);
  370. }
  371. /* create input playback/capture controls for the given pin */
  372. static int via_new_analog_input(struct via_spec *spec, const char *ctlname,
  373. int type_idx, int idx, int mix_nid)
  374. {
  375. char name[32];
  376. int err;
  377. sprintf(name, "%s Playback Volume", ctlname);
  378. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL, name, type_idx,
  379. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  380. if (err < 0)
  381. return err;
  382. sprintf(name, "%s Playback Switch", ctlname);
  383. err = __via_add_control(spec, VIA_CTL_WIDGET_ANALOG_MUTE, name, type_idx,
  384. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  385. if (err < 0)
  386. return err;
  387. return 0;
  388. }
  389. #define get_connection_index(codec, mux, nid) \
  390. snd_hda_get_conn_index(codec, mux, nid, 0)
  391. static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
  392. unsigned int mask)
  393. {
  394. unsigned int caps;
  395. if (!nid)
  396. return false;
  397. caps = get_wcaps(codec, nid);
  398. if (dir == HDA_INPUT)
  399. caps &= AC_WCAP_IN_AMP;
  400. else
  401. caps &= AC_WCAP_OUT_AMP;
  402. if (!caps)
  403. return false;
  404. if (query_amp_caps(codec, nid, dir) & mask)
  405. return true;
  406. return false;
  407. }
  408. #define have_mute(codec, nid, dir) \
  409. check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
  410. /* enable/disable the output-route mixers */
  411. static void activate_output_mix(struct hda_codec *codec, struct nid_path *path,
  412. hda_nid_t mix_nid, int idx, bool enable)
  413. {
  414. int i, num, val;
  415. if (!path)
  416. return;
  417. num = snd_hda_get_conn_list(codec, mix_nid, NULL);
  418. for (i = 0; i < num; i++) {
  419. if (i == idx)
  420. val = AMP_IN_UNMUTE(i);
  421. else
  422. val = AMP_IN_MUTE(i);
  423. snd_hda_codec_write(codec, mix_nid, 0,
  424. AC_VERB_SET_AMP_GAIN_MUTE, val);
  425. }
  426. }
  427. /* enable/disable the output-route */
  428. static void activate_output_path(struct hda_codec *codec, struct nid_path *path,
  429. bool enable, bool force)
  430. {
  431. struct via_spec *spec = codec->spec;
  432. int i;
  433. for (i = 0; i < path->depth; i++) {
  434. hda_nid_t src, dst;
  435. int idx = path->idx[i];
  436. src = path->path[i];
  437. if (i < path->depth - 1)
  438. dst = path->path[i + 1];
  439. else
  440. dst = 0;
  441. if (enable && path->multi[i])
  442. snd_hda_codec_write(codec, dst, 0,
  443. AC_VERB_SET_CONNECT_SEL, idx);
  444. if (!force && (dst == spec->aa_mix_nid))
  445. continue;
  446. if (have_mute(codec, dst, HDA_INPUT))
  447. activate_output_mix(codec, path, dst, idx, enable);
  448. if (!force && (src == path->vol_ctl || src == path->mute_ctl))
  449. continue;
  450. if (have_mute(codec, src, HDA_OUTPUT)) {
  451. int val = enable ? AMP_OUT_UNMUTE : AMP_OUT_MUTE;
  452. snd_hda_codec_write(codec, src, 0,
  453. AC_VERB_SET_AMP_GAIN_MUTE, val);
  454. }
  455. }
  456. }
  457. /* set the given pin as output */
  458. static void init_output_pin(struct hda_codec *codec, hda_nid_t pin,
  459. int pin_type)
  460. {
  461. if (!pin)
  462. return;
  463. snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  464. pin_type);
  465. if (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_EAPD)
  466. snd_hda_codec_write(codec, pin, 0,
  467. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  468. }
  469. static void via_auto_init_output(struct hda_codec *codec,
  470. struct nid_path *path, int pin_type)
  471. {
  472. unsigned int caps;
  473. hda_nid_t pin;
  474. if (!path->depth)
  475. return;
  476. pin = path->path[path->depth - 1];
  477. init_output_pin(codec, pin, pin_type);
  478. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  479. if (caps & AC_AMPCAP_MUTE) {
  480. unsigned int val;
  481. val = (caps & AC_AMPCAP_OFFSET) >> AC_AMPCAP_OFFSET_SHIFT;
  482. snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  483. AMP_OUT_MUTE | val);
  484. }
  485. activate_output_path(codec, path, true, true); /* force on */
  486. }
  487. static void via_auto_init_multi_out(struct hda_codec *codec)
  488. {
  489. struct via_spec *spec = codec->spec;
  490. struct nid_path *path;
  491. int i;
  492. for (i = 0; i < spec->autocfg.line_outs + spec->smart51_nums; i++) {
  493. path = &spec->out_path[i];
  494. if (!i && spec->aamix_mode && spec->out_mix_path.depth)
  495. path = &spec->out_mix_path;
  496. via_auto_init_output(codec, path, PIN_OUT);
  497. }
  498. }
  499. /* deactivate the inactive headphone-paths */
  500. static void deactivate_hp_paths(struct hda_codec *codec)
  501. {
  502. struct via_spec *spec = codec->spec;
  503. int shared = spec->hp_indep_shared;
  504. if (spec->hp_independent_mode) {
  505. activate_output_path(codec, &spec->hp_path, false, false);
  506. activate_output_path(codec, &spec->hp_mix_path, false, false);
  507. if (shared)
  508. activate_output_path(codec, &spec->out_path[shared],
  509. false, false);
  510. } else if (spec->aamix_mode || !spec->hp_path.depth) {
  511. activate_output_path(codec, &spec->hp_indep_path, false, false);
  512. activate_output_path(codec, &spec->hp_path, false, false);
  513. } else {
  514. activate_output_path(codec, &spec->hp_indep_path, false, false);
  515. activate_output_path(codec, &spec->hp_mix_path, false, false);
  516. }
  517. }
  518. static void via_auto_init_hp_out(struct hda_codec *codec)
  519. {
  520. struct via_spec *spec = codec->spec;
  521. if (!spec->hp_path.depth) {
  522. via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
  523. return;
  524. }
  525. deactivate_hp_paths(codec);
  526. if (spec->hp_independent_mode)
  527. via_auto_init_output(codec, &spec->hp_indep_path, PIN_HP);
  528. else if (spec->aamix_mode)
  529. via_auto_init_output(codec, &spec->hp_mix_path, PIN_HP);
  530. else
  531. via_auto_init_output(codec, &spec->hp_path, PIN_HP);
  532. }
  533. static void via_auto_init_speaker_out(struct hda_codec *codec)
  534. {
  535. struct via_spec *spec = codec->spec;
  536. if (!spec->autocfg.speaker_outs)
  537. return;
  538. if (!spec->speaker_path.depth) {
  539. via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
  540. return;
  541. }
  542. if (!spec->aamix_mode) {
  543. activate_output_path(codec, &spec->speaker_mix_path,
  544. false, false);
  545. via_auto_init_output(codec, &spec->speaker_path, PIN_OUT);
  546. } else {
  547. activate_output_path(codec, &spec->speaker_path, false, false);
  548. via_auto_init_output(codec, &spec->speaker_mix_path, PIN_OUT);
  549. }
  550. }
  551. static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin);
  552. static void via_hp_automute(struct hda_codec *codec);
  553. static void via_auto_init_analog_input(struct hda_codec *codec)
  554. {
  555. struct via_spec *spec = codec->spec;
  556. const struct auto_pin_cfg *cfg = &spec->autocfg;
  557. hda_nid_t conn[HDA_MAX_CONNECTIONS];
  558. unsigned int ctl;
  559. int i, num_conns;
  560. /* init ADCs */
  561. for (i = 0; i < spec->num_adc_nids; i++) {
  562. snd_hda_codec_write(codec, spec->adc_nids[i], 0,
  563. AC_VERB_SET_AMP_GAIN_MUTE,
  564. AMP_IN_UNMUTE(0));
  565. }
  566. /* init pins */
  567. for (i = 0; i < cfg->num_inputs; i++) {
  568. hda_nid_t nid = cfg->inputs[i].pin;
  569. if (spec->smart51_enabled && is_smart51_pins(codec, nid))
  570. ctl = PIN_OUT;
  571. else if (cfg->inputs[i].type == AUTO_PIN_MIC)
  572. ctl = PIN_VREF50;
  573. else
  574. ctl = PIN_IN;
  575. snd_hda_codec_write(codec, nid, 0,
  576. AC_VERB_SET_PIN_WIDGET_CONTROL, ctl);
  577. }
  578. /* init input-src */
  579. for (i = 0; i < spec->num_adc_nids; i++) {
  580. int adc_idx = spec->inputs[spec->cur_mux[i]].adc_idx;
  581. if (spec->mux_nids[adc_idx]) {
  582. int mux_idx = spec->inputs[spec->cur_mux[i]].mux_idx;
  583. snd_hda_codec_write(codec, spec->mux_nids[adc_idx], 0,
  584. AC_VERB_SET_CONNECT_SEL,
  585. mux_idx);
  586. }
  587. if (spec->dyn_adc_switch)
  588. break; /* only one input-src */
  589. }
  590. /* init aa-mixer */
  591. if (!spec->aa_mix_nid)
  592. return;
  593. num_conns = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
  594. ARRAY_SIZE(conn));
  595. for (i = 0; i < num_conns; i++) {
  596. unsigned int caps = get_wcaps(codec, conn[i]);
  597. if (get_wcaps_type(caps) == AC_WID_PIN)
  598. snd_hda_codec_write(codec, spec->aa_mix_nid, 0,
  599. AC_VERB_SET_AMP_GAIN_MUTE,
  600. AMP_IN_MUTE(i));
  601. }
  602. }
  603. static void set_pin_power_state(struct hda_codec *codec, hda_nid_t nid,
  604. unsigned int *affected_parm)
  605. {
  606. unsigned parm;
  607. unsigned def_conf = snd_hda_codec_get_pincfg(codec, nid);
  608. unsigned no_presence = (def_conf & AC_DEFCFG_MISC)
  609. >> AC_DEFCFG_MISC_SHIFT
  610. & AC_DEFCFG_MISC_NO_PRESENCE; /* do not support pin sense */
  611. struct via_spec *spec = codec->spec;
  612. unsigned present = 0;
  613. no_presence |= spec->no_pin_power_ctl;
  614. if (!no_presence)
  615. present = snd_hda_jack_detect(codec, nid);
  616. if ((spec->smart51_enabled && is_smart51_pins(codec, nid))
  617. || ((no_presence || present)
  618. && get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)) {
  619. *affected_parm = AC_PWRST_D0; /* if it's connected */
  620. parm = AC_PWRST_D0;
  621. } else
  622. parm = AC_PWRST_D3;
  623. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE, parm);
  624. }
  625. static int via_pin_power_ctl_info(struct snd_kcontrol *kcontrol,
  626. struct snd_ctl_elem_info *uinfo)
  627. {
  628. static const char * const texts[] = {
  629. "Disabled", "Enabled"
  630. };
  631. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  632. uinfo->count = 1;
  633. uinfo->value.enumerated.items = 2;
  634. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  635. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  636. strcpy(uinfo->value.enumerated.name,
  637. texts[uinfo->value.enumerated.item]);
  638. return 0;
  639. }
  640. static int via_pin_power_ctl_get(struct snd_kcontrol *kcontrol,
  641. struct snd_ctl_elem_value *ucontrol)
  642. {
  643. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  644. struct via_spec *spec = codec->spec;
  645. ucontrol->value.enumerated.item[0] = !spec->no_pin_power_ctl;
  646. return 0;
  647. }
  648. static int via_pin_power_ctl_put(struct snd_kcontrol *kcontrol,
  649. struct snd_ctl_elem_value *ucontrol)
  650. {
  651. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  652. struct via_spec *spec = codec->spec;
  653. unsigned int val = !ucontrol->value.enumerated.item[0];
  654. if (val == spec->no_pin_power_ctl)
  655. return 0;
  656. spec->no_pin_power_ctl = val;
  657. set_widgets_power_state(codec);
  658. return 1;
  659. }
  660. static const struct snd_kcontrol_new via_pin_power_ctl_enum = {
  661. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  662. .name = "Dynamic Power-Control",
  663. .info = via_pin_power_ctl_info,
  664. .get = via_pin_power_ctl_get,
  665. .put = via_pin_power_ctl_put,
  666. };
  667. static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
  668. struct snd_ctl_elem_info *uinfo)
  669. {
  670. static const char * const texts[] = { "OFF", "ON" };
  671. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  672. uinfo->count = 1;
  673. uinfo->value.enumerated.items = 2;
  674. if (uinfo->value.enumerated.item >= 2)
  675. uinfo->value.enumerated.item = 1;
  676. strcpy(uinfo->value.enumerated.name,
  677. texts[uinfo->value.enumerated.item]);
  678. return 0;
  679. }
  680. static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
  681. struct snd_ctl_elem_value *ucontrol)
  682. {
  683. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  684. struct via_spec *spec = codec->spec;
  685. ucontrol->value.enumerated.item[0] = spec->hp_independent_mode;
  686. return 0;
  687. }
  688. /* adjust spec->multiout setup according to the current flags */
  689. static void setup_playback_multi_pcm(struct via_spec *spec)
  690. {
  691. const struct auto_pin_cfg *cfg = &spec->autocfg;
  692. spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
  693. spec->multiout.hp_nid = 0;
  694. if (!spec->hp_independent_mode) {
  695. if (!spec->hp_indep_shared)
  696. spec->multiout.hp_nid = spec->hp_dac_nid;
  697. } else {
  698. if (spec->hp_indep_shared)
  699. spec->multiout.num_dacs = cfg->line_outs - 1;
  700. }
  701. }
  702. /* update DAC setups according to indep-HP switch;
  703. * this function is called only when indep-HP is modified
  704. */
  705. static void switch_indep_hp_dacs(struct hda_codec *codec)
  706. {
  707. struct via_spec *spec = codec->spec;
  708. int shared = spec->hp_indep_shared;
  709. hda_nid_t shared_dac, hp_dac;
  710. if (!spec->opened_streams)
  711. return;
  712. shared_dac = shared ? spec->multiout.dac_nids[shared] : 0;
  713. hp_dac = spec->hp_dac_nid;
  714. if (spec->hp_independent_mode) {
  715. /* switch to indep-HP mode */
  716. if (spec->active_streams & STREAM_MULTI_OUT) {
  717. __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
  718. __snd_hda_codec_cleanup_stream(codec, shared_dac, 1);
  719. }
  720. if (spec->active_streams & STREAM_INDEP_HP)
  721. snd_hda_codec_setup_stream(codec, hp_dac,
  722. spec->cur_hp_stream_tag, 0,
  723. spec->cur_hp_format);
  724. } else {
  725. /* back to HP or shared-DAC */
  726. if (spec->active_streams & STREAM_INDEP_HP)
  727. __snd_hda_codec_cleanup_stream(codec, hp_dac, 1);
  728. if (spec->active_streams & STREAM_MULTI_OUT) {
  729. hda_nid_t dac;
  730. int ch;
  731. if (shared_dac) { /* reset mutli-ch DAC */
  732. dac = shared_dac;
  733. ch = shared * 2;
  734. } else { /* reset HP DAC */
  735. dac = hp_dac;
  736. ch = 0;
  737. }
  738. snd_hda_codec_setup_stream(codec, dac,
  739. spec->cur_dac_stream_tag, ch,
  740. spec->cur_dac_format);
  741. }
  742. }
  743. setup_playback_multi_pcm(spec);
  744. }
  745. static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
  746. struct snd_ctl_elem_value *ucontrol)
  747. {
  748. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  749. struct via_spec *spec = codec->spec;
  750. int cur, shared;
  751. mutex_lock(&spec->config_mutex);
  752. cur = !!ucontrol->value.enumerated.item[0];
  753. if (spec->hp_independent_mode == cur) {
  754. mutex_unlock(&spec->config_mutex);
  755. return 0;
  756. }
  757. spec->hp_independent_mode = cur;
  758. shared = spec->hp_indep_shared;
  759. deactivate_hp_paths(codec);
  760. if (cur)
  761. activate_output_path(codec, &spec->hp_indep_path, true, false);
  762. else {
  763. if (shared)
  764. activate_output_path(codec, &spec->out_path[shared],
  765. true, false);
  766. if (spec->aamix_mode || !spec->hp_path.depth)
  767. activate_output_path(codec, &spec->hp_mix_path,
  768. true, false);
  769. else
  770. activate_output_path(codec, &spec->hp_path,
  771. true, false);
  772. }
  773. switch_indep_hp_dacs(codec);
  774. mutex_unlock(&spec->config_mutex);
  775. /* update jack power state */
  776. set_widgets_power_state(codec);
  777. via_hp_automute(codec);
  778. return 1;
  779. }
  780. static const struct snd_kcontrol_new via_hp_mixer = {
  781. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  782. .name = "Independent HP",
  783. .info = via_independent_hp_info,
  784. .get = via_independent_hp_get,
  785. .put = via_independent_hp_put,
  786. };
  787. static int via_hp_build(struct hda_codec *codec)
  788. {
  789. struct via_spec *spec = codec->spec;
  790. struct snd_kcontrol_new *knew;
  791. hda_nid_t nid;
  792. nid = spec->autocfg.hp_pins[0];
  793. knew = via_clone_control(spec, &via_hp_mixer);
  794. if (knew == NULL)
  795. return -ENOMEM;
  796. knew->subdevice = HDA_SUBDEV_NID_FLAG | nid;
  797. return 0;
  798. }
  799. static void notify_aa_path_ctls(struct hda_codec *codec)
  800. {
  801. struct via_spec *spec = codec->spec;
  802. int i;
  803. for (i = 0; i < spec->smart51_nums; i++) {
  804. struct snd_kcontrol *ctl;
  805. struct snd_ctl_elem_id id;
  806. memset(&id, 0, sizeof(id));
  807. id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  808. sprintf(id.name, "%s Playback Volume", spec->smart51_labels[i]);
  809. ctl = snd_hda_find_mixer_ctl(codec, id.name);
  810. if (ctl)
  811. snd_ctl_notify(codec->bus->card,
  812. SNDRV_CTL_EVENT_MASK_VALUE,
  813. &ctl->id);
  814. }
  815. }
  816. static void mute_aa_path(struct hda_codec *codec, int mute)
  817. {
  818. struct via_spec *spec = codec->spec;
  819. int val = mute ? HDA_AMP_MUTE : HDA_AMP_UNMUTE;
  820. int i;
  821. /* check AA path's mute status */
  822. for (i = 0; i < spec->smart51_nums; i++) {
  823. if (spec->smart51_idxs[i] < 0)
  824. continue;
  825. snd_hda_codec_amp_stereo(codec, spec->aa_mix_nid,
  826. HDA_INPUT, spec->smart51_idxs[i],
  827. HDA_AMP_MUTE, val);
  828. }
  829. }
  830. static bool is_smart51_pins(struct hda_codec *codec, hda_nid_t pin)
  831. {
  832. struct via_spec *spec = codec->spec;
  833. int i;
  834. for (i = 0; i < spec->smart51_nums; i++)
  835. if (spec->smart51_pins[i] == pin)
  836. return true;
  837. return false;
  838. }
  839. static int via_smart51_get(struct snd_kcontrol *kcontrol,
  840. struct snd_ctl_elem_value *ucontrol)
  841. {
  842. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  843. struct via_spec *spec = codec->spec;
  844. *ucontrol->value.integer.value = spec->smart51_enabled;
  845. return 0;
  846. }
  847. static int via_smart51_put(struct snd_kcontrol *kcontrol,
  848. struct snd_ctl_elem_value *ucontrol)
  849. {
  850. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  851. struct via_spec *spec = codec->spec;
  852. int out_in = *ucontrol->value.integer.value
  853. ? AC_PINCTL_OUT_EN : AC_PINCTL_IN_EN;
  854. int i;
  855. for (i = 0; i < spec->smart51_nums; i++) {
  856. hda_nid_t nid = spec->smart51_pins[i];
  857. unsigned int parm;
  858. parm = snd_hda_codec_read(codec, nid, 0,
  859. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  860. parm &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  861. parm |= out_in;
  862. snd_hda_codec_write(codec, nid, 0,
  863. AC_VERB_SET_PIN_WIDGET_CONTROL,
  864. parm);
  865. if (out_in == AC_PINCTL_OUT_EN) {
  866. mute_aa_path(codec, 1);
  867. notify_aa_path_ctls(codec);
  868. }
  869. }
  870. spec->smart51_enabled = *ucontrol->value.integer.value;
  871. set_widgets_power_state(codec);
  872. return 1;
  873. }
  874. static const struct snd_kcontrol_new via_smart51_mixer = {
  875. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  876. .name = "Smart 5.1",
  877. .count = 1,
  878. .info = snd_ctl_boolean_mono_info,
  879. .get = via_smart51_get,
  880. .put = via_smart51_put,
  881. };
  882. static int via_smart51_build(struct hda_codec *codec)
  883. {
  884. struct via_spec *spec = codec->spec;
  885. if (!spec->smart51_nums)
  886. return 0;
  887. if (!via_clone_control(spec, &via_smart51_mixer))
  888. return -ENOMEM;
  889. return 0;
  890. }
  891. /* check AA path's mute status */
  892. static bool is_aa_path_mute(struct hda_codec *codec)
  893. {
  894. struct via_spec *spec = codec->spec;
  895. const struct hda_amp_list *p;
  896. int i, ch, v;
  897. for (i = 0; i < spec->num_loopbacks; i++) {
  898. p = &spec->loopback_list[i];
  899. for (ch = 0; ch < 2; ch++) {
  900. v = snd_hda_codec_amp_read(codec, p->nid, ch, p->dir,
  901. p->idx);
  902. if (!(v & HDA_AMP_MUTE) && v > 0)
  903. return false;
  904. }
  905. }
  906. return true;
  907. }
  908. /* enter/exit analog low-current mode */
  909. static void analog_low_current_mode(struct hda_codec *codec)
  910. {
  911. struct via_spec *spec = codec->spec;
  912. bool enable;
  913. unsigned int verb, parm;
  914. enable = is_aa_path_mute(codec) && (spec->opened_streams != 0);
  915. /* decide low current mode's verb & parameter */
  916. switch (spec->codec_type) {
  917. case VT1708B_8CH:
  918. case VT1708B_4CH:
  919. verb = 0xf70;
  920. parm = enable ? 0x02 : 0x00; /* 0x02: 2/3x, 0x00: 1x */
  921. break;
  922. case VT1708S:
  923. case VT1718S:
  924. case VT1716S:
  925. verb = 0xf73;
  926. parm = enable ? 0x51 : 0xe1; /* 0x51: 4/28x, 0xe1: 1x */
  927. break;
  928. case VT1702:
  929. verb = 0xf73;
  930. parm = enable ? 0x01 : 0x1d; /* 0x01: 4/40x, 0x1d: 1x */
  931. break;
  932. case VT2002P:
  933. case VT1812:
  934. case VT1802:
  935. verb = 0xf93;
  936. parm = enable ? 0x00 : 0xe0; /* 0x00: 4/40x, 0xe0: 1x */
  937. break;
  938. default:
  939. return; /* other codecs are not supported */
  940. }
  941. /* send verb */
  942. snd_hda_codec_write(codec, codec->afg, 0, verb, parm);
  943. }
  944. /*
  945. * generic initialization of ADC, input mixers and output mixers
  946. */
  947. static const struct hda_verb vt1708_init_verbs[] = {
  948. /* power down jack detect function */
  949. {0x1, 0xf81, 0x1},
  950. { }
  951. };
  952. static void set_stream_open(struct hda_codec *codec, int bit, bool active)
  953. {
  954. struct via_spec *spec = codec->spec;
  955. if (active)
  956. spec->opened_streams |= bit;
  957. else
  958. spec->opened_streams &= ~bit;
  959. analog_low_current_mode(codec);
  960. }
  961. static int via_playback_multi_pcm_open(struct hda_pcm_stream *hinfo,
  962. struct hda_codec *codec,
  963. struct snd_pcm_substream *substream)
  964. {
  965. struct via_spec *spec = codec->spec;
  966. const struct auto_pin_cfg *cfg = &spec->autocfg;
  967. int err;
  968. spec->multiout.num_dacs = cfg->line_outs + spec->smart51_nums;
  969. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  970. set_stream_open(codec, STREAM_MULTI_OUT, true);
  971. err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  972. hinfo);
  973. if (err < 0) {
  974. set_stream_open(codec, STREAM_MULTI_OUT, false);
  975. return err;
  976. }
  977. return 0;
  978. }
  979. static int via_playback_multi_pcm_close(struct hda_pcm_stream *hinfo,
  980. struct hda_codec *codec,
  981. struct snd_pcm_substream *substream)
  982. {
  983. set_stream_open(codec, STREAM_MULTI_OUT, false);
  984. return 0;
  985. }
  986. static int via_playback_hp_pcm_open(struct hda_pcm_stream *hinfo,
  987. struct hda_codec *codec,
  988. struct snd_pcm_substream *substream)
  989. {
  990. struct via_spec *spec = codec->spec;
  991. if (snd_BUG_ON(!spec->hp_dac_nid))
  992. return -EINVAL;
  993. set_stream_open(codec, STREAM_INDEP_HP, true);
  994. return 0;
  995. }
  996. static int via_playback_hp_pcm_close(struct hda_pcm_stream *hinfo,
  997. struct hda_codec *codec,
  998. struct snd_pcm_substream *substream)
  999. {
  1000. set_stream_open(codec, STREAM_INDEP_HP, false);
  1001. return 0;
  1002. }
  1003. static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
  1004. struct hda_codec *codec,
  1005. unsigned int stream_tag,
  1006. unsigned int format,
  1007. struct snd_pcm_substream *substream)
  1008. {
  1009. struct via_spec *spec = codec->spec;
  1010. mutex_lock(&spec->config_mutex);
  1011. setup_playback_multi_pcm(spec);
  1012. snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  1013. format, substream);
  1014. /* remember for dynamic DAC switch with indep-HP */
  1015. spec->active_streams |= STREAM_MULTI_OUT;
  1016. spec->cur_dac_stream_tag = stream_tag;
  1017. spec->cur_dac_format = format;
  1018. mutex_unlock(&spec->config_mutex);
  1019. vt1708_start_hp_work(spec);
  1020. return 0;
  1021. }
  1022. static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
  1023. struct hda_codec *codec,
  1024. unsigned int stream_tag,
  1025. unsigned int format,
  1026. struct snd_pcm_substream *substream)
  1027. {
  1028. struct via_spec *spec = codec->spec;
  1029. mutex_lock(&spec->config_mutex);
  1030. if (spec->hp_independent_mode)
  1031. snd_hda_codec_setup_stream(codec, spec->hp_dac_nid,
  1032. stream_tag, 0, format);
  1033. spec->active_streams |= STREAM_INDEP_HP;
  1034. spec->cur_hp_stream_tag = stream_tag;
  1035. spec->cur_hp_format = format;
  1036. mutex_unlock(&spec->config_mutex);
  1037. vt1708_start_hp_work(spec);
  1038. return 0;
  1039. }
  1040. static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1041. struct hda_codec *codec,
  1042. struct snd_pcm_substream *substream)
  1043. {
  1044. struct via_spec *spec = codec->spec;
  1045. mutex_lock(&spec->config_mutex);
  1046. snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1047. spec->active_streams &= ~STREAM_MULTI_OUT;
  1048. mutex_unlock(&spec->config_mutex);
  1049. vt1708_stop_hp_work(spec);
  1050. return 0;
  1051. }
  1052. static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1053. struct hda_codec *codec,
  1054. struct snd_pcm_substream *substream)
  1055. {
  1056. struct via_spec *spec = codec->spec;
  1057. mutex_lock(&spec->config_mutex);
  1058. if (spec->hp_independent_mode)
  1059. snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
  1060. spec->active_streams &= ~STREAM_INDEP_HP;
  1061. mutex_unlock(&spec->config_mutex);
  1062. vt1708_stop_hp_work(spec);
  1063. return 0;
  1064. }
  1065. /*
  1066. * Digital out
  1067. */
  1068. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1069. struct hda_codec *codec,
  1070. struct snd_pcm_substream *substream)
  1071. {
  1072. struct via_spec *spec = codec->spec;
  1073. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1074. }
  1075. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1076. struct hda_codec *codec,
  1077. struct snd_pcm_substream *substream)
  1078. {
  1079. struct via_spec *spec = codec->spec;
  1080. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1081. }
  1082. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1083. struct hda_codec *codec,
  1084. unsigned int stream_tag,
  1085. unsigned int format,
  1086. struct snd_pcm_substream *substream)
  1087. {
  1088. struct via_spec *spec = codec->spec;
  1089. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1090. stream_tag, format, substream);
  1091. }
  1092. static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1093. struct hda_codec *codec,
  1094. struct snd_pcm_substream *substream)
  1095. {
  1096. struct via_spec *spec = codec->spec;
  1097. snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  1098. return 0;
  1099. }
  1100. /*
  1101. * Analog capture
  1102. */
  1103. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1104. struct hda_codec *codec,
  1105. unsigned int stream_tag,
  1106. unsigned int format,
  1107. struct snd_pcm_substream *substream)
  1108. {
  1109. struct via_spec *spec = codec->spec;
  1110. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1111. stream_tag, 0, format);
  1112. return 0;
  1113. }
  1114. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1115. struct hda_codec *codec,
  1116. struct snd_pcm_substream *substream)
  1117. {
  1118. struct via_spec *spec = codec->spec;
  1119. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  1120. return 0;
  1121. }
  1122. /* analog capture with dynamic ADC switching */
  1123. static int via_dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1124. struct hda_codec *codec,
  1125. unsigned int stream_tag,
  1126. unsigned int format,
  1127. struct snd_pcm_substream *substream)
  1128. {
  1129. struct via_spec *spec = codec->spec;
  1130. int adc_idx = spec->inputs[spec->cur_mux[0]].adc_idx;
  1131. mutex_lock(&spec->config_mutex);
  1132. spec->cur_adc = spec->adc_nids[adc_idx];
  1133. spec->cur_adc_stream_tag = stream_tag;
  1134. spec->cur_adc_format = format;
  1135. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  1136. mutex_unlock(&spec->config_mutex);
  1137. return 0;
  1138. }
  1139. static int via_dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1140. struct hda_codec *codec,
  1141. struct snd_pcm_substream *substream)
  1142. {
  1143. struct via_spec *spec = codec->spec;
  1144. mutex_lock(&spec->config_mutex);
  1145. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1146. spec->cur_adc = 0;
  1147. mutex_unlock(&spec->config_mutex);
  1148. return 0;
  1149. }
  1150. /* re-setup the stream if running; called from input-src put */
  1151. static bool via_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
  1152. {
  1153. struct via_spec *spec = codec->spec;
  1154. int adc_idx = spec->inputs[cur].adc_idx;
  1155. hda_nid_t adc = spec->adc_nids[adc_idx];
  1156. bool ret = false;
  1157. mutex_lock(&spec->config_mutex);
  1158. if (spec->cur_adc && spec->cur_adc != adc) {
  1159. /* stream is running, let's swap the current ADC */
  1160. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1161. spec->cur_adc = adc;
  1162. snd_hda_codec_setup_stream(codec, adc,
  1163. spec->cur_adc_stream_tag, 0,
  1164. spec->cur_adc_format);
  1165. ret = true;
  1166. }
  1167. mutex_unlock(&spec->config_mutex);
  1168. return ret;
  1169. }
  1170. static const struct hda_pcm_stream via_pcm_analog_playback = {
  1171. .substreams = 1,
  1172. .channels_min = 2,
  1173. .channels_max = 8,
  1174. /* NID is set in via_build_pcms */
  1175. .ops = {
  1176. .open = via_playback_multi_pcm_open,
  1177. .close = via_playback_multi_pcm_close,
  1178. .prepare = via_playback_multi_pcm_prepare,
  1179. .cleanup = via_playback_multi_pcm_cleanup
  1180. },
  1181. };
  1182. static const struct hda_pcm_stream via_pcm_hp_playback = {
  1183. .substreams = 1,
  1184. .channels_min = 2,
  1185. .channels_max = 2,
  1186. /* NID is set in via_build_pcms */
  1187. .ops = {
  1188. .open = via_playback_hp_pcm_open,
  1189. .close = via_playback_hp_pcm_close,
  1190. .prepare = via_playback_hp_pcm_prepare,
  1191. .cleanup = via_playback_hp_pcm_cleanup
  1192. },
  1193. };
  1194. static const struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
  1195. .substreams = 1,
  1196. .channels_min = 2,
  1197. .channels_max = 8,
  1198. /* NID is set in via_build_pcms */
  1199. /* We got noisy outputs on the right channel on VT1708 when
  1200. * 24bit samples are used. Until any workaround is found,
  1201. * disable the 24bit format, so far.
  1202. */
  1203. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  1204. .ops = {
  1205. .open = via_playback_multi_pcm_open,
  1206. .close = via_playback_multi_pcm_close,
  1207. .prepare = via_playback_multi_pcm_prepare,
  1208. .cleanup = via_playback_multi_pcm_cleanup
  1209. },
  1210. };
  1211. static const struct hda_pcm_stream via_pcm_analog_capture = {
  1212. .substreams = 1, /* will be changed in via_build_pcms() */
  1213. .channels_min = 2,
  1214. .channels_max = 2,
  1215. /* NID is set in via_build_pcms */
  1216. .ops = {
  1217. .prepare = via_capture_pcm_prepare,
  1218. .cleanup = via_capture_pcm_cleanup
  1219. },
  1220. };
  1221. static const struct hda_pcm_stream via_pcm_dyn_adc_analog_capture = {
  1222. .substreams = 1,
  1223. .channels_min = 2,
  1224. .channels_max = 2,
  1225. /* NID is set in via_build_pcms */
  1226. .ops = {
  1227. .prepare = via_dyn_adc_capture_pcm_prepare,
  1228. .cleanup = via_dyn_adc_capture_pcm_cleanup,
  1229. },
  1230. };
  1231. static const struct hda_pcm_stream via_pcm_digital_playback = {
  1232. .substreams = 1,
  1233. .channels_min = 2,
  1234. .channels_max = 2,
  1235. /* NID is set in via_build_pcms */
  1236. .ops = {
  1237. .open = via_dig_playback_pcm_open,
  1238. .close = via_dig_playback_pcm_close,
  1239. .prepare = via_dig_playback_pcm_prepare,
  1240. .cleanup = via_dig_playback_pcm_cleanup
  1241. },
  1242. };
  1243. static const struct hda_pcm_stream via_pcm_digital_capture = {
  1244. .substreams = 1,
  1245. .channels_min = 2,
  1246. .channels_max = 2,
  1247. };
  1248. /*
  1249. * slave controls for virtual master
  1250. */
  1251. static const char * const via_slave_vols[] = {
  1252. "Front Playback Volume",
  1253. "Surround Playback Volume",
  1254. "Center Playback Volume",
  1255. "LFE Playback Volume",
  1256. "Side Playback Volume",
  1257. "Headphone Playback Volume",
  1258. "Speaker Playback Volume",
  1259. NULL,
  1260. };
  1261. static const char * const via_slave_sws[] = {
  1262. "Front Playback Switch",
  1263. "Surround Playback Switch",
  1264. "Center Playback Switch",
  1265. "LFE Playback Switch",
  1266. "Side Playback Switch",
  1267. "Headphone Playback Switch",
  1268. "Speaker Playback Switch",
  1269. NULL,
  1270. };
  1271. static int via_build_controls(struct hda_codec *codec)
  1272. {
  1273. struct via_spec *spec = codec->spec;
  1274. struct snd_kcontrol *kctl;
  1275. int err, i;
  1276. if (spec->set_widgets_power_state)
  1277. if (!via_clone_control(spec, &via_pin_power_ctl_enum))
  1278. return -ENOMEM;
  1279. for (i = 0; i < spec->num_mixers; i++) {
  1280. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  1281. if (err < 0)
  1282. return err;
  1283. }
  1284. if (spec->multiout.dig_out_nid) {
  1285. err = snd_hda_create_spdif_out_ctls(codec,
  1286. spec->multiout.dig_out_nid,
  1287. spec->multiout.dig_out_nid);
  1288. if (err < 0)
  1289. return err;
  1290. err = snd_hda_create_spdif_share_sw(codec,
  1291. &spec->multiout);
  1292. if (err < 0)
  1293. return err;
  1294. spec->multiout.share_spdif = 1;
  1295. }
  1296. if (spec->dig_in_nid) {
  1297. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  1298. if (err < 0)
  1299. return err;
  1300. }
  1301. /* if we have no master control, let's create it */
  1302. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  1303. unsigned int vmaster_tlv[4];
  1304. snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
  1305. HDA_OUTPUT, vmaster_tlv);
  1306. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  1307. vmaster_tlv, via_slave_vols);
  1308. if (err < 0)
  1309. return err;
  1310. }
  1311. if (!snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  1312. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  1313. NULL, via_slave_sws);
  1314. if (err < 0)
  1315. return err;
  1316. }
  1317. /* assign Capture Source enums to NID */
  1318. kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
  1319. for (i = 0; kctl && i < kctl->count; i++) {
  1320. err = snd_hda_add_nid(codec, kctl, i, spec->mux_nids[i]);
  1321. if (err < 0)
  1322. return err;
  1323. }
  1324. /* init power states */
  1325. set_widgets_power_state(codec);
  1326. analog_low_current_mode(codec);
  1327. via_free_kctls(codec); /* no longer needed */
  1328. return 0;
  1329. }
  1330. static int via_build_pcms(struct hda_codec *codec)
  1331. {
  1332. struct via_spec *spec = codec->spec;
  1333. struct hda_pcm *info = spec->pcm_rec;
  1334. codec->num_pcms = 0;
  1335. codec->pcm_info = info;
  1336. if (spec->multiout.num_dacs || spec->num_adc_nids) {
  1337. snprintf(spec->stream_name_analog,
  1338. sizeof(spec->stream_name_analog),
  1339. "%s Analog", codec->chip_name);
  1340. info->name = spec->stream_name_analog;
  1341. if (spec->multiout.num_dacs) {
  1342. if (!spec->stream_analog_playback)
  1343. spec->stream_analog_playback =
  1344. &via_pcm_analog_playback;
  1345. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1346. *spec->stream_analog_playback;
  1347. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1348. spec->multiout.dac_nids[0];
  1349. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  1350. spec->multiout.max_channels;
  1351. }
  1352. if (!spec->stream_analog_capture) {
  1353. if (spec->dyn_adc_switch)
  1354. spec->stream_analog_capture =
  1355. &via_pcm_dyn_adc_analog_capture;
  1356. else
  1357. spec->stream_analog_capture =
  1358. &via_pcm_analog_capture;
  1359. }
  1360. if (spec->num_adc_nids) {
  1361. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1362. *spec->stream_analog_capture;
  1363. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1364. spec->adc_nids[0];
  1365. if (!spec->dyn_adc_switch)
  1366. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  1367. spec->num_adc_nids;
  1368. }
  1369. codec->num_pcms++;
  1370. info++;
  1371. }
  1372. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1373. snprintf(spec->stream_name_digital,
  1374. sizeof(spec->stream_name_digital),
  1375. "%s Digital", codec->chip_name);
  1376. info->name = spec->stream_name_digital;
  1377. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  1378. if (spec->multiout.dig_out_nid) {
  1379. if (!spec->stream_digital_playback)
  1380. spec->stream_digital_playback =
  1381. &via_pcm_digital_playback;
  1382. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  1383. *spec->stream_digital_playback;
  1384. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1385. spec->multiout.dig_out_nid;
  1386. }
  1387. if (spec->dig_in_nid) {
  1388. if (!spec->stream_digital_capture)
  1389. spec->stream_digital_capture =
  1390. &via_pcm_digital_capture;
  1391. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1392. *spec->stream_digital_capture;
  1393. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1394. spec->dig_in_nid;
  1395. }
  1396. codec->num_pcms++;
  1397. info++;
  1398. }
  1399. if (spec->hp_dac_nid) {
  1400. snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
  1401. "%s HP", codec->chip_name);
  1402. info->name = spec->stream_name_hp;
  1403. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
  1404. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  1405. spec->hp_dac_nid;
  1406. codec->num_pcms++;
  1407. info++;
  1408. }
  1409. return 0;
  1410. }
  1411. static void via_free(struct hda_codec *codec)
  1412. {
  1413. struct via_spec *spec = codec->spec;
  1414. if (!spec)
  1415. return;
  1416. via_free_kctls(codec);
  1417. vt1708_stop_hp_work(spec);
  1418. kfree(spec->bind_cap_vol);
  1419. kfree(spec->bind_cap_sw);
  1420. kfree(spec);
  1421. }
  1422. /* mute/unmute outputs */
  1423. static void toggle_output_mutes(struct hda_codec *codec, int num_pins,
  1424. hda_nid_t *pins, bool mute)
  1425. {
  1426. int i;
  1427. for (i = 0; i < num_pins; i++) {
  1428. unsigned int parm = snd_hda_codec_read(codec, pins[i], 0,
  1429. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1430. if (parm & AC_PINCTL_IN_EN)
  1431. continue;
  1432. if (mute)
  1433. parm &= ~AC_PINCTL_OUT_EN;
  1434. else
  1435. parm |= AC_PINCTL_OUT_EN;
  1436. snd_hda_codec_write(codec, pins[i], 0,
  1437. AC_VERB_SET_PIN_WIDGET_CONTROL, parm);
  1438. }
  1439. }
  1440. /* mute internal speaker if line-out is plugged */
  1441. static void via_line_automute(struct hda_codec *codec, int present)
  1442. {
  1443. struct via_spec *spec = codec->spec;
  1444. if (!spec->autocfg.speaker_outs)
  1445. return;
  1446. if (!present)
  1447. present = snd_hda_jack_detect(codec,
  1448. spec->autocfg.line_out_pins[0]);
  1449. toggle_output_mutes(codec, spec->autocfg.speaker_outs,
  1450. spec->autocfg.speaker_pins,
  1451. present);
  1452. }
  1453. /* mute internal speaker if HP is plugged */
  1454. static void via_hp_automute(struct hda_codec *codec)
  1455. {
  1456. int present = 0;
  1457. int nums;
  1458. struct via_spec *spec = codec->spec;
  1459. if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0])
  1460. present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
  1461. if (spec->smart51_enabled)
  1462. nums = spec->autocfg.line_outs + spec->smart51_nums;
  1463. else
  1464. nums = spec->autocfg.line_outs;
  1465. toggle_output_mutes(codec, nums, spec->autocfg.line_out_pins, present);
  1466. via_line_automute(codec, present);
  1467. }
  1468. static void via_gpio_control(struct hda_codec *codec)
  1469. {
  1470. unsigned int gpio_data;
  1471. unsigned int vol_counter;
  1472. unsigned int vol;
  1473. unsigned int master_vol;
  1474. struct via_spec *spec = codec->spec;
  1475. gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
  1476. AC_VERB_GET_GPIO_DATA, 0) & 0x03;
  1477. vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
  1478. 0xF84, 0) & 0x3F0000) >> 16;
  1479. vol = vol_counter & 0x1F;
  1480. master_vol = snd_hda_codec_read(codec, 0x1A, 0,
  1481. AC_VERB_GET_AMP_GAIN_MUTE,
  1482. AC_AMP_GET_INPUT);
  1483. if (gpio_data == 0x02) {
  1484. /* unmute line out */
  1485. snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
  1486. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1487. PIN_OUT);
  1488. if (vol_counter & 0x20) {
  1489. /* decrease volume */
  1490. if (vol > master_vol)
  1491. vol = master_vol;
  1492. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
  1493. 0, HDA_AMP_VOLMASK,
  1494. master_vol-vol);
  1495. } else {
  1496. /* increase volume */
  1497. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
  1498. HDA_AMP_VOLMASK,
  1499. ((master_vol+vol) > 0x2A) ? 0x2A :
  1500. (master_vol+vol));
  1501. }
  1502. } else if (!(gpio_data & 0x02)) {
  1503. /* mute line out */
  1504. snd_hda_codec_write(codec, spec->autocfg.line_out_pins[0], 0,
  1505. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1506. 0);
  1507. }
  1508. }
  1509. /* unsolicited event for jack sensing */
  1510. static void via_unsol_event(struct hda_codec *codec,
  1511. unsigned int res)
  1512. {
  1513. res >>= 26;
  1514. if (res & VIA_JACK_EVENT)
  1515. set_widgets_power_state(codec);
  1516. res &= ~VIA_JACK_EVENT;
  1517. if (res == VIA_HP_EVENT || res == VIA_LINE_EVENT)
  1518. via_hp_automute(codec);
  1519. else if (res == VIA_GPIO_EVENT)
  1520. via_gpio_control(codec);
  1521. }
  1522. #ifdef CONFIG_PM
  1523. static int via_suspend(struct hda_codec *codec, pm_message_t state)
  1524. {
  1525. struct via_spec *spec = codec->spec;
  1526. vt1708_stop_hp_work(spec);
  1527. return 0;
  1528. }
  1529. #endif
  1530. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1531. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1532. {
  1533. struct via_spec *spec = codec->spec;
  1534. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1535. }
  1536. #endif
  1537. /*
  1538. */
  1539. static int via_init(struct hda_codec *codec);
  1540. static const struct hda_codec_ops via_patch_ops = {
  1541. .build_controls = via_build_controls,
  1542. .build_pcms = via_build_pcms,
  1543. .init = via_init,
  1544. .free = via_free,
  1545. .unsol_event = via_unsol_event,
  1546. #ifdef CONFIG_PM
  1547. .suspend = via_suspend,
  1548. #endif
  1549. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1550. .check_power_status = via_check_power_status,
  1551. #endif
  1552. };
  1553. static bool is_empty_dac(struct hda_codec *codec, hda_nid_t dac)
  1554. {
  1555. struct via_spec *spec = codec->spec;
  1556. int i;
  1557. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1558. if (spec->multiout.dac_nids[i] == dac)
  1559. return false;
  1560. }
  1561. if (spec->hp_dac_nid == dac)
  1562. return false;
  1563. return true;
  1564. }
  1565. static bool __parse_output_path(struct hda_codec *codec, hda_nid_t nid,
  1566. hda_nid_t target_dac, int with_aa_mix,
  1567. struct nid_path *path, int depth)
  1568. {
  1569. struct via_spec *spec = codec->spec;
  1570. hda_nid_t conn[8];
  1571. int i, nums;
  1572. if (nid == spec->aa_mix_nid) {
  1573. if (!with_aa_mix)
  1574. return false;
  1575. with_aa_mix = 2; /* mark aa-mix is included */
  1576. }
  1577. nums = snd_hda_get_connections(codec, nid, conn, ARRAY_SIZE(conn));
  1578. for (i = 0; i < nums; i++) {
  1579. if (get_wcaps_type(get_wcaps(codec, conn[i])) != AC_WID_AUD_OUT)
  1580. continue;
  1581. if (conn[i] == target_dac || is_empty_dac(codec, conn[i])) {
  1582. /* aa-mix is requested but not included? */
  1583. if (!(spec->aa_mix_nid && with_aa_mix == 1))
  1584. goto found;
  1585. }
  1586. }
  1587. if (depth >= MAX_NID_PATH_DEPTH)
  1588. return false;
  1589. for (i = 0; i < nums; i++) {
  1590. unsigned int type;
  1591. type = get_wcaps_type(get_wcaps(codec, conn[i]));
  1592. if (type == AC_WID_AUD_OUT)
  1593. continue;
  1594. if (__parse_output_path(codec, conn[i], target_dac,
  1595. with_aa_mix, path, depth + 1))
  1596. goto found;
  1597. }
  1598. return false;
  1599. found:
  1600. path->path[path->depth] = conn[i];
  1601. path->idx[path->depth] = i;
  1602. if (nums > 1 && get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_AUD_MIX)
  1603. path->multi[path->depth] = 1;
  1604. path->depth++;
  1605. return true;
  1606. }
  1607. static bool parse_output_path(struct hda_codec *codec, hda_nid_t nid,
  1608. hda_nid_t target_dac, int with_aa_mix,
  1609. struct nid_path *path)
  1610. {
  1611. if (__parse_output_path(codec, nid, target_dac, with_aa_mix, path, 1)) {
  1612. path->path[path->depth] = nid;
  1613. path->depth++;
  1614. snd_printdd("output-path: depth=%d, %02x/%02x/%02x/%02x/%02x\n",
  1615. path->depth, path->path[0], path->path[1],
  1616. path->path[2], path->path[3], path->path[4]);
  1617. return true;
  1618. }
  1619. return false;
  1620. }
  1621. static int via_auto_fill_dac_nids(struct hda_codec *codec)
  1622. {
  1623. struct via_spec *spec = codec->spec;
  1624. const struct auto_pin_cfg *cfg = &spec->autocfg;
  1625. int i, dac_num;
  1626. hda_nid_t nid;
  1627. spec->multiout.dac_nids = spec->private_dac_nids;
  1628. dac_num = 0;
  1629. for (i = 0; i < cfg->line_outs; i++) {
  1630. hda_nid_t dac = 0;
  1631. nid = cfg->line_out_pins[i];
  1632. if (!nid)
  1633. continue;
  1634. if (parse_output_path(codec, nid, 0, 0, &spec->out_path[i]))
  1635. dac = spec->out_path[i].path[0];
  1636. if (!i && parse_output_path(codec, nid, dac, 1,
  1637. &spec->out_mix_path))
  1638. dac = spec->out_mix_path.path[0];
  1639. if (dac) {
  1640. spec->private_dac_nids[i] = dac;
  1641. dac_num++;
  1642. }
  1643. }
  1644. if (!spec->out_path[0].depth && spec->out_mix_path.depth) {
  1645. spec->out_path[0] = spec->out_mix_path;
  1646. spec->out_mix_path.depth = 0;
  1647. }
  1648. spec->multiout.num_dacs = dac_num;
  1649. return 0;
  1650. }
  1651. static int create_ch_ctls(struct hda_codec *codec, const char *pfx,
  1652. int chs, bool check_dac, struct nid_path *path)
  1653. {
  1654. struct via_spec *spec = codec->spec;
  1655. char name[32];
  1656. hda_nid_t dac, pin, sel, nid;
  1657. int err;
  1658. dac = check_dac ? path->path[0] : 0;
  1659. pin = path->path[path->depth - 1];
  1660. sel = path->depth > 1 ? path->path[1] : 0;
  1661. if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1662. nid = dac;
  1663. else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1664. nid = pin;
  1665. else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_NUM_STEPS))
  1666. nid = sel;
  1667. else
  1668. nid = 0;
  1669. if (nid) {
  1670. sprintf(name, "%s Playback Volume", pfx);
  1671. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1672. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1673. if (err < 0)
  1674. return err;
  1675. path->vol_ctl = nid;
  1676. }
  1677. if (dac && check_amp_caps(codec, dac, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1678. nid = dac;
  1679. else if (check_amp_caps(codec, pin, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1680. nid = pin;
  1681. else if (check_amp_caps(codec, sel, HDA_OUTPUT, AC_AMPCAP_MUTE))
  1682. nid = sel;
  1683. else
  1684. nid = 0;
  1685. if (nid) {
  1686. sprintf(name, "%s Playback Switch", pfx);
  1687. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1688. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1689. if (err < 0)
  1690. return err;
  1691. path->mute_ctl = nid;
  1692. }
  1693. return 0;
  1694. }
  1695. static void mangle_smart51(struct hda_codec *codec)
  1696. {
  1697. struct via_spec *spec = codec->spec;
  1698. struct auto_pin_cfg *cfg = &spec->autocfg;
  1699. struct auto_pin_cfg_item *ins = cfg->inputs;
  1700. int i, j, nums, attr;
  1701. int pins[AUTO_CFG_MAX_INS];
  1702. for (attr = INPUT_PIN_ATTR_REAR; attr >= INPUT_PIN_ATTR_NORMAL; attr--) {
  1703. nums = 0;
  1704. for (i = 0; i < cfg->num_inputs; i++) {
  1705. unsigned int def;
  1706. if (ins[i].type > AUTO_PIN_LINE_IN)
  1707. continue;
  1708. def = snd_hda_codec_get_pincfg(codec, ins[i].pin);
  1709. if (snd_hda_get_input_pin_attr(def) != attr)
  1710. continue;
  1711. for (j = 0; j < nums; j++)
  1712. if (ins[pins[j]].type < ins[i].type) {
  1713. memmove(pins + j + 1, pins + j,
  1714. (nums - j) * sizeof(int));
  1715. break;
  1716. }
  1717. pins[j] = i;
  1718. nums++;
  1719. }
  1720. if (cfg->line_outs + nums < 3)
  1721. continue;
  1722. for (i = 0; i < nums; i++) {
  1723. hda_nid_t pin = ins[pins[i]].pin;
  1724. spec->smart51_pins[spec->smart51_nums++] = pin;
  1725. cfg->line_out_pins[cfg->line_outs++] = pin;
  1726. if (cfg->line_outs == 3)
  1727. break;
  1728. }
  1729. return;
  1730. }
  1731. }
  1732. static void copy_path_mixer_ctls(struct nid_path *dst, struct nid_path *src)
  1733. {
  1734. dst->vol_ctl = src->vol_ctl;
  1735. dst->mute_ctl = src->mute_ctl;
  1736. }
  1737. /* add playback controls from the parsed DAC table */
  1738. static int via_auto_create_multi_out_ctls(struct hda_codec *codec)
  1739. {
  1740. struct via_spec *spec = codec->spec;
  1741. struct auto_pin_cfg *cfg = &spec->autocfg;
  1742. struct nid_path *path;
  1743. static const char * const chname[4] = {
  1744. "Front", "Surround", "C/LFE", "Side"
  1745. };
  1746. int i, idx, err;
  1747. int old_line_outs;
  1748. /* check smart51 */
  1749. old_line_outs = cfg->line_outs;
  1750. if (cfg->line_outs == 1)
  1751. mangle_smart51(codec);
  1752. err = via_auto_fill_dac_nids(codec);
  1753. if (err < 0)
  1754. return err;
  1755. if (spec->multiout.num_dacs < 3) {
  1756. spec->smart51_nums = 0;
  1757. cfg->line_outs = old_line_outs;
  1758. }
  1759. for (i = 0; i < cfg->line_outs; i++) {
  1760. hda_nid_t pin, dac;
  1761. pin = cfg->line_out_pins[i];
  1762. dac = spec->multiout.dac_nids[i];
  1763. if (!pin || !dac)
  1764. continue;
  1765. path = spec->out_path + i;
  1766. if (i == HDA_CLFE) {
  1767. err = create_ch_ctls(codec, "Center", 1, true, path);
  1768. if (err < 0)
  1769. return err;
  1770. err = create_ch_ctls(codec, "LFE", 2, true, path);
  1771. if (err < 0)
  1772. return err;
  1773. } else {
  1774. const char *pfx = chname[i];
  1775. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
  1776. cfg->line_outs == 1)
  1777. pfx = "Speaker";
  1778. err = create_ch_ctls(codec, pfx, 3, true, path);
  1779. if (err < 0)
  1780. return err;
  1781. }
  1782. if (path != spec->out_path + i)
  1783. copy_path_mixer_ctls(&spec->out_path[i], path);
  1784. if (path == spec->out_path && spec->out_mix_path.depth)
  1785. copy_path_mixer_ctls(&spec->out_mix_path, path);
  1786. }
  1787. idx = get_connection_index(codec, spec->aa_mix_nid,
  1788. spec->multiout.dac_nids[0]);
  1789. if (idx >= 0) {
  1790. /* add control to mixer */
  1791. const char *name;
  1792. name = spec->out_mix_path.depth ?
  1793. "PCM Loopback Playback Volume" : "PCM Playback Volume";
  1794. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1795. HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
  1796. idx, HDA_INPUT));
  1797. if (err < 0)
  1798. return err;
  1799. name = spec->out_mix_path.depth ?
  1800. "PCM Loopback Playback Switch" : "PCM Playback Switch";
  1801. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1802. HDA_COMPOSE_AMP_VAL(spec->aa_mix_nid, 3,
  1803. idx, HDA_INPUT));
  1804. if (err < 0)
  1805. return err;
  1806. }
  1807. cfg->line_outs = old_line_outs;
  1808. return 0;
  1809. }
  1810. static int via_auto_create_hp_ctls(struct hda_codec *codec, hda_nid_t pin)
  1811. {
  1812. struct via_spec *spec = codec->spec;
  1813. struct nid_path *path;
  1814. bool check_dac;
  1815. int i, err;
  1816. if (!pin)
  1817. return 0;
  1818. if (!parse_output_path(codec, pin, 0, 0, &spec->hp_indep_path)) {
  1819. for (i = HDA_SIDE; i >= HDA_CLFE; i--) {
  1820. if (i < spec->multiout.num_dacs &&
  1821. parse_output_path(codec, pin,
  1822. spec->multiout.dac_nids[i], 0,
  1823. &spec->hp_indep_path)) {
  1824. spec->hp_indep_shared = i;
  1825. break;
  1826. }
  1827. }
  1828. }
  1829. if (spec->hp_indep_path.depth) {
  1830. spec->hp_dac_nid = spec->hp_indep_path.path[0];
  1831. if (!spec->hp_indep_shared)
  1832. spec->hp_path = spec->hp_indep_path;
  1833. }
  1834. /* optionally check front-path w/o AA-mix */
  1835. if (!spec->hp_path.depth)
  1836. parse_output_path(codec, pin,
  1837. spec->multiout.dac_nids[HDA_FRONT], 0,
  1838. &spec->hp_path);
  1839. if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
  1840. 1, &spec->hp_mix_path) && !spec->hp_path.depth)
  1841. return 0;
  1842. if (spec->hp_path.depth) {
  1843. path = &spec->hp_path;
  1844. check_dac = true;
  1845. } else {
  1846. path = &spec->hp_mix_path;
  1847. check_dac = false;
  1848. }
  1849. err = create_ch_ctls(codec, "Headphone", 3, check_dac, path);
  1850. if (err < 0)
  1851. return err;
  1852. if (check_dac)
  1853. copy_path_mixer_ctls(&spec->hp_mix_path, path);
  1854. else
  1855. copy_path_mixer_ctls(&spec->hp_path, path);
  1856. if (spec->hp_indep_path.depth)
  1857. copy_path_mixer_ctls(&spec->hp_indep_path, path);
  1858. return 0;
  1859. }
  1860. static int via_auto_create_speaker_ctls(struct hda_codec *codec)
  1861. {
  1862. struct via_spec *spec = codec->spec;
  1863. struct nid_path *path;
  1864. bool check_dac;
  1865. hda_nid_t pin, dac = 0;
  1866. int err;
  1867. pin = spec->autocfg.speaker_pins[0];
  1868. if (!spec->autocfg.speaker_outs || !pin)
  1869. return 0;
  1870. if (parse_output_path(codec, pin, 0, 0, &spec->speaker_path))
  1871. dac = spec->speaker_path.path[0];
  1872. if (!dac)
  1873. parse_output_path(codec, pin,
  1874. spec->multiout.dac_nids[HDA_FRONT], 0,
  1875. &spec->speaker_path);
  1876. if (!parse_output_path(codec, pin, spec->multiout.dac_nids[HDA_FRONT],
  1877. 1, &spec->speaker_mix_path) && !dac)
  1878. return 0;
  1879. /* no AA-path for front? */
  1880. if (!spec->out_mix_path.depth && spec->speaker_mix_path.depth)
  1881. dac = 0;
  1882. spec->speaker_dac_nid = dac;
  1883. spec->multiout.extra_out_nid[0] = dac;
  1884. if (dac) {
  1885. path = &spec->speaker_path;
  1886. check_dac = true;
  1887. } else {
  1888. path = &spec->speaker_mix_path;
  1889. check_dac = false;
  1890. }
  1891. err = create_ch_ctls(codec, "Speaker", 3, check_dac, path);
  1892. if (err < 0)
  1893. return err;
  1894. if (check_dac)
  1895. copy_path_mixer_ctls(&spec->speaker_mix_path, path);
  1896. else
  1897. copy_path_mixer_ctls(&spec->speaker_path, path);
  1898. return 0;
  1899. }
  1900. #define via_aamix_ctl_info via_pin_power_ctl_info
  1901. static int via_aamix_ctl_get(struct snd_kcontrol *kcontrol,
  1902. struct snd_ctl_elem_value *ucontrol)
  1903. {
  1904. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1905. struct via_spec *spec = codec->spec;
  1906. ucontrol->value.enumerated.item[0] = spec->aamix_mode;
  1907. return 0;
  1908. }
  1909. static void update_aamix_paths(struct hda_codec *codec, int do_mix,
  1910. struct nid_path *nomix, struct nid_path *mix)
  1911. {
  1912. if (do_mix) {
  1913. activate_output_path(codec, nomix, false, false);
  1914. activate_output_path(codec, mix, true, false);
  1915. } else {
  1916. activate_output_path(codec, mix, false, false);
  1917. activate_output_path(codec, nomix, true, false);
  1918. }
  1919. }
  1920. static int via_aamix_ctl_put(struct snd_kcontrol *kcontrol,
  1921. struct snd_ctl_elem_value *ucontrol)
  1922. {
  1923. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1924. struct via_spec *spec = codec->spec;
  1925. unsigned int val = ucontrol->value.enumerated.item[0];
  1926. if (val == spec->aamix_mode)
  1927. return 0;
  1928. spec->aamix_mode = val;
  1929. /* update front path */
  1930. update_aamix_paths(codec, val, &spec->out_path[0], &spec->out_mix_path);
  1931. /* update HP path */
  1932. if (!spec->hp_independent_mode) {
  1933. update_aamix_paths(codec, val, &spec->hp_path,
  1934. &spec->hp_mix_path);
  1935. }
  1936. /* update speaker path */
  1937. update_aamix_paths(codec, val, &spec->speaker_path,
  1938. &spec->speaker_mix_path);
  1939. return 1;
  1940. }
  1941. static const struct snd_kcontrol_new via_aamix_ctl_enum = {
  1942. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1943. .name = "Loopback Mixing",
  1944. .info = via_aamix_ctl_info,
  1945. .get = via_aamix_ctl_get,
  1946. .put = via_aamix_ctl_put,
  1947. };
  1948. static int via_auto_create_loopback_switch(struct hda_codec *codec)
  1949. {
  1950. struct via_spec *spec = codec->spec;
  1951. if (!spec->aa_mix_nid || !spec->out_mix_path.depth)
  1952. return 0; /* no loopback switching available */
  1953. if (!via_clone_control(spec, &via_aamix_ctl_enum))
  1954. return -ENOMEM;
  1955. return 0;
  1956. }
  1957. /* look for ADCs */
  1958. static int via_fill_adcs(struct hda_codec *codec)
  1959. {
  1960. struct via_spec *spec = codec->spec;
  1961. hda_nid_t nid = codec->start_nid;
  1962. int i;
  1963. for (i = 0; i < codec->num_nodes; i++, nid++) {
  1964. unsigned int wcaps = get_wcaps(codec, nid);
  1965. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  1966. continue;
  1967. if (wcaps & AC_WCAP_DIGITAL)
  1968. continue;
  1969. if (!(wcaps & AC_WCAP_CONN_LIST))
  1970. continue;
  1971. if (spec->num_adc_nids >= ARRAY_SIZE(spec->adc_nids))
  1972. return -ENOMEM;
  1973. spec->adc_nids[spec->num_adc_nids++] = nid;
  1974. }
  1975. return 0;
  1976. }
  1977. /* input-src control */
  1978. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  1979. struct snd_ctl_elem_info *uinfo)
  1980. {
  1981. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1982. struct via_spec *spec = codec->spec;
  1983. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1984. uinfo->count = 1;
  1985. uinfo->value.enumerated.items = spec->num_inputs;
  1986. if (uinfo->value.enumerated.item >= spec->num_inputs)
  1987. uinfo->value.enumerated.item = spec->num_inputs - 1;
  1988. strcpy(uinfo->value.enumerated.name,
  1989. spec->inputs[uinfo->value.enumerated.item].label);
  1990. return 0;
  1991. }
  1992. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  1993. struct snd_ctl_elem_value *ucontrol)
  1994. {
  1995. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1996. struct via_spec *spec = codec->spec;
  1997. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1998. ucontrol->value.enumerated.item[0] = spec->cur_mux[idx];
  1999. return 0;
  2000. }
  2001. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  2002. struct snd_ctl_elem_value *ucontrol)
  2003. {
  2004. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2005. struct via_spec *spec = codec->spec;
  2006. unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  2007. hda_nid_t mux;
  2008. int cur;
  2009. cur = ucontrol->value.enumerated.item[0];
  2010. if (cur < 0 || cur >= spec->num_inputs)
  2011. return -EINVAL;
  2012. if (spec->cur_mux[idx] == cur)
  2013. return 0;
  2014. spec->cur_mux[idx] = cur;
  2015. if (spec->dyn_adc_switch) {
  2016. int adc_idx = spec->inputs[cur].adc_idx;
  2017. mux = spec->mux_nids[adc_idx];
  2018. via_dyn_adc_pcm_resetup(codec, cur);
  2019. } else {
  2020. mux = spec->mux_nids[idx];
  2021. if (snd_BUG_ON(!mux))
  2022. return -EINVAL;
  2023. }
  2024. if (mux) {
  2025. /* switch to D0 beofre change index */
  2026. if (snd_hda_codec_read(codec, mux, 0,
  2027. AC_VERB_GET_POWER_STATE, 0x00) != AC_PWRST_D0)
  2028. snd_hda_codec_write(codec, mux, 0,
  2029. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  2030. snd_hda_codec_write(codec, mux, 0,
  2031. AC_VERB_SET_CONNECT_SEL,
  2032. spec->inputs[cur].mux_idx);
  2033. }
  2034. /* update jack power state */
  2035. set_widgets_power_state(codec);
  2036. return 0;
  2037. }
  2038. static const struct snd_kcontrol_new via_input_src_ctl = {
  2039. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2040. /* The multiple "Capture Source" controls confuse alsamixer
  2041. * So call somewhat different..
  2042. */
  2043. /* .name = "Capture Source", */
  2044. .name = "Input Source",
  2045. .info = via_mux_enum_info,
  2046. .get = via_mux_enum_get,
  2047. .put = via_mux_enum_put,
  2048. };
  2049. static int create_input_src_ctls(struct hda_codec *codec, int count)
  2050. {
  2051. struct via_spec *spec = codec->spec;
  2052. struct snd_kcontrol_new *knew;
  2053. if (spec->num_inputs <= 1 || !count)
  2054. return 0; /* no need for single src */
  2055. knew = via_clone_control(spec, &via_input_src_ctl);
  2056. if (!knew)
  2057. return -ENOMEM;
  2058. knew->count = count;
  2059. return 0;
  2060. }
  2061. /* add the powersave loopback-list entry */
  2062. static void add_loopback_list(struct via_spec *spec, hda_nid_t mix, int idx)
  2063. {
  2064. struct hda_amp_list *list;
  2065. if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
  2066. return;
  2067. list = spec->loopback_list + spec->num_loopbacks;
  2068. list->nid = mix;
  2069. list->dir = HDA_INPUT;
  2070. list->idx = idx;
  2071. spec->num_loopbacks++;
  2072. spec->loopback.amplist = spec->loopback_list;
  2073. }
  2074. static bool is_reachable_nid(struct hda_codec *codec, hda_nid_t src,
  2075. hda_nid_t dst)
  2076. {
  2077. return snd_hda_get_conn_index(codec, src, dst, 1) >= 0;
  2078. }
  2079. /* add the input-route to the given pin */
  2080. static bool add_input_route(struct hda_codec *codec, hda_nid_t pin)
  2081. {
  2082. struct via_spec *spec = codec->spec;
  2083. int c, idx;
  2084. spec->inputs[spec->num_inputs].adc_idx = -1;
  2085. spec->inputs[spec->num_inputs].pin = pin;
  2086. for (c = 0; c < spec->num_adc_nids; c++) {
  2087. if (spec->mux_nids[c]) {
  2088. idx = get_connection_index(codec, spec->mux_nids[c],
  2089. pin);
  2090. if (idx < 0)
  2091. continue;
  2092. spec->inputs[spec->num_inputs].mux_idx = idx;
  2093. } else {
  2094. if (!is_reachable_nid(codec, spec->adc_nids[c], pin))
  2095. continue;
  2096. }
  2097. spec->inputs[spec->num_inputs].adc_idx = c;
  2098. /* Can primary ADC satisfy all inputs? */
  2099. if (!spec->dyn_adc_switch &&
  2100. spec->num_inputs > 0 && spec->inputs[0].adc_idx != c) {
  2101. snd_printd(KERN_INFO
  2102. "via: dynamic ADC switching enabled\n");
  2103. spec->dyn_adc_switch = 1;
  2104. }
  2105. return true;
  2106. }
  2107. return false;
  2108. }
  2109. static int get_mux_nids(struct hda_codec *codec);
  2110. /* parse input-routes; fill ADCs, MUXs and input-src entries */
  2111. static int parse_analog_inputs(struct hda_codec *codec)
  2112. {
  2113. struct via_spec *spec = codec->spec;
  2114. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2115. int i, err;
  2116. err = via_fill_adcs(codec);
  2117. if (err < 0)
  2118. return err;
  2119. err = get_mux_nids(codec);
  2120. if (err < 0)
  2121. return err;
  2122. /* fill all input-routes */
  2123. for (i = 0; i < cfg->num_inputs; i++) {
  2124. if (add_input_route(codec, cfg->inputs[i].pin))
  2125. spec->inputs[spec->num_inputs++].label =
  2126. hda_get_autocfg_input_label(codec, cfg, i);
  2127. }
  2128. /* check for internal loopback recording */
  2129. if (spec->aa_mix_nid &&
  2130. add_input_route(codec, spec->aa_mix_nid))
  2131. spec->inputs[spec->num_inputs++].label = "Stereo Mixer";
  2132. return 0;
  2133. }
  2134. /* create analog-loopback volume/switch controls */
  2135. static int create_loopback_ctls(struct hda_codec *codec)
  2136. {
  2137. struct via_spec *spec = codec->spec;
  2138. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2139. const char *prev_label = NULL;
  2140. int type_idx = 0;
  2141. int i, j, err, idx;
  2142. if (!spec->aa_mix_nid)
  2143. return 0;
  2144. for (i = 0; i < cfg->num_inputs; i++) {
  2145. hda_nid_t pin = cfg->inputs[i].pin;
  2146. const char *label = hda_get_autocfg_input_label(codec, cfg, i);
  2147. if (prev_label && !strcmp(label, prev_label))
  2148. type_idx++;
  2149. else
  2150. type_idx = 0;
  2151. prev_label = label;
  2152. idx = get_connection_index(codec, spec->aa_mix_nid, pin);
  2153. if (idx >= 0) {
  2154. err = via_new_analog_input(spec, label, type_idx,
  2155. idx, spec->aa_mix_nid);
  2156. if (err < 0)
  2157. return err;
  2158. add_loopback_list(spec, spec->aa_mix_nid, idx);
  2159. }
  2160. /* remember the label for smart51 control */
  2161. for (j = 0; j < spec->smart51_nums; j++) {
  2162. if (spec->smart51_pins[j] == pin) {
  2163. spec->smart51_idxs[j] = idx;
  2164. spec->smart51_labels[j] = label;
  2165. break;
  2166. }
  2167. }
  2168. }
  2169. return 0;
  2170. }
  2171. /* create mic-boost controls (if present) */
  2172. static int create_mic_boost_ctls(struct hda_codec *codec)
  2173. {
  2174. struct via_spec *spec = codec->spec;
  2175. const struct auto_pin_cfg *cfg = &spec->autocfg;
  2176. int i, err;
  2177. for (i = 0; i < cfg->num_inputs; i++) {
  2178. hda_nid_t pin = cfg->inputs[i].pin;
  2179. unsigned int caps;
  2180. const char *label;
  2181. char name[32];
  2182. if (cfg->inputs[i].type != AUTO_PIN_MIC)
  2183. continue;
  2184. caps = query_amp_caps(codec, pin, HDA_INPUT);
  2185. if (caps == -1 || !(caps & AC_AMPCAP_NUM_STEPS))
  2186. continue;
  2187. label = hda_get_autocfg_input_label(codec, cfg, i);
  2188. snprintf(name, sizeof(name), "%s Boost Volume", label);
  2189. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2190. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_INPUT));
  2191. if (err < 0)
  2192. return err;
  2193. }
  2194. return 0;
  2195. }
  2196. /* create capture and input-src controls for multiple streams */
  2197. static int create_multi_adc_ctls(struct hda_codec *codec)
  2198. {
  2199. struct via_spec *spec = codec->spec;
  2200. int i, err;
  2201. /* create capture mixer elements */
  2202. for (i = 0; i < spec->num_adc_nids; i++) {
  2203. hda_nid_t adc = spec->adc_nids[i];
  2204. err = __via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2205. "Capture Volume", i,
  2206. HDA_COMPOSE_AMP_VAL(adc, 3, 0,
  2207. HDA_INPUT));
  2208. if (err < 0)
  2209. return err;
  2210. err = __via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2211. "Capture Switch", i,
  2212. HDA_COMPOSE_AMP_VAL(adc, 3, 0,
  2213. HDA_INPUT));
  2214. if (err < 0)
  2215. return err;
  2216. }
  2217. /* input-source control */
  2218. for (i = 0; i < spec->num_adc_nids; i++)
  2219. if (!spec->mux_nids[i])
  2220. break;
  2221. err = create_input_src_ctls(codec, i);
  2222. if (err < 0)
  2223. return err;
  2224. return 0;
  2225. }
  2226. /* bind capture volume/switch */
  2227. static struct snd_kcontrol_new via_bind_cap_vol_ctl =
  2228. HDA_BIND_VOL("Capture Volume", 0);
  2229. static struct snd_kcontrol_new via_bind_cap_sw_ctl =
  2230. HDA_BIND_SW("Capture Switch", 0);
  2231. static int init_bind_ctl(struct via_spec *spec, struct hda_bind_ctls **ctl_ret,
  2232. struct hda_ctl_ops *ops)
  2233. {
  2234. struct hda_bind_ctls *ctl;
  2235. int i;
  2236. ctl = kzalloc(sizeof(*ctl) + sizeof(long) * 4, GFP_KERNEL);
  2237. if (!ctl)
  2238. return -ENOMEM;
  2239. ctl->ops = ops;
  2240. for (i = 0; i < spec->num_adc_nids; i++)
  2241. ctl->values[i] =
  2242. HDA_COMPOSE_AMP_VAL(spec->adc_nids[i], 3, 0, HDA_INPUT);
  2243. *ctl_ret = ctl;
  2244. return 0;
  2245. }
  2246. /* create capture and input-src controls for dynamic ADC-switch case */
  2247. static int create_dyn_adc_ctls(struct hda_codec *codec)
  2248. {
  2249. struct via_spec *spec = codec->spec;
  2250. struct snd_kcontrol_new *knew;
  2251. int err;
  2252. /* set up the bind capture ctls */
  2253. err = init_bind_ctl(spec, &spec->bind_cap_vol, &snd_hda_bind_vol);
  2254. if (err < 0)
  2255. return err;
  2256. err = init_bind_ctl(spec, &spec->bind_cap_sw, &snd_hda_bind_sw);
  2257. if (err < 0)
  2258. return err;
  2259. /* create capture mixer elements */
  2260. knew = via_clone_control(spec, &via_bind_cap_vol_ctl);
  2261. if (!knew)
  2262. return -ENOMEM;
  2263. knew->private_value = (long)spec->bind_cap_vol;
  2264. knew = via_clone_control(spec, &via_bind_cap_sw_ctl);
  2265. if (!knew)
  2266. return -ENOMEM;
  2267. knew->private_value = (long)spec->bind_cap_sw;
  2268. /* input-source control */
  2269. err = create_input_src_ctls(codec, 1);
  2270. if (err < 0)
  2271. return err;
  2272. return 0;
  2273. }
  2274. /* parse and create capture-related stuff */
  2275. static int via_auto_create_analog_input_ctls(struct hda_codec *codec)
  2276. {
  2277. struct via_spec *spec = codec->spec;
  2278. int err;
  2279. err = parse_analog_inputs(codec);
  2280. if (err < 0)
  2281. return err;
  2282. if (spec->dyn_adc_switch)
  2283. err = create_dyn_adc_ctls(codec);
  2284. else
  2285. err = create_multi_adc_ctls(codec);
  2286. if (err < 0)
  2287. return err;
  2288. err = create_loopback_ctls(codec);
  2289. if (err < 0)
  2290. return err;
  2291. err = create_mic_boost_ctls(codec);
  2292. if (err < 0)
  2293. return err;
  2294. return 0;
  2295. }
  2296. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  2297. {
  2298. unsigned int def_conf;
  2299. unsigned char seqassoc;
  2300. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  2301. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  2302. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  2303. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE
  2304. && (seqassoc == 0xf0 || seqassoc == 0xff)) {
  2305. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  2306. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  2307. }
  2308. return;
  2309. }
  2310. static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
  2311. struct snd_ctl_elem_value *ucontrol)
  2312. {
  2313. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2314. struct via_spec *spec = codec->spec;
  2315. if (spec->codec_type != VT1708)
  2316. return 0;
  2317. spec->vt1708_jack_detect =
  2318. !((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
  2319. ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
  2320. return 0;
  2321. }
  2322. static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
  2323. struct snd_ctl_elem_value *ucontrol)
  2324. {
  2325. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2326. struct via_spec *spec = codec->spec;
  2327. int change;
  2328. if (spec->codec_type != VT1708)
  2329. return 0;
  2330. spec->vt1708_jack_detect = ucontrol->value.integer.value[0];
  2331. change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8))
  2332. == !spec->vt1708_jack_detect;
  2333. if (spec->vt1708_jack_detect) {
  2334. mute_aa_path(codec, 1);
  2335. notify_aa_path_ctls(codec);
  2336. }
  2337. return change;
  2338. }
  2339. static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
  2340. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2341. .name = "Jack Detect",
  2342. .count = 1,
  2343. .info = snd_ctl_boolean_mono_info,
  2344. .get = vt1708_jack_detect_get,
  2345. .put = vt1708_jack_detect_put,
  2346. };
  2347. static void fill_dig_outs(struct hda_codec *codec);
  2348. static void fill_dig_in(struct hda_codec *codec);
  2349. static int via_parse_auto_config(struct hda_codec *codec)
  2350. {
  2351. struct via_spec *spec = codec->spec;
  2352. int err;
  2353. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2354. if (err < 0)
  2355. return err;
  2356. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2357. return -EINVAL;
  2358. err = via_auto_create_multi_out_ctls(codec);
  2359. if (err < 0)
  2360. return err;
  2361. err = via_auto_create_hp_ctls(codec, spec->autocfg.hp_pins[0]);
  2362. if (err < 0)
  2363. return err;
  2364. err = via_auto_create_speaker_ctls(codec);
  2365. if (err < 0)
  2366. return err;
  2367. err = via_auto_create_loopback_switch(codec);
  2368. if (err < 0)
  2369. return err;
  2370. err = via_auto_create_analog_input_ctls(codec);
  2371. if (err < 0)
  2372. return err;
  2373. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2374. fill_dig_outs(codec);
  2375. fill_dig_in(codec);
  2376. if (spec->kctls.list)
  2377. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2378. if (spec->hp_dac_nid && spec->hp_mix_path.depth) {
  2379. err = via_hp_build(codec);
  2380. if (err < 0)
  2381. return err;
  2382. }
  2383. err = via_smart51_build(codec);
  2384. if (err < 0)
  2385. return err;
  2386. /* assign slave outs */
  2387. if (spec->slave_dig_outs[0])
  2388. codec->slave_dig_outs = spec->slave_dig_outs;
  2389. return 1;
  2390. }
  2391. static void via_auto_init_dig_outs(struct hda_codec *codec)
  2392. {
  2393. struct via_spec *spec = codec->spec;
  2394. if (spec->multiout.dig_out_nid)
  2395. init_output_pin(codec, spec->autocfg.dig_out_pins[0], PIN_OUT);
  2396. if (spec->slave_dig_outs[0])
  2397. init_output_pin(codec, spec->autocfg.dig_out_pins[1], PIN_OUT);
  2398. }
  2399. static void via_auto_init_dig_in(struct hda_codec *codec)
  2400. {
  2401. struct via_spec *spec = codec->spec;
  2402. if (!spec->dig_in_nid)
  2403. return;
  2404. snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
  2405. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  2406. }
  2407. /* initialize the unsolicited events */
  2408. static void via_auto_init_unsol_event(struct hda_codec *codec)
  2409. {
  2410. struct via_spec *spec = codec->spec;
  2411. struct auto_pin_cfg *cfg = &spec->autocfg;
  2412. unsigned int ev;
  2413. int i;
  2414. if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
  2415. snd_hda_codec_write(codec, cfg->hp_pins[0], 0,
  2416. AC_VERB_SET_UNSOLICITED_ENABLE,
  2417. AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
  2418. if (cfg->speaker_pins[0])
  2419. ev = VIA_LINE_EVENT;
  2420. else
  2421. ev = 0;
  2422. for (i = 0; i < cfg->line_outs; i++) {
  2423. if (cfg->line_out_pins[i] &&
  2424. is_jack_detectable(codec, cfg->line_out_pins[i]))
  2425. snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
  2426. AC_VERB_SET_UNSOLICITED_ENABLE,
  2427. AC_USRSP_EN | ev | VIA_JACK_EVENT);
  2428. }
  2429. for (i = 0; i < cfg->num_inputs; i++) {
  2430. if (is_jack_detectable(codec, cfg->inputs[i].pin))
  2431. snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
  2432. AC_VERB_SET_UNSOLICITED_ENABLE,
  2433. AC_USRSP_EN | VIA_JACK_EVENT);
  2434. }
  2435. }
  2436. static int via_init(struct hda_codec *codec)
  2437. {
  2438. struct via_spec *spec = codec->spec;
  2439. int i;
  2440. for (i = 0; i < spec->num_iverbs; i++)
  2441. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  2442. via_auto_init_multi_out(codec);
  2443. via_auto_init_hp_out(codec);
  2444. via_auto_init_speaker_out(codec);
  2445. via_auto_init_analog_input(codec);
  2446. via_auto_init_dig_outs(codec);
  2447. via_auto_init_dig_in(codec);
  2448. via_auto_init_unsol_event(codec);
  2449. via_hp_automute(codec);
  2450. return 0;
  2451. }
  2452. static void vt1708_update_hp_jack_state(struct work_struct *work)
  2453. {
  2454. struct via_spec *spec = container_of(work, struct via_spec,
  2455. vt1708_hp_work.work);
  2456. if (spec->codec_type != VT1708)
  2457. return;
  2458. /* if jack state toggled */
  2459. if (spec->vt1708_hp_present
  2460. != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
  2461. spec->vt1708_hp_present ^= 1;
  2462. via_hp_automute(spec->codec);
  2463. }
  2464. vt1708_start_hp_work(spec);
  2465. }
  2466. static int get_mux_nids(struct hda_codec *codec)
  2467. {
  2468. struct via_spec *spec = codec->spec;
  2469. hda_nid_t nid, conn[8];
  2470. unsigned int type;
  2471. int i, n;
  2472. for (i = 0; i < spec->num_adc_nids; i++) {
  2473. nid = spec->adc_nids[i];
  2474. while (nid) {
  2475. type = get_wcaps_type(get_wcaps(codec, nid));
  2476. if (type == AC_WID_PIN)
  2477. break;
  2478. n = snd_hda_get_connections(codec, nid, conn,
  2479. ARRAY_SIZE(conn));
  2480. if (n <= 0)
  2481. break;
  2482. if (n > 1) {
  2483. spec->mux_nids[i] = nid;
  2484. break;
  2485. }
  2486. nid = conn[0];
  2487. }
  2488. }
  2489. return 0;
  2490. }
  2491. static int patch_vt1708(struct hda_codec *codec)
  2492. {
  2493. struct via_spec *spec;
  2494. int err;
  2495. /* create a codec specific record */
  2496. spec = via_new_spec(codec);
  2497. if (spec == NULL)
  2498. return -ENOMEM;
  2499. spec->aa_mix_nid = 0x17;
  2500. /* Add HP and CD pin config connect bit re-config action */
  2501. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  2502. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  2503. /* automatic parse from the BIOS config */
  2504. err = via_parse_auto_config(codec);
  2505. if (err < 0) {
  2506. via_free(codec);
  2507. return err;
  2508. }
  2509. /* add jack detect on/off control */
  2510. if (!via_clone_control(spec, &vt1708_jack_detect_ctl))
  2511. return -ENOMEM;
  2512. /* disable 32bit format on VT1708 */
  2513. if (codec->vendor_id == 0x11061708)
  2514. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  2515. spec->init_verbs[spec->num_iverbs++] = vt1708_init_verbs;
  2516. codec->patch_ops = via_patch_ops;
  2517. INIT_DELAYED_WORK(&spec->vt1708_hp_work, vt1708_update_hp_jack_state);
  2518. return 0;
  2519. }
  2520. static int patch_vt1709(struct hda_codec *codec)
  2521. {
  2522. struct via_spec *spec;
  2523. int err;
  2524. /* create a codec specific record */
  2525. spec = via_new_spec(codec);
  2526. if (spec == NULL)
  2527. return -ENOMEM;
  2528. spec->aa_mix_nid = 0x18;
  2529. err = via_parse_auto_config(codec);
  2530. if (err < 0) {
  2531. via_free(codec);
  2532. return err;
  2533. }
  2534. codec->patch_ops = via_patch_ops;
  2535. return 0;
  2536. }
  2537. static void set_widgets_power_state_vt1708B(struct hda_codec *codec)
  2538. {
  2539. struct via_spec *spec = codec->spec;
  2540. int imux_is_smixer;
  2541. unsigned int parm;
  2542. int is_8ch = 0;
  2543. if ((spec->codec_type != VT1708B_4CH) &&
  2544. (codec->vendor_id != 0x11064397))
  2545. is_8ch = 1;
  2546. /* SW0 (17h) = stereo mixer */
  2547. imux_is_smixer =
  2548. (snd_hda_codec_read(codec, 0x17, 0, AC_VERB_GET_CONNECT_SEL, 0x00)
  2549. == ((spec->codec_type == VT1708S) ? 5 : 0));
  2550. /* inputs */
  2551. /* PW 1/2/5 (1ah/1bh/1eh) */
  2552. parm = AC_PWRST_D3;
  2553. set_pin_power_state(codec, 0x1a, &parm);
  2554. set_pin_power_state(codec, 0x1b, &parm);
  2555. set_pin_power_state(codec, 0x1e, &parm);
  2556. if (imux_is_smixer)
  2557. parm = AC_PWRST_D0;
  2558. /* SW0 (17h), AIW 0/1 (13h/14h) */
  2559. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
  2560. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
  2561. snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
  2562. /* outputs */
  2563. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  2564. parm = AC_PWRST_D3;
  2565. set_pin_power_state(codec, 0x19, &parm);
  2566. if (spec->smart51_enabled)
  2567. set_pin_power_state(codec, 0x1b, &parm);
  2568. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
  2569. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
  2570. /* PW6 (22h), SW2 (26h), AOW2 (24h) */
  2571. if (is_8ch) {
  2572. parm = AC_PWRST_D3;
  2573. set_pin_power_state(codec, 0x22, &parm);
  2574. if (spec->smart51_enabled)
  2575. set_pin_power_state(codec, 0x1a, &parm);
  2576. snd_hda_codec_write(codec, 0x26, 0,
  2577. AC_VERB_SET_POWER_STATE, parm);
  2578. snd_hda_codec_write(codec, 0x24, 0,
  2579. AC_VERB_SET_POWER_STATE, parm);
  2580. } else if (codec->vendor_id == 0x11064397) {
  2581. /* PW7(23h), SW2(27h), AOW2(25h) */
  2582. parm = AC_PWRST_D3;
  2583. set_pin_power_state(codec, 0x23, &parm);
  2584. if (spec->smart51_enabled)
  2585. set_pin_power_state(codec, 0x1a, &parm);
  2586. snd_hda_codec_write(codec, 0x27, 0,
  2587. AC_VERB_SET_POWER_STATE, parm);
  2588. snd_hda_codec_write(codec, 0x25, 0,
  2589. AC_VERB_SET_POWER_STATE, parm);
  2590. }
  2591. /* PW 3/4/7 (1ch/1dh/23h) */
  2592. parm = AC_PWRST_D3;
  2593. /* force to D0 for internal Speaker */
  2594. set_pin_power_state(codec, 0x1c, &parm);
  2595. set_pin_power_state(codec, 0x1d, &parm);
  2596. if (is_8ch)
  2597. set_pin_power_state(codec, 0x23, &parm);
  2598. /* MW0 (16h), Sw3 (27h), AOW 0/3 (10h/25h) */
  2599. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
  2600. imux_is_smixer ? AC_PWRST_D0 : parm);
  2601. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
  2602. if (is_8ch) {
  2603. snd_hda_codec_write(codec, 0x25, 0,
  2604. AC_VERB_SET_POWER_STATE, parm);
  2605. snd_hda_codec_write(codec, 0x27, 0,
  2606. AC_VERB_SET_POWER_STATE, parm);
  2607. } else if (codec->vendor_id == 0x11064397 && spec->hp_independent_mode)
  2608. snd_hda_codec_write(codec, 0x25, 0,
  2609. AC_VERB_SET_POWER_STATE, parm);
  2610. }
  2611. static int patch_vt1708S(struct hda_codec *codec);
  2612. static int patch_vt1708B(struct hda_codec *codec)
  2613. {
  2614. struct via_spec *spec;
  2615. int err;
  2616. if (get_codec_type(codec) == VT1708BCE)
  2617. return patch_vt1708S(codec);
  2618. /* create a codec specific record */
  2619. spec = via_new_spec(codec);
  2620. if (spec == NULL)
  2621. return -ENOMEM;
  2622. spec->aa_mix_nid = 0x16;
  2623. /* automatic parse from the BIOS config */
  2624. err = via_parse_auto_config(codec);
  2625. if (err < 0) {
  2626. via_free(codec);
  2627. return err;
  2628. }
  2629. codec->patch_ops = via_patch_ops;
  2630. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  2631. return 0;
  2632. }
  2633. /* Patch for VT1708S */
  2634. static const struct hda_verb vt1708S_init_verbs[] = {
  2635. /* Enable Mic Boost Volume backdoor */
  2636. {0x1, 0xf98, 0x1},
  2637. /* don't bybass mixer */
  2638. {0x1, 0xf88, 0xc0},
  2639. { }
  2640. };
  2641. /* fill out digital output widgets; one for master and one for slave outputs */
  2642. static void fill_dig_outs(struct hda_codec *codec)
  2643. {
  2644. struct via_spec *spec = codec->spec;
  2645. int i;
  2646. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  2647. hda_nid_t nid;
  2648. int conn;
  2649. nid = spec->autocfg.dig_out_pins[i];
  2650. if (!nid)
  2651. continue;
  2652. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  2653. if (conn < 1)
  2654. continue;
  2655. if (!spec->multiout.dig_out_nid)
  2656. spec->multiout.dig_out_nid = nid;
  2657. else {
  2658. spec->slave_dig_outs[0] = nid;
  2659. break; /* at most two dig outs */
  2660. }
  2661. }
  2662. }
  2663. static void fill_dig_in(struct hda_codec *codec)
  2664. {
  2665. struct via_spec *spec = codec->spec;
  2666. hda_nid_t dig_nid;
  2667. int i, err;
  2668. if (!spec->autocfg.dig_in_pin)
  2669. return;
  2670. dig_nid = codec->start_nid;
  2671. for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
  2672. unsigned int wcaps = get_wcaps(codec, dig_nid);
  2673. if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
  2674. continue;
  2675. if (!(wcaps & AC_WCAP_DIGITAL))
  2676. continue;
  2677. if (!(wcaps & AC_WCAP_CONN_LIST))
  2678. continue;
  2679. err = get_connection_index(codec, dig_nid,
  2680. spec->autocfg.dig_in_pin);
  2681. if (err >= 0) {
  2682. spec->dig_in_nid = dig_nid;
  2683. break;
  2684. }
  2685. }
  2686. }
  2687. static void override_mic_boost(struct hda_codec *codec, hda_nid_t pin,
  2688. int offset, int num_steps, int step_size)
  2689. {
  2690. snd_hda_override_amp_caps(codec, pin, HDA_INPUT,
  2691. (offset << AC_AMPCAP_OFFSET_SHIFT) |
  2692. (num_steps << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2693. (step_size << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2694. (0 << AC_AMPCAP_MUTE_SHIFT));
  2695. }
  2696. static int patch_vt1708S(struct hda_codec *codec)
  2697. {
  2698. struct via_spec *spec;
  2699. int err;
  2700. /* create a codec specific record */
  2701. spec = via_new_spec(codec);
  2702. if (spec == NULL)
  2703. return -ENOMEM;
  2704. spec->aa_mix_nid = 0x16;
  2705. override_mic_boost(codec, 0x1a, 0, 3, 40);
  2706. override_mic_boost(codec, 0x1e, 0, 3, 40);
  2707. /* automatic parse from the BIOS config */
  2708. err = via_parse_auto_config(codec);
  2709. if (err < 0) {
  2710. via_free(codec);
  2711. return err;
  2712. }
  2713. spec->init_verbs[spec->num_iverbs++] = vt1708S_init_verbs;
  2714. codec->patch_ops = via_patch_ops;
  2715. /* correct names for VT1708BCE */
  2716. if (get_codec_type(codec) == VT1708BCE) {
  2717. kfree(codec->chip_name);
  2718. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  2719. snprintf(codec->bus->card->mixername,
  2720. sizeof(codec->bus->card->mixername),
  2721. "%s %s", codec->vendor_name, codec->chip_name);
  2722. }
  2723. /* correct names for VT1705 */
  2724. if (codec->vendor_id == 0x11064397) {
  2725. kfree(codec->chip_name);
  2726. codec->chip_name = kstrdup("VT1705", GFP_KERNEL);
  2727. snprintf(codec->bus->card->mixername,
  2728. sizeof(codec->bus->card->mixername),
  2729. "%s %s", codec->vendor_name, codec->chip_name);
  2730. }
  2731. spec->set_widgets_power_state = set_widgets_power_state_vt1708B;
  2732. return 0;
  2733. }
  2734. /* Patch for VT1702 */
  2735. static const struct hda_verb vt1702_init_verbs[] = {
  2736. /* mixer enable */
  2737. {0x1, 0xF88, 0x3},
  2738. /* GPIO 0~2 */
  2739. {0x1, 0xF82, 0x3F},
  2740. { }
  2741. };
  2742. static void set_widgets_power_state_vt1702(struct hda_codec *codec)
  2743. {
  2744. int imux_is_smixer =
  2745. snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  2746. unsigned int parm;
  2747. /* inputs */
  2748. /* PW 1/2/5 (14h/15h/18h) */
  2749. parm = AC_PWRST_D3;
  2750. set_pin_power_state(codec, 0x14, &parm);
  2751. set_pin_power_state(codec, 0x15, &parm);
  2752. set_pin_power_state(codec, 0x18, &parm);
  2753. if (imux_is_smixer)
  2754. parm = AC_PWRST_D0; /* SW0 (13h) = stereo mixer (idx 3) */
  2755. /* SW0 (13h), AIW 0/1/2 (12h/1fh/20h) */
  2756. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
  2757. snd_hda_codec_write(codec, 0x12, 0, AC_VERB_SET_POWER_STATE, parm);
  2758. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
  2759. snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_POWER_STATE, parm);
  2760. /* outputs */
  2761. /* PW 3/4 (16h/17h) */
  2762. parm = AC_PWRST_D3;
  2763. set_pin_power_state(codec, 0x17, &parm);
  2764. set_pin_power_state(codec, 0x16, &parm);
  2765. /* MW0 (1ah), AOW 0/1 (10h/1dh) */
  2766. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE,
  2767. imux_is_smixer ? AC_PWRST_D0 : parm);
  2768. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
  2769. snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
  2770. }
  2771. static int patch_vt1702(struct hda_codec *codec)
  2772. {
  2773. struct via_spec *spec;
  2774. int err;
  2775. /* create a codec specific record */
  2776. spec = via_new_spec(codec);
  2777. if (spec == NULL)
  2778. return -ENOMEM;
  2779. spec->aa_mix_nid = 0x1a;
  2780. /* limit AA path volume to 0 dB */
  2781. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  2782. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2783. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2784. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2785. (1 << AC_AMPCAP_MUTE_SHIFT));
  2786. /* automatic parse from the BIOS config */
  2787. err = via_parse_auto_config(codec);
  2788. if (err < 0) {
  2789. via_free(codec);
  2790. return err;
  2791. }
  2792. spec->init_verbs[spec->num_iverbs++] = vt1702_init_verbs;
  2793. codec->patch_ops = via_patch_ops;
  2794. spec->set_widgets_power_state = set_widgets_power_state_vt1702;
  2795. return 0;
  2796. }
  2797. /* Patch for VT1718S */
  2798. static const struct hda_verb vt1718S_init_verbs[] = {
  2799. /* Enable MW0 adjust Gain 5 */
  2800. {0x1, 0xfb2, 0x10},
  2801. /* Enable Boost Volume backdoor */
  2802. {0x1, 0xf88, 0x8},
  2803. { }
  2804. };
  2805. static void set_widgets_power_state_vt1718S(struct hda_codec *codec)
  2806. {
  2807. struct via_spec *spec = codec->spec;
  2808. int imux_is_smixer;
  2809. unsigned int parm;
  2810. /* MUX6 (1eh) = stereo mixer */
  2811. imux_is_smixer =
  2812. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
  2813. /* inputs */
  2814. /* PW 5/6/7 (29h/2ah/2bh) */
  2815. parm = AC_PWRST_D3;
  2816. set_pin_power_state(codec, 0x29, &parm);
  2817. set_pin_power_state(codec, 0x2a, &parm);
  2818. set_pin_power_state(codec, 0x2b, &parm);
  2819. if (imux_is_smixer)
  2820. parm = AC_PWRST_D0;
  2821. /* MUX6/7 (1eh/1fh), AIW 0/1 (10h/11h) */
  2822. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
  2823. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
  2824. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
  2825. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
  2826. /* outputs */
  2827. /* PW3 (27h), MW2 (1ah), AOW3 (bh) */
  2828. parm = AC_PWRST_D3;
  2829. set_pin_power_state(codec, 0x27, &parm);
  2830. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_POWER_STATE, parm);
  2831. snd_hda_codec_write(codec, 0xb, 0, AC_VERB_SET_POWER_STATE, parm);
  2832. /* PW2 (26h), AOW2 (ah) */
  2833. parm = AC_PWRST_D3;
  2834. set_pin_power_state(codec, 0x26, &parm);
  2835. if (spec->smart51_enabled)
  2836. set_pin_power_state(codec, 0x2b, &parm);
  2837. snd_hda_codec_write(codec, 0xa, 0, AC_VERB_SET_POWER_STATE, parm);
  2838. /* PW0 (24h), AOW0 (8h) */
  2839. parm = AC_PWRST_D3;
  2840. set_pin_power_state(codec, 0x24, &parm);
  2841. if (!spec->hp_independent_mode) /* check for redirected HP */
  2842. set_pin_power_state(codec, 0x28, &parm);
  2843. snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
  2844. /* MW9 (21h), Mw2 (1ah), AOW0 (8h) */
  2845. snd_hda_codec_write(codec, 0x21, 0, AC_VERB_SET_POWER_STATE,
  2846. imux_is_smixer ? AC_PWRST_D0 : parm);
  2847. /* PW1 (25h), AOW1 (9h) */
  2848. parm = AC_PWRST_D3;
  2849. set_pin_power_state(codec, 0x25, &parm);
  2850. if (spec->smart51_enabled)
  2851. set_pin_power_state(codec, 0x2a, &parm);
  2852. snd_hda_codec_write(codec, 0x9, 0, AC_VERB_SET_POWER_STATE, parm);
  2853. if (spec->hp_independent_mode) {
  2854. /* PW4 (28h), MW3 (1bh), MUX1(34h), AOW4 (ch) */
  2855. parm = AC_PWRST_D3;
  2856. set_pin_power_state(codec, 0x28, &parm);
  2857. snd_hda_codec_write(codec, 0x1b, 0,
  2858. AC_VERB_SET_POWER_STATE, parm);
  2859. snd_hda_codec_write(codec, 0x34, 0,
  2860. AC_VERB_SET_POWER_STATE, parm);
  2861. snd_hda_codec_write(codec, 0xc, 0,
  2862. AC_VERB_SET_POWER_STATE, parm);
  2863. }
  2864. }
  2865. /* Add a connection to the primary DAC from AA-mixer for some codecs
  2866. * This isn't listed from the raw info, but the chip has a secret connection.
  2867. */
  2868. static int add_secret_dac_path(struct hda_codec *codec)
  2869. {
  2870. struct via_spec *spec = codec->spec;
  2871. int i, nums;
  2872. hda_nid_t conn[8];
  2873. hda_nid_t nid;
  2874. if (!spec->aa_mix_nid)
  2875. return 0;
  2876. nums = snd_hda_get_connections(codec, spec->aa_mix_nid, conn,
  2877. ARRAY_SIZE(conn) - 1);
  2878. for (i = 0; i < nums; i++) {
  2879. if (get_wcaps_type(get_wcaps(codec, conn[i])) == AC_WID_AUD_OUT)
  2880. return 0;
  2881. }
  2882. /* find the primary DAC and add to the connection list */
  2883. nid = codec->start_nid;
  2884. for (i = 0; i < codec->num_nodes; i++, nid++) {
  2885. unsigned int caps = get_wcaps(codec, nid);
  2886. if (get_wcaps_type(caps) == AC_WID_AUD_OUT &&
  2887. !(caps & AC_WCAP_DIGITAL)) {
  2888. conn[nums++] = nid;
  2889. return snd_hda_override_conn_list(codec,
  2890. spec->aa_mix_nid,
  2891. nums, conn);
  2892. }
  2893. }
  2894. return 0;
  2895. }
  2896. static int patch_vt1718S(struct hda_codec *codec)
  2897. {
  2898. struct via_spec *spec;
  2899. int err;
  2900. /* create a codec specific record */
  2901. spec = via_new_spec(codec);
  2902. if (spec == NULL)
  2903. return -ENOMEM;
  2904. spec->aa_mix_nid = 0x21;
  2905. override_mic_boost(codec, 0x2b, 0, 3, 40);
  2906. override_mic_boost(codec, 0x29, 0, 3, 40);
  2907. add_secret_dac_path(codec);
  2908. /* automatic parse from the BIOS config */
  2909. err = via_parse_auto_config(codec);
  2910. if (err < 0) {
  2911. via_free(codec);
  2912. return err;
  2913. }
  2914. spec->init_verbs[spec->num_iverbs++] = vt1718S_init_verbs;
  2915. codec->patch_ops = via_patch_ops;
  2916. spec->set_widgets_power_state = set_widgets_power_state_vt1718S;
  2917. return 0;
  2918. }
  2919. /* Patch for VT1716S */
  2920. static int vt1716s_dmic_info(struct snd_kcontrol *kcontrol,
  2921. struct snd_ctl_elem_info *uinfo)
  2922. {
  2923. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  2924. uinfo->count = 1;
  2925. uinfo->value.integer.min = 0;
  2926. uinfo->value.integer.max = 1;
  2927. return 0;
  2928. }
  2929. static int vt1716s_dmic_get(struct snd_kcontrol *kcontrol,
  2930. struct snd_ctl_elem_value *ucontrol)
  2931. {
  2932. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2933. int index = 0;
  2934. index = snd_hda_codec_read(codec, 0x26, 0,
  2935. AC_VERB_GET_CONNECT_SEL, 0);
  2936. if (index != -1)
  2937. *ucontrol->value.integer.value = index;
  2938. return 0;
  2939. }
  2940. static int vt1716s_dmic_put(struct snd_kcontrol *kcontrol,
  2941. struct snd_ctl_elem_value *ucontrol)
  2942. {
  2943. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2944. struct via_spec *spec = codec->spec;
  2945. int index = *ucontrol->value.integer.value;
  2946. snd_hda_codec_write(codec, 0x26, 0,
  2947. AC_VERB_SET_CONNECT_SEL, index);
  2948. spec->dmic_enabled = index;
  2949. set_widgets_power_state(codec);
  2950. return 1;
  2951. }
  2952. static const struct snd_kcontrol_new vt1716s_dmic_mixer[] = {
  2953. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x22, 0x0, HDA_INPUT),
  2954. {
  2955. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2956. .name = "Digital Mic Capture Switch",
  2957. .subdevice = HDA_SUBDEV_NID_FLAG | 0x26,
  2958. .count = 1,
  2959. .info = vt1716s_dmic_info,
  2960. .get = vt1716s_dmic_get,
  2961. .put = vt1716s_dmic_put,
  2962. },
  2963. {} /* end */
  2964. };
  2965. /* mono-out mixer elements */
  2966. static const struct snd_kcontrol_new vt1716S_mono_out_mixer[] = {
  2967. HDA_CODEC_MUTE("Mono Playback Switch", 0x2a, 0x0, HDA_OUTPUT),
  2968. { } /* end */
  2969. };
  2970. static const struct hda_verb vt1716S_init_verbs[] = {
  2971. /* Enable Boost Volume backdoor */
  2972. {0x1, 0xf8a, 0x80},
  2973. /* don't bybass mixer */
  2974. {0x1, 0xf88, 0xc0},
  2975. /* Enable mono output */
  2976. {0x1, 0xf90, 0x08},
  2977. { }
  2978. };
  2979. static void set_widgets_power_state_vt1716S(struct hda_codec *codec)
  2980. {
  2981. struct via_spec *spec = codec->spec;
  2982. int imux_is_smixer;
  2983. unsigned int parm;
  2984. unsigned int mono_out, present;
  2985. /* SW0 (17h) = stereo mixer */
  2986. imux_is_smixer =
  2987. (snd_hda_codec_read(codec, 0x17, 0,
  2988. AC_VERB_GET_CONNECT_SEL, 0x00) == 5);
  2989. /* inputs */
  2990. /* PW 1/2/5 (1ah/1bh/1eh) */
  2991. parm = AC_PWRST_D3;
  2992. set_pin_power_state(codec, 0x1a, &parm);
  2993. set_pin_power_state(codec, 0x1b, &parm);
  2994. set_pin_power_state(codec, 0x1e, &parm);
  2995. if (imux_is_smixer)
  2996. parm = AC_PWRST_D0;
  2997. /* SW0 (17h), AIW0(13h) */
  2998. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_POWER_STATE, parm);
  2999. snd_hda_codec_write(codec, 0x13, 0, AC_VERB_SET_POWER_STATE, parm);
  3000. parm = AC_PWRST_D3;
  3001. set_pin_power_state(codec, 0x1e, &parm);
  3002. /* PW11 (22h) */
  3003. if (spec->dmic_enabled)
  3004. set_pin_power_state(codec, 0x22, &parm);
  3005. else
  3006. snd_hda_codec_write(codec, 0x22, 0,
  3007. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3008. /* SW2(26h), AIW1(14h) */
  3009. snd_hda_codec_write(codec, 0x26, 0, AC_VERB_SET_POWER_STATE, parm);
  3010. snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_POWER_STATE, parm);
  3011. /* outputs */
  3012. /* PW0 (19h), SW1 (18h), AOW1 (11h) */
  3013. parm = AC_PWRST_D3;
  3014. set_pin_power_state(codec, 0x19, &parm);
  3015. /* Smart 5.1 PW2(1bh) */
  3016. if (spec->smart51_enabled)
  3017. set_pin_power_state(codec, 0x1b, &parm);
  3018. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
  3019. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
  3020. /* PW7 (23h), SW3 (27h), AOW3 (25h) */
  3021. parm = AC_PWRST_D3;
  3022. set_pin_power_state(codec, 0x23, &parm);
  3023. /* Smart 5.1 PW1(1ah) */
  3024. if (spec->smart51_enabled)
  3025. set_pin_power_state(codec, 0x1a, &parm);
  3026. snd_hda_codec_write(codec, 0x27, 0, AC_VERB_SET_POWER_STATE, parm);
  3027. /* Smart 5.1 PW5(1eh) */
  3028. if (spec->smart51_enabled)
  3029. set_pin_power_state(codec, 0x1e, &parm);
  3030. snd_hda_codec_write(codec, 0x25, 0, AC_VERB_SET_POWER_STATE, parm);
  3031. /* Mono out */
  3032. /* SW4(28h)->MW1(29h)-> PW12 (2ah)*/
  3033. present = snd_hda_jack_detect(codec, 0x1c);
  3034. if (present)
  3035. mono_out = 0;
  3036. else {
  3037. present = snd_hda_jack_detect(codec, 0x1d);
  3038. if (!spec->hp_independent_mode && present)
  3039. mono_out = 0;
  3040. else
  3041. mono_out = 1;
  3042. }
  3043. parm = mono_out ? AC_PWRST_D0 : AC_PWRST_D3;
  3044. snd_hda_codec_write(codec, 0x28, 0, AC_VERB_SET_POWER_STATE, parm);
  3045. snd_hda_codec_write(codec, 0x29, 0, AC_VERB_SET_POWER_STATE, parm);
  3046. snd_hda_codec_write(codec, 0x2a, 0, AC_VERB_SET_POWER_STATE, parm);
  3047. /* PW 3/4 (1ch/1dh) */
  3048. parm = AC_PWRST_D3;
  3049. set_pin_power_state(codec, 0x1c, &parm);
  3050. set_pin_power_state(codec, 0x1d, &parm);
  3051. /* HP Independent Mode, power on AOW3 */
  3052. if (spec->hp_independent_mode)
  3053. snd_hda_codec_write(codec, 0x25, 0,
  3054. AC_VERB_SET_POWER_STATE, parm);
  3055. /* force to D0 for internal Speaker */
  3056. /* MW0 (16h), AOW0 (10h) */
  3057. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_POWER_STATE,
  3058. imux_is_smixer ? AC_PWRST_D0 : parm);
  3059. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE,
  3060. mono_out ? AC_PWRST_D0 : parm);
  3061. }
  3062. static int patch_vt1716S(struct hda_codec *codec)
  3063. {
  3064. struct via_spec *spec;
  3065. int err;
  3066. /* create a codec specific record */
  3067. spec = via_new_spec(codec);
  3068. if (spec == NULL)
  3069. return -ENOMEM;
  3070. spec->aa_mix_nid = 0x16;
  3071. override_mic_boost(codec, 0x1a, 0, 3, 40);
  3072. override_mic_boost(codec, 0x1e, 0, 3, 40);
  3073. /* automatic parse from the BIOS config */
  3074. err = via_parse_auto_config(codec);
  3075. if (err < 0) {
  3076. via_free(codec);
  3077. return err;
  3078. }
  3079. spec->init_verbs[spec->num_iverbs++] = vt1716S_init_verbs;
  3080. spec->mixers[spec->num_mixers] = vt1716s_dmic_mixer;
  3081. spec->num_mixers++;
  3082. spec->mixers[spec->num_mixers++] = vt1716S_mono_out_mixer;
  3083. codec->patch_ops = via_patch_ops;
  3084. spec->set_widgets_power_state = set_widgets_power_state_vt1716S;
  3085. return 0;
  3086. }
  3087. /* for vt2002P */
  3088. static const struct hda_verb vt2002P_init_verbs[] = {
  3089. /* Class-D speaker related verbs */
  3090. {0x1, 0xfe0, 0x4},
  3091. {0x1, 0xfe9, 0x80},
  3092. {0x1, 0xfe2, 0x22},
  3093. /* Enable Boost Volume backdoor */
  3094. {0x1, 0xfb9, 0x24},
  3095. /* Enable AOW0 to MW9 */
  3096. {0x1, 0xfb8, 0x88},
  3097. { }
  3098. };
  3099. static const struct hda_verb vt1802_init_verbs[] = {
  3100. /* Enable Boost Volume backdoor */
  3101. {0x1, 0xfb9, 0x24},
  3102. /* Enable AOW0 to MW9 */
  3103. {0x1, 0xfb8, 0x88},
  3104. { }
  3105. };
  3106. static void set_widgets_power_state_vt2002P(struct hda_codec *codec)
  3107. {
  3108. struct via_spec *spec = codec->spec;
  3109. int imux_is_smixer;
  3110. unsigned int parm;
  3111. unsigned int present;
  3112. /* MUX9 (1eh) = stereo mixer */
  3113. imux_is_smixer =
  3114. snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
  3115. /* inputs */
  3116. /* PW 5/6/7 (29h/2ah/2bh) */
  3117. parm = AC_PWRST_D3;
  3118. set_pin_power_state(codec, 0x29, &parm);
  3119. set_pin_power_state(codec, 0x2a, &parm);
  3120. set_pin_power_state(codec, 0x2b, &parm);
  3121. parm = AC_PWRST_D0;
  3122. /* MUX9/10 (1eh/1fh), AIW 0/1 (10h/11h) */
  3123. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
  3124. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
  3125. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
  3126. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
  3127. /* outputs */
  3128. /* AOW0 (8h)*/
  3129. snd_hda_codec_write(codec, 0x8, 0, AC_VERB_SET_POWER_STATE, parm);
  3130. if (spec->codec_type == VT1802) {
  3131. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  3132. parm = AC_PWRST_D3;
  3133. set_pin_power_state(codec, 0x28, &parm);
  3134. snd_hda_codec_write(codec, 0x18, 0,
  3135. AC_VERB_SET_POWER_STATE, parm);
  3136. snd_hda_codec_write(codec, 0x38, 0,
  3137. AC_VERB_SET_POWER_STATE, parm);
  3138. } else {
  3139. /* PW4 (26h), MW4 (1ch), MUX4(37h) */
  3140. parm = AC_PWRST_D3;
  3141. set_pin_power_state(codec, 0x26, &parm);
  3142. snd_hda_codec_write(codec, 0x1c, 0,
  3143. AC_VERB_SET_POWER_STATE, parm);
  3144. snd_hda_codec_write(codec, 0x37, 0,
  3145. AC_VERB_SET_POWER_STATE, parm);
  3146. }
  3147. if (spec->codec_type == VT1802) {
  3148. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  3149. parm = AC_PWRST_D3;
  3150. set_pin_power_state(codec, 0x25, &parm);
  3151. snd_hda_codec_write(codec, 0x15, 0,
  3152. AC_VERB_SET_POWER_STATE, parm);
  3153. snd_hda_codec_write(codec, 0x35, 0,
  3154. AC_VERB_SET_POWER_STATE, parm);
  3155. } else {
  3156. /* PW1 (25h), MW1 (19h), MUX1(35h), AOW1 (9h) */
  3157. parm = AC_PWRST_D3;
  3158. set_pin_power_state(codec, 0x25, &parm);
  3159. snd_hda_codec_write(codec, 0x19, 0,
  3160. AC_VERB_SET_POWER_STATE, parm);
  3161. snd_hda_codec_write(codec, 0x35, 0,
  3162. AC_VERB_SET_POWER_STATE, parm);
  3163. }
  3164. if (spec->hp_independent_mode)
  3165. snd_hda_codec_write(codec, 0x9, 0,
  3166. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3167. /* Class-D */
  3168. /* PW0 (24h), MW0(18h/14h), MUX0(34h) */
  3169. present = snd_hda_jack_detect(codec, 0x25);
  3170. parm = AC_PWRST_D3;
  3171. set_pin_power_state(codec, 0x24, &parm);
  3172. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  3173. if (spec->codec_type == VT1802)
  3174. snd_hda_codec_write(codec, 0x14, 0,
  3175. AC_VERB_SET_POWER_STATE, parm);
  3176. else
  3177. snd_hda_codec_write(codec, 0x18, 0,
  3178. AC_VERB_SET_POWER_STATE, parm);
  3179. snd_hda_codec_write(codec, 0x34, 0, AC_VERB_SET_POWER_STATE, parm);
  3180. /* Mono Out */
  3181. present = snd_hda_jack_detect(codec, 0x26);
  3182. parm = present ? AC_PWRST_D3 : AC_PWRST_D0;
  3183. if (spec->codec_type == VT1802) {
  3184. /* PW15 (33h), MW8(1ch), MUX8(3ch) */
  3185. snd_hda_codec_write(codec, 0x33, 0,
  3186. AC_VERB_SET_POWER_STATE, parm);
  3187. snd_hda_codec_write(codec, 0x1c, 0,
  3188. AC_VERB_SET_POWER_STATE, parm);
  3189. snd_hda_codec_write(codec, 0x3c, 0,
  3190. AC_VERB_SET_POWER_STATE, parm);
  3191. } else {
  3192. /* PW15 (31h), MW8(17h), MUX8(3bh) */
  3193. snd_hda_codec_write(codec, 0x31, 0,
  3194. AC_VERB_SET_POWER_STATE, parm);
  3195. snd_hda_codec_write(codec, 0x17, 0,
  3196. AC_VERB_SET_POWER_STATE, parm);
  3197. snd_hda_codec_write(codec, 0x3b, 0,
  3198. AC_VERB_SET_POWER_STATE, parm);
  3199. }
  3200. /* MW9 (21h) */
  3201. if (imux_is_smixer || !is_aa_path_mute(codec))
  3202. snd_hda_codec_write(codec, 0x21, 0,
  3203. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3204. else
  3205. snd_hda_codec_write(codec, 0x21, 0,
  3206. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3207. }
  3208. /* patch for vt2002P */
  3209. static int patch_vt2002P(struct hda_codec *codec)
  3210. {
  3211. struct via_spec *spec;
  3212. int err;
  3213. /* create a codec specific record */
  3214. spec = via_new_spec(codec);
  3215. if (spec == NULL)
  3216. return -ENOMEM;
  3217. spec->aa_mix_nid = 0x21;
  3218. override_mic_boost(codec, 0x2b, 0, 3, 40);
  3219. override_mic_boost(codec, 0x29, 0, 3, 40);
  3220. add_secret_dac_path(codec);
  3221. /* automatic parse from the BIOS config */
  3222. err = via_parse_auto_config(codec);
  3223. if (err < 0) {
  3224. via_free(codec);
  3225. return err;
  3226. }
  3227. if (spec->codec_type == VT1802)
  3228. spec->init_verbs[spec->num_iverbs++] = vt1802_init_verbs;
  3229. else
  3230. spec->init_verbs[spec->num_iverbs++] = vt2002P_init_verbs;
  3231. codec->patch_ops = via_patch_ops;
  3232. spec->set_widgets_power_state = set_widgets_power_state_vt2002P;
  3233. return 0;
  3234. }
  3235. /* for vt1812 */
  3236. static const struct hda_verb vt1812_init_verbs[] = {
  3237. /* Enable Boost Volume backdoor */
  3238. {0x1, 0xfb9, 0x24},
  3239. /* Enable AOW0 to MW9 */
  3240. {0x1, 0xfb8, 0xa8},
  3241. { }
  3242. };
  3243. static void set_widgets_power_state_vt1812(struct hda_codec *codec)
  3244. {
  3245. struct via_spec *spec = codec->spec;
  3246. unsigned int parm;
  3247. unsigned int present;
  3248. /* inputs */
  3249. /* PW 5/6/7 (29h/2ah/2bh) */
  3250. parm = AC_PWRST_D3;
  3251. set_pin_power_state(codec, 0x29, &parm);
  3252. set_pin_power_state(codec, 0x2a, &parm);
  3253. set_pin_power_state(codec, 0x2b, &parm);
  3254. parm = AC_PWRST_D0;
  3255. /* MUX10/11 (1eh/1fh), AIW 0/1 (10h/11h) */
  3256. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_POWER_STATE, parm);
  3257. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_POWER_STATE, parm);
  3258. snd_hda_codec_write(codec, 0x10, 0, AC_VERB_SET_POWER_STATE, parm);
  3259. snd_hda_codec_write(codec, 0x11, 0, AC_VERB_SET_POWER_STATE, parm);
  3260. /* outputs */
  3261. /* AOW0 (8h)*/
  3262. snd_hda_codec_write(codec, 0x8, 0,
  3263. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3264. /* PW4 (28h), MW4 (18h), MUX4(38h) */
  3265. parm = AC_PWRST_D3;
  3266. set_pin_power_state(codec, 0x28, &parm);
  3267. snd_hda_codec_write(codec, 0x18, 0, AC_VERB_SET_POWER_STATE, parm);
  3268. snd_hda_codec_write(codec, 0x38, 0, AC_VERB_SET_POWER_STATE, parm);
  3269. /* PW1 (25h), MW1 (15h), MUX1(35h), AOW1 (9h) */
  3270. parm = AC_PWRST_D3;
  3271. set_pin_power_state(codec, 0x25, &parm);
  3272. snd_hda_codec_write(codec, 0x15, 0, AC_VERB_SET_POWER_STATE, parm);
  3273. snd_hda_codec_write(codec, 0x35, 0, AC_VERB_SET_POWER_STATE, parm);
  3274. if (spec->hp_independent_mode)
  3275. snd_hda_codec_write(codec, 0x9, 0,
  3276. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3277. /* Internal Speaker */
  3278. /* PW0 (24h), MW0(14h), MUX0(34h) */
  3279. present = snd_hda_jack_detect(codec, 0x25);
  3280. parm = AC_PWRST_D3;
  3281. set_pin_power_state(codec, 0x24, &parm);
  3282. if (present) {
  3283. snd_hda_codec_write(codec, 0x14, 0,
  3284. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3285. snd_hda_codec_write(codec, 0x34, 0,
  3286. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3287. } else {
  3288. snd_hda_codec_write(codec, 0x14, 0,
  3289. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3290. snd_hda_codec_write(codec, 0x34, 0,
  3291. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3292. }
  3293. /* Mono Out */
  3294. /* PW13 (31h), MW13(1ch), MUX13(3ch), MW14(3eh) */
  3295. present = snd_hda_jack_detect(codec, 0x28);
  3296. parm = AC_PWRST_D3;
  3297. set_pin_power_state(codec, 0x31, &parm);
  3298. if (present) {
  3299. snd_hda_codec_write(codec, 0x1c, 0,
  3300. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3301. snd_hda_codec_write(codec, 0x3c, 0,
  3302. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3303. snd_hda_codec_write(codec, 0x3e, 0,
  3304. AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
  3305. } else {
  3306. snd_hda_codec_write(codec, 0x1c, 0,
  3307. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3308. snd_hda_codec_write(codec, 0x3c, 0,
  3309. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3310. snd_hda_codec_write(codec, 0x3e, 0,
  3311. AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  3312. }
  3313. /* PW15 (33h), MW15 (1dh), MUX15(3dh) */
  3314. parm = AC_PWRST_D3;
  3315. set_pin_power_state(codec, 0x33, &parm);
  3316. snd_hda_codec_write(codec, 0x1d, 0, AC_VERB_SET_POWER_STATE, parm);
  3317. snd_hda_codec_write(codec, 0x3d, 0, AC_VERB_SET_POWER_STATE, parm);
  3318. }
  3319. /* patch for vt1812 */
  3320. static int patch_vt1812(struct hda_codec *codec)
  3321. {
  3322. struct via_spec *spec;
  3323. int err;
  3324. /* create a codec specific record */
  3325. spec = via_new_spec(codec);
  3326. if (spec == NULL)
  3327. return -ENOMEM;
  3328. spec->aa_mix_nid = 0x21;
  3329. override_mic_boost(codec, 0x2b, 0, 3, 40);
  3330. override_mic_boost(codec, 0x29, 0, 3, 40);
  3331. add_secret_dac_path(codec);
  3332. /* automatic parse from the BIOS config */
  3333. err = via_parse_auto_config(codec);
  3334. if (err < 0) {
  3335. via_free(codec);
  3336. return err;
  3337. }
  3338. spec->init_verbs[spec->num_iverbs++] = vt1812_init_verbs;
  3339. codec->patch_ops = via_patch_ops;
  3340. spec->set_widgets_power_state = set_widgets_power_state_vt1812;
  3341. return 0;
  3342. }
  3343. /*
  3344. * patch entries
  3345. */
  3346. static const struct hda_codec_preset snd_hda_preset_via[] = {
  3347. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  3348. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  3349. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  3350. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  3351. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  3352. .patch = patch_vt1709},
  3353. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  3354. .patch = patch_vt1709},
  3355. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  3356. .patch = patch_vt1709},
  3357. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  3358. .patch = patch_vt1709},
  3359. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  3360. .patch = patch_vt1709},
  3361. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  3362. .patch = patch_vt1709},
  3363. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  3364. .patch = patch_vt1709},
  3365. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  3366. .patch = patch_vt1709},
  3367. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  3368. .patch = patch_vt1708B},
  3369. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  3370. .patch = patch_vt1708B},
  3371. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  3372. .patch = patch_vt1708B},
  3373. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  3374. .patch = patch_vt1708B},
  3375. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  3376. .patch = patch_vt1708B},
  3377. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  3378. .patch = patch_vt1708B},
  3379. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  3380. .patch = patch_vt1708B},
  3381. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  3382. .patch = patch_vt1708B},
  3383. { .id = 0x11060397, .name = "VT1708S",
  3384. .patch = patch_vt1708S},
  3385. { .id = 0x11061397, .name = "VT1708S",
  3386. .patch = patch_vt1708S},
  3387. { .id = 0x11062397, .name = "VT1708S",
  3388. .patch = patch_vt1708S},
  3389. { .id = 0x11063397, .name = "VT1708S",
  3390. .patch = patch_vt1708S},
  3391. { .id = 0x11064397, .name = "VT1705",
  3392. .patch = patch_vt1708S},
  3393. { .id = 0x11065397, .name = "VT1708S",
  3394. .patch = patch_vt1708S},
  3395. { .id = 0x11066397, .name = "VT1708S",
  3396. .patch = patch_vt1708S},
  3397. { .id = 0x11067397, .name = "VT1708S",
  3398. .patch = patch_vt1708S},
  3399. { .id = 0x11060398, .name = "VT1702",
  3400. .patch = patch_vt1702},
  3401. { .id = 0x11061398, .name = "VT1702",
  3402. .patch = patch_vt1702},
  3403. { .id = 0x11062398, .name = "VT1702",
  3404. .patch = patch_vt1702},
  3405. { .id = 0x11063398, .name = "VT1702",
  3406. .patch = patch_vt1702},
  3407. { .id = 0x11064398, .name = "VT1702",
  3408. .patch = patch_vt1702},
  3409. { .id = 0x11065398, .name = "VT1702",
  3410. .patch = patch_vt1702},
  3411. { .id = 0x11066398, .name = "VT1702",
  3412. .patch = patch_vt1702},
  3413. { .id = 0x11067398, .name = "VT1702",
  3414. .patch = patch_vt1702},
  3415. { .id = 0x11060428, .name = "VT1718S",
  3416. .patch = patch_vt1718S},
  3417. { .id = 0x11064428, .name = "VT1718S",
  3418. .patch = patch_vt1718S},
  3419. { .id = 0x11060441, .name = "VT2020",
  3420. .patch = patch_vt1718S},
  3421. { .id = 0x11064441, .name = "VT1828S",
  3422. .patch = patch_vt1718S},
  3423. { .id = 0x11060433, .name = "VT1716S",
  3424. .patch = patch_vt1716S},
  3425. { .id = 0x1106a721, .name = "VT1716S",
  3426. .patch = patch_vt1716S},
  3427. { .id = 0x11060438, .name = "VT2002P", .patch = patch_vt2002P},
  3428. { .id = 0x11064438, .name = "VT2002P", .patch = patch_vt2002P},
  3429. { .id = 0x11060448, .name = "VT1812", .patch = patch_vt1812},
  3430. { .id = 0x11060440, .name = "VT1818S",
  3431. .patch = patch_vt1708S},
  3432. { .id = 0x11060446, .name = "VT1802",
  3433. .patch = patch_vt2002P},
  3434. { .id = 0x11068446, .name = "VT1802",
  3435. .patch = patch_vt2002P},
  3436. {} /* terminator */
  3437. };
  3438. MODULE_ALIAS("snd-hda-codec-id:1106*");
  3439. static struct hda_codec_preset_list via_list = {
  3440. .preset = snd_hda_preset_via,
  3441. .owner = THIS_MODULE,
  3442. };
  3443. MODULE_LICENSE("GPL");
  3444. MODULE_DESCRIPTION("VIA HD-audio codec");
  3445. static int __init patch_via_init(void)
  3446. {
  3447. return snd_hda_add_codec_preset(&via_list);
  3448. }
  3449. static void __exit patch_via_exit(void)
  3450. {
  3451. snd_hda_delete_codec_preset(&via_list);
  3452. }
  3453. module_init(patch_via_init)
  3454. module_exit(patch_via_exit)