patch_via.c 105 KB

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