patch_via.c 90 KB

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