patch_via.c 107 KB

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