patch_via.c 105 KB

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