patch_via.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for VIA VT1702/VT1708/VT1709 codec
  5. *
  6. * Copyright (c) 2006-2008 Lydia Wang <lydiawang@viatech.com>
  7. * 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. /* */
  39. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  40. #include <linux/init.h>
  41. #include <linux/delay.h>
  42. #include <linux/slab.h>
  43. #include <sound/core.h>
  44. #include <sound/asoundef.h>
  45. #include "hda_codec.h"
  46. #include "hda_local.h"
  47. /* amp values */
  48. #define AMP_VAL_IDX_SHIFT 19
  49. #define AMP_VAL_IDX_MASK (0x0f<<19)
  50. /* Pin Widget NID */
  51. #define VT1708_HP_NID 0x13
  52. #define VT1708_DIGOUT_NID 0x14
  53. #define VT1708_DIGIN_NID 0x16
  54. #define VT1708_DIGIN_PIN 0x26
  55. #define VT1708_HP_PIN_NID 0x20
  56. #define VT1708_CD_PIN_NID 0x24
  57. #define VT1709_HP_DAC_NID 0x28
  58. #define VT1709_DIGOUT_NID 0x13
  59. #define VT1709_DIGIN_NID 0x17
  60. #define VT1709_DIGIN_PIN 0x25
  61. #define VT1708B_HP_NID 0x25
  62. #define VT1708B_DIGOUT_NID 0x12
  63. #define VT1708B_DIGIN_NID 0x15
  64. #define VT1708B_DIGIN_PIN 0x21
  65. #define VT1708S_HP_NID 0x25
  66. #define VT1708S_DIGOUT_NID 0x12
  67. #define VT1702_HP_NID 0x17
  68. #define VT1702_DIGOUT_NID 0x11
  69. #define IS_VT1708_VENDORID(x) ((x) >= 0x11061708 && (x) <= 0x1106170b)
  70. #define IS_VT1709_10CH_VENDORID(x) ((x) >= 0x1106e710 && (x) <= 0x1106e713)
  71. #define IS_VT1709_6CH_VENDORID(x) ((x) >= 0x1106e714 && (x) <= 0x1106e717)
  72. #define IS_VT1708B_8CH_VENDORID(x) ((x) >= 0x1106e720 && (x) <= 0x1106e723)
  73. #define IS_VT1708B_4CH_VENDORID(x) ((x) >= 0x1106e724 && (x) <= 0x1106e727)
  74. #define IS_VT1708S_VENDORID(x) ((x) >= 0x11060397 && (x) <= 0x11067397)
  75. #define IS_VT1702_VENDORID(x) ((x) >= 0x11060398 && (x) <= 0x11067398)
  76. enum VIA_HDA_CODEC {
  77. UNKNOWN = -1,
  78. VT1708,
  79. VT1709_10CH,
  80. VT1709_6CH,
  81. VT1708B_8CH,
  82. VT1708B_4CH,
  83. VT1708S,
  84. VT1702,
  85. CODEC_TYPES,
  86. };
  87. static enum VIA_HDA_CODEC get_codec_type(u32 vendor_id)
  88. {
  89. u16 ven_id = vendor_id >> 16;
  90. u16 dev_id = vendor_id & 0xffff;
  91. enum VIA_HDA_CODEC codec_type;
  92. /* get codec type */
  93. if (ven_id != 0x1106)
  94. codec_type = UNKNOWN;
  95. else if (dev_id >= 0x1708 && dev_id <= 0x170b)
  96. codec_type = VT1708;
  97. else if (dev_id >= 0xe710 && dev_id <= 0xe713)
  98. codec_type = VT1709_10CH;
  99. else if (dev_id >= 0xe714 && dev_id <= 0xe717)
  100. codec_type = VT1709_6CH;
  101. else if (dev_id >= 0xe720 && dev_id <= 0xe723)
  102. codec_type = VT1708B_8CH;
  103. else if (dev_id >= 0xe724 && dev_id <= 0xe727)
  104. codec_type = VT1708B_4CH;
  105. else if ((dev_id & 0xfff) == 0x397
  106. && (dev_id >> 12) < 8)
  107. codec_type = VT1708S;
  108. else if ((dev_id & 0xfff) == 0x398
  109. && (dev_id >> 12) < 8)
  110. codec_type = VT1702;
  111. else
  112. codec_type = UNKNOWN;
  113. return codec_type;
  114. };
  115. #define VIA_HP_EVENT 0x01
  116. #define VIA_GPIO_EVENT 0x02
  117. enum {
  118. VIA_CTL_WIDGET_VOL,
  119. VIA_CTL_WIDGET_MUTE,
  120. };
  121. enum {
  122. AUTO_SEQ_FRONT = 0,
  123. AUTO_SEQ_SURROUND,
  124. AUTO_SEQ_CENLFE,
  125. AUTO_SEQ_SIDE
  126. };
  127. /* Some VT1708S based boards gets the micboost setting wrong, so we have
  128. * to apply some brute-force and re-write the TLV's by software. */
  129. static int mic_boost_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  130. unsigned int size, unsigned int __user *_tlv)
  131. {
  132. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  133. hda_nid_t nid = get_amp_nid(kcontrol);
  134. if (get_codec_type(codec->vendor_id) == VT1708S
  135. && (nid == 0x1a || nid == 0x1e)) {
  136. if (size < 4 * sizeof(unsigned int))
  137. return -ENOMEM;
  138. if (put_user(1, _tlv)) /* SNDRV_CTL_TLVT_DB_SCALE */
  139. return -EFAULT;
  140. if (put_user(2 * sizeof(unsigned int), _tlv + 1))
  141. return -EFAULT;
  142. if (put_user(0, _tlv + 2)) /* offset = 0 */
  143. return -EFAULT;
  144. if (put_user(1000, _tlv + 3)) /* step size = 10 dB */
  145. return -EFAULT;
  146. }
  147. return 0;
  148. }
  149. static int mic_boost_volume_info(struct snd_kcontrol *kcontrol,
  150. struct snd_ctl_elem_info *uinfo)
  151. {
  152. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  153. hda_nid_t nid = get_amp_nid(kcontrol);
  154. if (get_codec_type(codec->vendor_id) == VT1708S
  155. && (nid == 0x1a || nid == 0x1e)) {
  156. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  157. uinfo->count = 2;
  158. uinfo->value.integer.min = 0;
  159. uinfo->value.integer.max = 3;
  160. }
  161. return 0;
  162. }
  163. static struct snd_kcontrol_new vt1708_control_templates[] = {
  164. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  165. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  166. };
  167. struct via_spec {
  168. /* codec parameterization */
  169. struct snd_kcontrol_new *mixers[3];
  170. unsigned int num_mixers;
  171. struct hda_verb *init_verbs[5];
  172. unsigned int num_iverbs;
  173. char *stream_name_analog;
  174. struct hda_pcm_stream *stream_analog_playback;
  175. struct hda_pcm_stream *stream_analog_capture;
  176. char *stream_name_digital;
  177. struct hda_pcm_stream *stream_digital_playback;
  178. struct hda_pcm_stream *stream_digital_capture;
  179. /* playback */
  180. struct hda_multi_out multiout;
  181. hda_nid_t slave_dig_outs[2];
  182. /* capture */
  183. unsigned int num_adc_nids;
  184. hda_nid_t *adc_nids;
  185. hda_nid_t mux_nids[3];
  186. hda_nid_t dig_in_nid;
  187. hda_nid_t dig_in_pin;
  188. /* capture source */
  189. const struct hda_input_mux *input_mux;
  190. unsigned int cur_mux[3];
  191. /* PCM information */
  192. struct hda_pcm pcm_rec[3];
  193. /* dynamic controls, init_verbs and input_mux */
  194. struct auto_pin_cfg autocfg;
  195. struct snd_array kctls;
  196. struct hda_input_mux private_imux[2];
  197. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  198. /* HP mode source */
  199. const struct hda_input_mux *hp_mux;
  200. unsigned int hp_independent_mode;
  201. #ifdef CONFIG_SND_HDA_POWER_SAVE
  202. struct hda_loopback_check loopback;
  203. #endif
  204. };
  205. static hda_nid_t vt1708_adc_nids[2] = {
  206. /* ADC1-2 */
  207. 0x15, 0x27
  208. };
  209. static hda_nid_t vt1709_adc_nids[3] = {
  210. /* ADC1-2 */
  211. 0x14, 0x15, 0x16
  212. };
  213. static hda_nid_t vt1708B_adc_nids[2] = {
  214. /* ADC1-2 */
  215. 0x13, 0x14
  216. };
  217. static hda_nid_t vt1708S_adc_nids[2] = {
  218. /* ADC1-2 */
  219. 0x13, 0x14
  220. };
  221. static hda_nid_t vt1702_adc_nids[3] = {
  222. /* ADC1-2 */
  223. 0x12, 0x20, 0x1F
  224. };
  225. /* add dynamic controls */
  226. static int via_add_control(struct via_spec *spec, int type, const char *name,
  227. unsigned long val)
  228. {
  229. struct snd_kcontrol_new *knew;
  230. snd_array_init(&spec->kctls, sizeof(*knew), 32);
  231. knew = snd_array_new(&spec->kctls);
  232. if (!knew)
  233. return -ENOMEM;
  234. *knew = vt1708_control_templates[type];
  235. knew->name = kstrdup(name, GFP_KERNEL);
  236. if (!knew->name)
  237. return -ENOMEM;
  238. knew->private_value = val;
  239. return 0;
  240. }
  241. static void via_free_kctls(struct hda_codec *codec)
  242. {
  243. struct via_spec *spec = codec->spec;
  244. if (spec->kctls.list) {
  245. struct snd_kcontrol_new *kctl = spec->kctls.list;
  246. int i;
  247. for (i = 0; i < spec->kctls.used; i++)
  248. kfree(kctl[i].name);
  249. }
  250. snd_array_free(&spec->kctls);
  251. }
  252. /* create input playback/capture controls for the given pin */
  253. static int via_new_analog_input(struct via_spec *spec, hda_nid_t pin,
  254. const char *ctlname, int idx, int mix_nid)
  255. {
  256. char name[32];
  257. int err;
  258. sprintf(name, "%s Playback Volume", ctlname);
  259. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  260. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  261. if (err < 0)
  262. return err;
  263. sprintf(name, "%s Playback Switch", ctlname);
  264. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  265. HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
  266. if (err < 0)
  267. return err;
  268. return 0;
  269. }
  270. static void via_auto_set_output_and_unmute(struct hda_codec *codec,
  271. hda_nid_t nid, int pin_type,
  272. int dac_idx)
  273. {
  274. /* set as output */
  275. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  276. pin_type);
  277. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  278. AMP_OUT_UNMUTE);
  279. if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
  280. snd_hda_codec_write(codec, nid, 0,
  281. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  282. }
  283. static void via_auto_init_multi_out(struct hda_codec *codec)
  284. {
  285. struct via_spec *spec = codec->spec;
  286. int i;
  287. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  288. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  289. if (nid)
  290. via_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  291. }
  292. }
  293. static void via_auto_init_hp_out(struct hda_codec *codec)
  294. {
  295. struct via_spec *spec = codec->spec;
  296. hda_nid_t pin;
  297. pin = spec->autocfg.hp_pins[0];
  298. if (pin) /* connect to front */
  299. via_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  300. }
  301. static void via_auto_init_analog_input(struct hda_codec *codec)
  302. {
  303. struct via_spec *spec = codec->spec;
  304. int i;
  305. for (i = 0; i < AUTO_PIN_LAST; i++) {
  306. hda_nid_t nid = spec->autocfg.input_pins[i];
  307. snd_hda_codec_write(codec, nid, 0,
  308. AC_VERB_SET_PIN_WIDGET_CONTROL,
  309. (i <= AUTO_PIN_FRONT_MIC ?
  310. PIN_VREF50 : PIN_IN));
  311. }
  312. }
  313. /*
  314. * input MUX handling
  315. */
  316. static int via_mux_enum_info(struct snd_kcontrol *kcontrol,
  317. struct snd_ctl_elem_info *uinfo)
  318. {
  319. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  320. struct via_spec *spec = codec->spec;
  321. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  322. }
  323. static int via_mux_enum_get(struct snd_kcontrol *kcontrol,
  324. struct snd_ctl_elem_value *ucontrol)
  325. {
  326. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  327. struct via_spec *spec = codec->spec;
  328. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  329. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  330. return 0;
  331. }
  332. static int via_mux_enum_put(struct snd_kcontrol *kcontrol,
  333. struct snd_ctl_elem_value *ucontrol)
  334. {
  335. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  336. struct via_spec *spec = codec->spec;
  337. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  338. if (!spec->mux_nids[adc_idx])
  339. return -EINVAL;
  340. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  341. spec->mux_nids[adc_idx],
  342. &spec->cur_mux[adc_idx]);
  343. }
  344. static int via_independent_hp_info(struct snd_kcontrol *kcontrol,
  345. struct snd_ctl_elem_info *uinfo)
  346. {
  347. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  348. struct via_spec *spec = codec->spec;
  349. return snd_hda_input_mux_info(spec->hp_mux, uinfo);
  350. }
  351. static int via_independent_hp_get(struct snd_kcontrol *kcontrol,
  352. struct snd_ctl_elem_value *ucontrol)
  353. {
  354. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  355. struct via_spec *spec = codec->spec;
  356. hda_nid_t nid = spec->autocfg.hp_pins[0];
  357. unsigned int pinsel = snd_hda_codec_read(codec, nid, 0,
  358. AC_VERB_GET_CONNECT_SEL,
  359. 0x00);
  360. ucontrol->value.enumerated.item[0] = pinsel;
  361. return 0;
  362. }
  363. static int via_independent_hp_put(struct snd_kcontrol *kcontrol,
  364. struct snd_ctl_elem_value *ucontrol)
  365. {
  366. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  367. struct via_spec *spec = codec->spec;
  368. hda_nid_t nid = spec->autocfg.hp_pins[0];
  369. unsigned int pinsel = ucontrol->value.enumerated.item[0];
  370. unsigned int con_nid = snd_hda_codec_read(codec, nid, 0,
  371. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  372. if (con_nid == spec->multiout.hp_nid) {
  373. if (pinsel == 0) {
  374. if (!spec->hp_independent_mode) {
  375. if (spec->multiout.num_dacs > 1)
  376. spec->multiout.num_dacs -= 1;
  377. spec->hp_independent_mode = 1;
  378. }
  379. } else if (pinsel == 1) {
  380. if (spec->hp_independent_mode) {
  381. if (spec->multiout.num_dacs > 1)
  382. spec->multiout.num_dacs += 1;
  383. spec->hp_independent_mode = 0;
  384. }
  385. }
  386. } else {
  387. if (pinsel == 0) {
  388. if (spec->hp_independent_mode) {
  389. if (spec->multiout.num_dacs > 1)
  390. spec->multiout.num_dacs += 1;
  391. spec->hp_independent_mode = 0;
  392. }
  393. } else if (pinsel == 1) {
  394. if (!spec->hp_independent_mode) {
  395. if (spec->multiout.num_dacs > 1)
  396. spec->multiout.num_dacs -= 1;
  397. spec->hp_independent_mode = 1;
  398. }
  399. }
  400. }
  401. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL,
  402. pinsel);
  403. if (spec->multiout.hp_nid &&
  404. spec->multiout.hp_nid != spec->multiout.dac_nids[HDA_FRONT])
  405. snd_hda_codec_setup_stream(codec,
  406. spec->multiout.hp_nid,
  407. 0, 0, 0);
  408. return 0;
  409. }
  410. static struct snd_kcontrol_new via_hp_mixer[] = {
  411. {
  412. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  413. .name = "Independent HP",
  414. .count = 1,
  415. .info = via_independent_hp_info,
  416. .get = via_independent_hp_get,
  417. .put = via_independent_hp_put,
  418. },
  419. { } /* end */
  420. };
  421. /* capture mixer elements */
  422. static struct snd_kcontrol_new vt1708_capture_mixer[] = {
  423. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_INPUT),
  424. HDA_CODEC_MUTE("Capture Switch", 0x15, 0x0, HDA_INPUT),
  425. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x27, 0x0, HDA_INPUT),
  426. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x27, 0x0, HDA_INPUT),
  427. {
  428. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  429. /* The multiple "Capture Source" controls confuse alsamixer
  430. * So call somewhat different..
  431. */
  432. /* .name = "Capture Source", */
  433. .name = "Input Source",
  434. .count = 1,
  435. .info = via_mux_enum_info,
  436. .get = via_mux_enum_get,
  437. .put = via_mux_enum_put,
  438. },
  439. { } /* end */
  440. };
  441. /*
  442. * generic initialization of ADC, input mixers and output mixers
  443. */
  444. static struct hda_verb vt1708_volume_init_verbs[] = {
  445. /*
  446. * Unmute ADC0-1 and set the default input to mic-in
  447. */
  448. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  449. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  450. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  451. * mixer widget
  452. */
  453. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  454. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  455. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  456. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  457. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  458. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  459. /*
  460. * Set up output mixers (0x19 - 0x1b)
  461. */
  462. /* set vol=0 to output mixers */
  463. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  464. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  465. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  466. /* Setup default input to PW4 */
  467. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  468. /* PW9 Output enable */
  469. {0x25, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  470. { }
  471. };
  472. static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
  473. struct hda_codec *codec,
  474. struct snd_pcm_substream *substream)
  475. {
  476. struct via_spec *spec = codec->spec;
  477. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  478. hinfo);
  479. }
  480. static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  481. struct hda_codec *codec,
  482. unsigned int stream_tag,
  483. unsigned int format,
  484. struct snd_pcm_substream *substream)
  485. {
  486. struct via_spec *spec = codec->spec;
  487. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  488. stream_tag, format, substream);
  489. }
  490. static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  491. struct hda_codec *codec,
  492. struct snd_pcm_substream *substream)
  493. {
  494. struct via_spec *spec = codec->spec;
  495. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  496. }
  497. static void playback_multi_pcm_prep_0(struct hda_codec *codec,
  498. unsigned int stream_tag,
  499. unsigned int format,
  500. struct snd_pcm_substream *substream)
  501. {
  502. struct via_spec *spec = codec->spec;
  503. struct hda_multi_out *mout = &spec->multiout;
  504. hda_nid_t *nids = mout->dac_nids;
  505. int chs = substream->runtime->channels;
  506. int i;
  507. mutex_lock(&codec->spdif_mutex);
  508. if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
  509. if (chs == 2 &&
  510. snd_hda_is_supported_format(codec, mout->dig_out_nid,
  511. format) &&
  512. !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
  513. mout->dig_out_used = HDA_DIG_ANALOG_DUP;
  514. /* turn off SPDIF once; otherwise the IEC958 bits won't
  515. * be updated */
  516. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  517. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  518. AC_VERB_SET_DIGI_CONVERT_1,
  519. codec->spdif_ctls &
  520. ~AC_DIG1_ENABLE & 0xff);
  521. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  522. stream_tag, 0, format);
  523. /* turn on again (if needed) */
  524. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  525. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  526. AC_VERB_SET_DIGI_CONVERT_1,
  527. codec->spdif_ctls & 0xff);
  528. } else {
  529. mout->dig_out_used = 0;
  530. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  531. 0, 0, 0);
  532. }
  533. }
  534. mutex_unlock(&codec->spdif_mutex);
  535. /* front */
  536. snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
  537. 0, format);
  538. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  539. !spec->hp_independent_mode)
  540. /* headphone out will just decode front left/right (stereo) */
  541. snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
  542. 0, format);
  543. /* extra outputs copied from front */
  544. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  545. if (mout->extra_out_nid[i])
  546. snd_hda_codec_setup_stream(codec,
  547. mout->extra_out_nid[i],
  548. stream_tag, 0, format);
  549. /* surrounds */
  550. for (i = 1; i < mout->num_dacs; i++) {
  551. if (chs >= (i + 1) * 2) /* independent out */
  552. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  553. i * 2, format);
  554. else /* copy front */
  555. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  556. 0, format);
  557. }
  558. }
  559. static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
  560. struct hda_codec *codec,
  561. unsigned int stream_tag,
  562. unsigned int format,
  563. struct snd_pcm_substream *substream)
  564. {
  565. struct via_spec *spec = codec->spec;
  566. struct hda_multi_out *mout = &spec->multiout;
  567. hda_nid_t *nids = mout->dac_nids;
  568. if (substream->number == 0)
  569. playback_multi_pcm_prep_0(codec, stream_tag, format,
  570. substream);
  571. else {
  572. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  573. spec->hp_independent_mode)
  574. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  575. stream_tag, 0, format);
  576. }
  577. return 0;
  578. }
  579. static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  580. struct hda_codec *codec,
  581. struct snd_pcm_substream *substream)
  582. {
  583. struct via_spec *spec = codec->spec;
  584. struct hda_multi_out *mout = &spec->multiout;
  585. hda_nid_t *nids = mout->dac_nids;
  586. int i;
  587. if (substream->number == 0) {
  588. for (i = 0; i < mout->num_dacs; i++)
  589. snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
  590. if (mout->hp_nid && !spec->hp_independent_mode)
  591. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  592. 0, 0, 0);
  593. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  594. if (mout->extra_out_nid[i])
  595. snd_hda_codec_setup_stream(codec,
  596. mout->extra_out_nid[i],
  597. 0, 0, 0);
  598. mutex_lock(&codec->spdif_mutex);
  599. if (mout->dig_out_nid &&
  600. mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
  601. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  602. 0, 0, 0);
  603. mout->dig_out_used = 0;
  604. }
  605. mutex_unlock(&codec->spdif_mutex);
  606. } else {
  607. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  608. spec->hp_independent_mode)
  609. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  610. 0, 0, 0);
  611. }
  612. return 0;
  613. }
  614. /*
  615. * Digital out
  616. */
  617. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  618. struct hda_codec *codec,
  619. struct snd_pcm_substream *substream)
  620. {
  621. struct via_spec *spec = codec->spec;
  622. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  623. }
  624. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  625. struct hda_codec *codec,
  626. struct snd_pcm_substream *substream)
  627. {
  628. struct via_spec *spec = codec->spec;
  629. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  630. }
  631. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  632. struct hda_codec *codec,
  633. unsigned int stream_tag,
  634. unsigned int format,
  635. struct snd_pcm_substream *substream)
  636. {
  637. struct via_spec *spec = codec->spec;
  638. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  639. stream_tag, format, substream);
  640. }
  641. static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  642. struct hda_codec *codec,
  643. struct snd_pcm_substream *substream)
  644. {
  645. struct via_spec *spec = codec->spec;
  646. snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  647. return 0;
  648. }
  649. /*
  650. * Analog capture
  651. */
  652. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  653. struct hda_codec *codec,
  654. unsigned int stream_tag,
  655. unsigned int format,
  656. struct snd_pcm_substream *substream)
  657. {
  658. struct via_spec *spec = codec->spec;
  659. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  660. stream_tag, 0, format);
  661. return 0;
  662. }
  663. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  664. struct hda_codec *codec,
  665. struct snd_pcm_substream *substream)
  666. {
  667. struct via_spec *spec = codec->spec;
  668. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  669. return 0;
  670. }
  671. static struct hda_pcm_stream vt1708_pcm_analog_playback = {
  672. .substreams = 2,
  673. .channels_min = 2,
  674. .channels_max = 8,
  675. .nid = 0x10, /* NID to query formats and rates */
  676. .ops = {
  677. .open = via_playback_pcm_open,
  678. .prepare = via_playback_multi_pcm_prepare,
  679. .cleanup = via_playback_multi_pcm_cleanup
  680. },
  681. };
  682. static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
  683. .substreams = 1,
  684. .channels_min = 2,
  685. .channels_max = 8,
  686. .nid = 0x10, /* NID to query formats and rates */
  687. /* We got noisy outputs on the right channel on VT1708 when
  688. * 24bit samples are used. Until any workaround is found,
  689. * disable the 24bit format, so far.
  690. */
  691. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  692. .ops = {
  693. .open = via_playback_pcm_open,
  694. .prepare = via_playback_pcm_prepare,
  695. .cleanup = via_playback_pcm_cleanup
  696. },
  697. };
  698. static struct hda_pcm_stream vt1708_pcm_analog_capture = {
  699. .substreams = 2,
  700. .channels_min = 2,
  701. .channels_max = 2,
  702. .nid = 0x15, /* NID to query formats and rates */
  703. .ops = {
  704. .prepare = via_capture_pcm_prepare,
  705. .cleanup = via_capture_pcm_cleanup
  706. },
  707. };
  708. static struct hda_pcm_stream vt1708_pcm_digital_playback = {
  709. .substreams = 1,
  710. .channels_min = 2,
  711. .channels_max = 2,
  712. /* NID is set in via_build_pcms */
  713. .ops = {
  714. .open = via_dig_playback_pcm_open,
  715. .close = via_dig_playback_pcm_close,
  716. .prepare = via_dig_playback_pcm_prepare,
  717. .cleanup = via_dig_playback_pcm_cleanup
  718. },
  719. };
  720. static struct hda_pcm_stream vt1708_pcm_digital_capture = {
  721. .substreams = 1,
  722. .channels_min = 2,
  723. .channels_max = 2,
  724. };
  725. static int via_build_controls(struct hda_codec *codec)
  726. {
  727. struct via_spec *spec = codec->spec;
  728. int err;
  729. int i;
  730. for (i = 0; i < spec->num_mixers; i++) {
  731. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  732. if (err < 0)
  733. return err;
  734. }
  735. if (spec->multiout.dig_out_nid) {
  736. err = snd_hda_create_spdif_out_ctls(codec,
  737. spec->multiout.dig_out_nid);
  738. if (err < 0)
  739. return err;
  740. err = snd_hda_create_spdif_share_sw(codec,
  741. &spec->multiout);
  742. if (err < 0)
  743. return err;
  744. spec->multiout.share_spdif = 1;
  745. }
  746. if (spec->dig_in_nid) {
  747. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  748. if (err < 0)
  749. return err;
  750. }
  751. via_free_kctls(codec); /* no longer needed */
  752. return 0;
  753. }
  754. static int via_build_pcms(struct hda_codec *codec)
  755. {
  756. struct via_spec *spec = codec->spec;
  757. struct hda_pcm *info = spec->pcm_rec;
  758. codec->num_pcms = 1;
  759. codec->pcm_info = info;
  760. info->name = spec->stream_name_analog;
  761. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
  762. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  763. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  764. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  765. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  766. spec->multiout.max_channels;
  767. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  768. codec->num_pcms++;
  769. info++;
  770. info->name = spec->stream_name_digital;
  771. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  772. if (spec->multiout.dig_out_nid) {
  773. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  774. *(spec->stream_digital_playback);
  775. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  776. spec->multiout.dig_out_nid;
  777. }
  778. if (spec->dig_in_nid) {
  779. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  780. *(spec->stream_digital_capture);
  781. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  782. spec->dig_in_nid;
  783. }
  784. }
  785. return 0;
  786. }
  787. static void via_free(struct hda_codec *codec)
  788. {
  789. struct via_spec *spec = codec->spec;
  790. if (!spec)
  791. return;
  792. via_free_kctls(codec);
  793. kfree(codec->spec);
  794. }
  795. /* mute internal speaker if HP is plugged */
  796. static void via_hp_automute(struct hda_codec *codec)
  797. {
  798. unsigned int present;
  799. struct via_spec *spec = codec->spec;
  800. present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
  801. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  802. snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
  803. HDA_OUTPUT, 0, HDA_AMP_MUTE,
  804. present ? HDA_AMP_MUTE : 0);
  805. }
  806. static void via_gpio_control(struct hda_codec *codec)
  807. {
  808. unsigned int gpio_data;
  809. unsigned int vol_counter;
  810. unsigned int vol;
  811. unsigned int master_vol;
  812. struct via_spec *spec = codec->spec;
  813. gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
  814. AC_VERB_GET_GPIO_DATA, 0) & 0x03;
  815. vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
  816. 0xF84, 0) & 0x3F0000) >> 16;
  817. vol = vol_counter & 0x1F;
  818. master_vol = snd_hda_codec_read(codec, 0x1A, 0,
  819. AC_VERB_GET_AMP_GAIN_MUTE,
  820. AC_AMP_GET_INPUT);
  821. if (gpio_data == 0x02) {
  822. /* unmute line out */
  823. snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
  824. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  825. if (vol_counter & 0x20) {
  826. /* decrease volume */
  827. if (vol > master_vol)
  828. vol = master_vol;
  829. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
  830. 0, HDA_AMP_VOLMASK,
  831. master_vol-vol);
  832. } else {
  833. /* increase volume */
  834. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
  835. HDA_AMP_VOLMASK,
  836. ((master_vol+vol) > 0x2A) ? 0x2A :
  837. (master_vol+vol));
  838. }
  839. } else if (!(gpio_data & 0x02)) {
  840. /* mute line out */
  841. snd_hda_codec_amp_stereo(codec,
  842. spec->autocfg.line_out_pins[0],
  843. HDA_OUTPUT, 0, HDA_AMP_MUTE,
  844. HDA_AMP_MUTE);
  845. }
  846. }
  847. /* unsolicited event for jack sensing */
  848. static void via_unsol_event(struct hda_codec *codec,
  849. unsigned int res)
  850. {
  851. res >>= 26;
  852. if (res == VIA_HP_EVENT)
  853. via_hp_automute(codec);
  854. else if (res == VIA_GPIO_EVENT)
  855. via_gpio_control(codec);
  856. }
  857. static int via_init(struct hda_codec *codec)
  858. {
  859. struct via_spec *spec = codec->spec;
  860. int i;
  861. for (i = 0; i < spec->num_iverbs; i++)
  862. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  863. /* Lydia Add for EAPD enable */
  864. if (!spec->dig_in_nid) { /* No Digital In connection */
  865. if (spec->dig_in_pin) {
  866. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  867. AC_VERB_SET_PIN_WIDGET_CONTROL,
  868. PIN_OUT);
  869. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  870. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  871. }
  872. } else /* enable SPDIF-input pin */
  873. snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
  874. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  875. /* assign slave outs */
  876. if (spec->slave_dig_outs[0])
  877. codec->slave_dig_outs = spec->slave_dig_outs;
  878. return 0;
  879. }
  880. #ifdef CONFIG_SND_HDA_POWER_SAVE
  881. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  882. {
  883. struct via_spec *spec = codec->spec;
  884. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  885. }
  886. #endif
  887. /*
  888. */
  889. static struct hda_codec_ops via_patch_ops = {
  890. .build_controls = via_build_controls,
  891. .build_pcms = via_build_pcms,
  892. .init = via_init,
  893. .free = via_free,
  894. #ifdef CONFIG_SND_HDA_POWER_SAVE
  895. .check_power_status = via_check_power_status,
  896. #endif
  897. };
  898. /* fill in the dac_nids table from the parsed pin configuration */
  899. static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
  900. const struct auto_pin_cfg *cfg)
  901. {
  902. int i;
  903. hda_nid_t nid;
  904. spec->multiout.num_dacs = cfg->line_outs;
  905. spec->multiout.dac_nids = spec->private_dac_nids;
  906. for(i = 0; i < 4; i++) {
  907. nid = cfg->line_out_pins[i];
  908. if (nid) {
  909. /* config dac list */
  910. switch (i) {
  911. case AUTO_SEQ_FRONT:
  912. spec->multiout.dac_nids[i] = 0x10;
  913. break;
  914. case AUTO_SEQ_CENLFE:
  915. spec->multiout.dac_nids[i] = 0x12;
  916. break;
  917. case AUTO_SEQ_SURROUND:
  918. spec->multiout.dac_nids[i] = 0x11;
  919. break;
  920. case AUTO_SEQ_SIDE:
  921. spec->multiout.dac_nids[i] = 0x13;
  922. break;
  923. }
  924. }
  925. }
  926. return 0;
  927. }
  928. /* add playback controls from the parsed DAC table */
  929. static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
  930. const struct auto_pin_cfg *cfg)
  931. {
  932. char name[32];
  933. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  934. hda_nid_t nid, nid_vol = 0;
  935. int i, err;
  936. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  937. nid = cfg->line_out_pins[i];
  938. if (!nid)
  939. continue;
  940. if (i != AUTO_SEQ_FRONT)
  941. nid_vol = 0x18 + i;
  942. if (i == AUTO_SEQ_CENLFE) {
  943. /* Center/LFE */
  944. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  945. "Center Playback Volume",
  946. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  947. HDA_OUTPUT));
  948. if (err < 0)
  949. return err;
  950. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  951. "LFE Playback Volume",
  952. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  953. HDA_OUTPUT));
  954. if (err < 0)
  955. return err;
  956. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  957. "Center Playback Switch",
  958. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  959. HDA_OUTPUT));
  960. if (err < 0)
  961. return err;
  962. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  963. "LFE Playback Switch",
  964. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  965. HDA_OUTPUT));
  966. if (err < 0)
  967. return err;
  968. } else if (i == AUTO_SEQ_FRONT){
  969. /* add control to mixer index 0 */
  970. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  971. "Master Front Playback Volume",
  972. HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
  973. HDA_INPUT));
  974. if (err < 0)
  975. return err;
  976. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  977. "Master Front Playback Switch",
  978. HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
  979. HDA_INPUT));
  980. if (err < 0)
  981. return err;
  982. /* add control to PW3 */
  983. sprintf(name, "%s Playback Volume", chname[i]);
  984. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  985. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  986. HDA_OUTPUT));
  987. if (err < 0)
  988. return err;
  989. sprintf(name, "%s Playback Switch", chname[i]);
  990. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  991. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  992. HDA_OUTPUT));
  993. if (err < 0)
  994. return err;
  995. } else {
  996. sprintf(name, "%s Playback Volume", chname[i]);
  997. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  998. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  999. HDA_OUTPUT));
  1000. if (err < 0)
  1001. return err;
  1002. sprintf(name, "%s Playback Switch", chname[i]);
  1003. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1004. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1005. HDA_OUTPUT));
  1006. if (err < 0)
  1007. return err;
  1008. }
  1009. }
  1010. return 0;
  1011. }
  1012. static void create_hp_imux(struct via_spec *spec)
  1013. {
  1014. int i;
  1015. struct hda_input_mux *imux = &spec->private_imux[1];
  1016. static const char *texts[] = { "OFF", "ON", NULL};
  1017. /* for hp mode select */
  1018. i = 0;
  1019. while (texts[i] != NULL) {
  1020. imux->items[imux->num_items].label = texts[i];
  1021. imux->items[imux->num_items].index = i;
  1022. imux->num_items++;
  1023. i++;
  1024. }
  1025. spec->hp_mux = &spec->private_imux[1];
  1026. }
  1027. static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  1028. {
  1029. int err;
  1030. if (!pin)
  1031. return 0;
  1032. spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
  1033. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1034. "Headphone Playback Volume",
  1035. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1036. if (err < 0)
  1037. return err;
  1038. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1039. "Headphone Playback Switch",
  1040. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1041. if (err < 0)
  1042. return err;
  1043. create_hp_imux(spec);
  1044. return 0;
  1045. }
  1046. /* create playback/capture controls for input pins */
  1047. static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
  1048. const struct auto_pin_cfg *cfg)
  1049. {
  1050. static char *labels[] = {
  1051. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  1052. };
  1053. struct hda_input_mux *imux = &spec->private_imux[0];
  1054. int i, err, idx = 0;
  1055. /* for internal loopback recording select */
  1056. imux->items[imux->num_items].label = "Stereo Mixer";
  1057. imux->items[imux->num_items].index = idx;
  1058. imux->num_items++;
  1059. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1060. if (!cfg->input_pins[i])
  1061. continue;
  1062. switch (cfg->input_pins[i]) {
  1063. case 0x1d: /* Mic */
  1064. idx = 2;
  1065. break;
  1066. case 0x1e: /* Line In */
  1067. idx = 3;
  1068. break;
  1069. case 0x21: /* Front Mic */
  1070. idx = 4;
  1071. break;
  1072. case 0x24: /* CD */
  1073. idx = 1;
  1074. break;
  1075. }
  1076. err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
  1077. idx, 0x17);
  1078. if (err < 0)
  1079. return err;
  1080. imux->items[imux->num_items].label = labels[i];
  1081. imux->items[imux->num_items].index = idx;
  1082. imux->num_items++;
  1083. }
  1084. return 0;
  1085. }
  1086. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1087. static struct hda_amp_list vt1708_loopbacks[] = {
  1088. { 0x17, HDA_INPUT, 1 },
  1089. { 0x17, HDA_INPUT, 2 },
  1090. { 0x17, HDA_INPUT, 3 },
  1091. { 0x17, HDA_INPUT, 4 },
  1092. { } /* end */
  1093. };
  1094. #endif
  1095. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  1096. {
  1097. unsigned int def_conf;
  1098. unsigned char seqassoc;
  1099. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  1100. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  1101. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  1102. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
  1103. if (seqassoc == 0xff) {
  1104. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  1105. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  1106. }
  1107. }
  1108. return;
  1109. }
  1110. static int vt1708_parse_auto_config(struct hda_codec *codec)
  1111. {
  1112. struct via_spec *spec = codec->spec;
  1113. int err;
  1114. /* Add HP and CD pin config connect bit re-config action */
  1115. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  1116. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  1117. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  1118. if (err < 0)
  1119. return err;
  1120. err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
  1121. if (err < 0)
  1122. return err;
  1123. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  1124. return 0; /* can't find valid BIOS pin config */
  1125. err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
  1126. if (err < 0)
  1127. return err;
  1128. err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  1129. if (err < 0)
  1130. return err;
  1131. err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
  1132. if (err < 0)
  1133. return err;
  1134. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1135. if (spec->autocfg.dig_outs)
  1136. spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
  1137. spec->dig_in_pin = VT1708_DIGIN_PIN;
  1138. if (spec->autocfg.dig_in_pin)
  1139. spec->dig_in_nid = VT1708_DIGIN_NID;
  1140. if (spec->kctls.list)
  1141. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  1142. spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
  1143. spec->input_mux = &spec->private_imux[0];
  1144. if (spec->hp_mux)
  1145. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  1146. return 1;
  1147. }
  1148. /* init callback for auto-configuration model -- overriding the default init */
  1149. static int via_auto_init(struct hda_codec *codec)
  1150. {
  1151. via_init(codec);
  1152. via_auto_init_multi_out(codec);
  1153. via_auto_init_hp_out(codec);
  1154. via_auto_init_analog_input(codec);
  1155. return 0;
  1156. }
  1157. static int get_mux_nids(struct hda_codec *codec)
  1158. {
  1159. struct via_spec *spec = codec->spec;
  1160. hda_nid_t nid, conn[8];
  1161. unsigned int type;
  1162. int i, n;
  1163. for (i = 0; i < spec->num_adc_nids; i++) {
  1164. nid = spec->adc_nids[i];
  1165. while (nid) {
  1166. type = get_wcaps_type(get_wcaps(codec, nid));
  1167. if (type == AC_WID_PIN)
  1168. break;
  1169. n = snd_hda_get_connections(codec, nid, conn,
  1170. ARRAY_SIZE(conn));
  1171. if (n <= 0)
  1172. break;
  1173. if (n > 1) {
  1174. spec->mux_nids[i] = nid;
  1175. break;
  1176. }
  1177. nid = conn[0];
  1178. }
  1179. }
  1180. return 0;
  1181. }
  1182. static int patch_vt1708(struct hda_codec *codec)
  1183. {
  1184. struct via_spec *spec;
  1185. int err;
  1186. /* create a codec specific record */
  1187. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1188. if (spec == NULL)
  1189. return -ENOMEM;
  1190. codec->spec = spec;
  1191. /* automatic parse from the BIOS config */
  1192. err = vt1708_parse_auto_config(codec);
  1193. if (err < 0) {
  1194. via_free(codec);
  1195. return err;
  1196. } else if (!err) {
  1197. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  1198. "from BIOS. Using genenic mode...\n");
  1199. }
  1200. spec->stream_name_analog = "VT1708 Analog";
  1201. spec->stream_analog_playback = &vt1708_pcm_analog_playback;
  1202. /* disable 32bit format on VT1708 */
  1203. if (codec->vendor_id == 0x11061708)
  1204. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  1205. spec->stream_analog_capture = &vt1708_pcm_analog_capture;
  1206. spec->stream_name_digital = "VT1708 Digital";
  1207. spec->stream_digital_playback = &vt1708_pcm_digital_playback;
  1208. spec->stream_digital_capture = &vt1708_pcm_digital_capture;
  1209. if (!spec->adc_nids && spec->input_mux) {
  1210. spec->adc_nids = vt1708_adc_nids;
  1211. spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
  1212. get_mux_nids(codec);
  1213. spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
  1214. spec->num_mixers++;
  1215. }
  1216. codec->patch_ops = via_patch_ops;
  1217. codec->patch_ops.init = via_auto_init;
  1218. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1219. spec->loopback.amplist = vt1708_loopbacks;
  1220. #endif
  1221. return 0;
  1222. }
  1223. /* capture mixer elements */
  1224. static struct snd_kcontrol_new vt1709_capture_mixer[] = {
  1225. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
  1226. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
  1227. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
  1228. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
  1229. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
  1230. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
  1231. {
  1232. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1233. /* The multiple "Capture Source" controls confuse alsamixer
  1234. * So call somewhat different..
  1235. */
  1236. /* .name = "Capture Source", */
  1237. .name = "Input Source",
  1238. .count = 1,
  1239. .info = via_mux_enum_info,
  1240. .get = via_mux_enum_get,
  1241. .put = via_mux_enum_put,
  1242. },
  1243. { } /* end */
  1244. };
  1245. static struct hda_verb vt1709_uniwill_init_verbs[] = {
  1246. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  1247. { }
  1248. };
  1249. /*
  1250. * generic initialization of ADC, input mixers and output mixers
  1251. */
  1252. static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
  1253. /*
  1254. * Unmute ADC0-2 and set the default input to mic-in
  1255. */
  1256. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1257. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1258. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1259. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1260. * mixer widget
  1261. */
  1262. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1263. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1264. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1265. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1266. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1267. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1268. /*
  1269. * Set up output selector (0x1a, 0x1b, 0x29)
  1270. */
  1271. /* set vol=0 to output mixers */
  1272. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1273. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1274. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1275. /*
  1276. * Unmute PW3 and PW4
  1277. */
  1278. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1279. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1280. /* Set input of PW4 as AOW4 */
  1281. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  1282. /* PW9 Output enable */
  1283. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1284. { }
  1285. };
  1286. static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
  1287. .substreams = 1,
  1288. .channels_min = 2,
  1289. .channels_max = 10,
  1290. .nid = 0x10, /* NID to query formats and rates */
  1291. .ops = {
  1292. .open = via_playback_pcm_open,
  1293. .prepare = via_playback_pcm_prepare,
  1294. .cleanup = via_playback_pcm_cleanup
  1295. },
  1296. };
  1297. static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
  1298. .substreams = 1,
  1299. .channels_min = 2,
  1300. .channels_max = 6,
  1301. .nid = 0x10, /* NID to query formats and rates */
  1302. .ops = {
  1303. .open = via_playback_pcm_open,
  1304. .prepare = via_playback_pcm_prepare,
  1305. .cleanup = via_playback_pcm_cleanup
  1306. },
  1307. };
  1308. static struct hda_pcm_stream vt1709_pcm_analog_capture = {
  1309. .substreams = 2,
  1310. .channels_min = 2,
  1311. .channels_max = 2,
  1312. .nid = 0x14, /* NID to query formats and rates */
  1313. .ops = {
  1314. .prepare = via_capture_pcm_prepare,
  1315. .cleanup = via_capture_pcm_cleanup
  1316. },
  1317. };
  1318. static struct hda_pcm_stream vt1709_pcm_digital_playback = {
  1319. .substreams = 1,
  1320. .channels_min = 2,
  1321. .channels_max = 2,
  1322. /* NID is set in via_build_pcms */
  1323. .ops = {
  1324. .open = via_dig_playback_pcm_open,
  1325. .close = via_dig_playback_pcm_close
  1326. },
  1327. };
  1328. static struct hda_pcm_stream vt1709_pcm_digital_capture = {
  1329. .substreams = 1,
  1330. .channels_min = 2,
  1331. .channels_max = 2,
  1332. };
  1333. static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
  1334. const struct auto_pin_cfg *cfg)
  1335. {
  1336. int i;
  1337. hda_nid_t nid;
  1338. if (cfg->line_outs == 4) /* 10 channels */
  1339. spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
  1340. else if (cfg->line_outs == 3) /* 6 channels */
  1341. spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
  1342. spec->multiout.dac_nids = spec->private_dac_nids;
  1343. if (cfg->line_outs == 4) { /* 10 channels */
  1344. for (i = 0; i < cfg->line_outs; i++) {
  1345. nid = cfg->line_out_pins[i];
  1346. if (nid) {
  1347. /* config dac list */
  1348. switch (i) {
  1349. case AUTO_SEQ_FRONT:
  1350. /* AOW0 */
  1351. spec->multiout.dac_nids[i] = 0x10;
  1352. break;
  1353. case AUTO_SEQ_CENLFE:
  1354. /* AOW2 */
  1355. spec->multiout.dac_nids[i] = 0x12;
  1356. break;
  1357. case AUTO_SEQ_SURROUND:
  1358. /* AOW3 */
  1359. spec->multiout.dac_nids[i] = 0x11;
  1360. break;
  1361. case AUTO_SEQ_SIDE:
  1362. /* AOW1 */
  1363. spec->multiout.dac_nids[i] = 0x27;
  1364. break;
  1365. default:
  1366. break;
  1367. }
  1368. }
  1369. }
  1370. spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
  1371. } else if (cfg->line_outs == 3) { /* 6 channels */
  1372. for(i = 0; i < cfg->line_outs; i++) {
  1373. nid = cfg->line_out_pins[i];
  1374. if (nid) {
  1375. /* config dac list */
  1376. switch(i) {
  1377. case AUTO_SEQ_FRONT:
  1378. /* AOW0 */
  1379. spec->multiout.dac_nids[i] = 0x10;
  1380. break;
  1381. case AUTO_SEQ_CENLFE:
  1382. /* AOW2 */
  1383. spec->multiout.dac_nids[i] = 0x12;
  1384. break;
  1385. case AUTO_SEQ_SURROUND:
  1386. /* AOW1 */
  1387. spec->multiout.dac_nids[i] = 0x11;
  1388. break;
  1389. default:
  1390. break;
  1391. }
  1392. }
  1393. }
  1394. }
  1395. return 0;
  1396. }
  1397. /* add playback controls from the parsed DAC table */
  1398. static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
  1399. const struct auto_pin_cfg *cfg)
  1400. {
  1401. char name[32];
  1402. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  1403. hda_nid_t nid = 0;
  1404. int i, err;
  1405. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  1406. nid = cfg->line_out_pins[i];
  1407. if (!nid)
  1408. continue;
  1409. if (i == AUTO_SEQ_CENLFE) {
  1410. /* Center/LFE */
  1411. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1412. "Center Playback Volume",
  1413. HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
  1414. HDA_OUTPUT));
  1415. if (err < 0)
  1416. return err;
  1417. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1418. "LFE Playback Volume",
  1419. HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
  1420. HDA_OUTPUT));
  1421. if (err < 0)
  1422. return err;
  1423. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1424. "Center Playback Switch",
  1425. HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
  1426. HDA_OUTPUT));
  1427. if (err < 0)
  1428. return err;
  1429. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1430. "LFE Playback Switch",
  1431. HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
  1432. HDA_OUTPUT));
  1433. if (err < 0)
  1434. return err;
  1435. } else if (i == AUTO_SEQ_FRONT){
  1436. /* add control to mixer index 0 */
  1437. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1438. "Master Front Playback Volume",
  1439. HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
  1440. HDA_INPUT));
  1441. if (err < 0)
  1442. return err;
  1443. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1444. "Master Front Playback Switch",
  1445. HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
  1446. HDA_INPUT));
  1447. if (err < 0)
  1448. return err;
  1449. /* add control to PW3 */
  1450. sprintf(name, "%s Playback Volume", chname[i]);
  1451. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1452. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1453. HDA_OUTPUT));
  1454. if (err < 0)
  1455. return err;
  1456. sprintf(name, "%s Playback Switch", chname[i]);
  1457. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1458. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1459. HDA_OUTPUT));
  1460. if (err < 0)
  1461. return err;
  1462. } else if (i == AUTO_SEQ_SURROUND) {
  1463. sprintf(name, "%s Playback Volume", chname[i]);
  1464. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1465. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
  1466. HDA_OUTPUT));
  1467. if (err < 0)
  1468. return err;
  1469. sprintf(name, "%s Playback Switch", chname[i]);
  1470. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1471. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
  1472. HDA_OUTPUT));
  1473. if (err < 0)
  1474. return err;
  1475. } else if (i == AUTO_SEQ_SIDE) {
  1476. sprintf(name, "%s Playback Volume", chname[i]);
  1477. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1478. HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
  1479. HDA_OUTPUT));
  1480. if (err < 0)
  1481. return err;
  1482. sprintf(name, "%s Playback Switch", chname[i]);
  1483. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1484. HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
  1485. HDA_OUTPUT));
  1486. if (err < 0)
  1487. return err;
  1488. }
  1489. }
  1490. return 0;
  1491. }
  1492. static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  1493. {
  1494. int err;
  1495. if (!pin)
  1496. return 0;
  1497. if (spec->multiout.num_dacs == 5) /* 10 channels */
  1498. spec->multiout.hp_nid = VT1709_HP_DAC_NID;
  1499. else if (spec->multiout.num_dacs == 3) /* 6 channels */
  1500. spec->multiout.hp_nid = 0;
  1501. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1502. "Headphone Playback Volume",
  1503. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1504. if (err < 0)
  1505. return err;
  1506. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1507. "Headphone Playback Switch",
  1508. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1509. if (err < 0)
  1510. return err;
  1511. return 0;
  1512. }
  1513. /* create playback/capture controls for input pins */
  1514. static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
  1515. const struct auto_pin_cfg *cfg)
  1516. {
  1517. static char *labels[] = {
  1518. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  1519. };
  1520. struct hda_input_mux *imux = &spec->private_imux[0];
  1521. int i, err, idx = 0;
  1522. /* for internal loopback recording select */
  1523. imux->items[imux->num_items].label = "Stereo Mixer";
  1524. imux->items[imux->num_items].index = idx;
  1525. imux->num_items++;
  1526. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1527. if (!cfg->input_pins[i])
  1528. continue;
  1529. switch (cfg->input_pins[i]) {
  1530. case 0x1d: /* Mic */
  1531. idx = 2;
  1532. break;
  1533. case 0x1e: /* Line In */
  1534. idx = 3;
  1535. break;
  1536. case 0x21: /* Front Mic */
  1537. idx = 4;
  1538. break;
  1539. case 0x23: /* CD */
  1540. idx = 1;
  1541. break;
  1542. }
  1543. err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
  1544. idx, 0x18);
  1545. if (err < 0)
  1546. return err;
  1547. imux->items[imux->num_items].label = labels[i];
  1548. imux->items[imux->num_items].index = idx;
  1549. imux->num_items++;
  1550. }
  1551. return 0;
  1552. }
  1553. static int vt1709_parse_auto_config(struct hda_codec *codec)
  1554. {
  1555. struct via_spec *spec = codec->spec;
  1556. int err;
  1557. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  1558. if (err < 0)
  1559. return err;
  1560. err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
  1561. if (err < 0)
  1562. return err;
  1563. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  1564. return 0; /* can't find valid BIOS pin config */
  1565. err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
  1566. if (err < 0)
  1567. return err;
  1568. err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  1569. if (err < 0)
  1570. return err;
  1571. err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
  1572. if (err < 0)
  1573. return err;
  1574. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1575. if (spec->autocfg.dig_outs)
  1576. spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
  1577. spec->dig_in_pin = VT1709_DIGIN_PIN;
  1578. if (spec->autocfg.dig_in_pin)
  1579. spec->dig_in_nid = VT1709_DIGIN_NID;
  1580. if (spec->kctls.list)
  1581. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  1582. spec->input_mux = &spec->private_imux[0];
  1583. if (spec->hp_mux)
  1584. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  1585. return 1;
  1586. }
  1587. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1588. static struct hda_amp_list vt1709_loopbacks[] = {
  1589. { 0x18, HDA_INPUT, 1 },
  1590. { 0x18, HDA_INPUT, 2 },
  1591. { 0x18, HDA_INPUT, 3 },
  1592. { 0x18, HDA_INPUT, 4 },
  1593. { } /* end */
  1594. };
  1595. #endif
  1596. static int patch_vt1709_10ch(struct hda_codec *codec)
  1597. {
  1598. struct via_spec *spec;
  1599. int err;
  1600. /* create a codec specific record */
  1601. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1602. if (spec == NULL)
  1603. return -ENOMEM;
  1604. codec->spec = spec;
  1605. err = vt1709_parse_auto_config(codec);
  1606. if (err < 0) {
  1607. via_free(codec);
  1608. return err;
  1609. } else if (!err) {
  1610. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  1611. "Using genenic mode...\n");
  1612. }
  1613. spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
  1614. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  1615. spec->stream_name_analog = "VT1709 Analog";
  1616. spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
  1617. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  1618. spec->stream_name_digital = "VT1709 Digital";
  1619. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  1620. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  1621. if (!spec->adc_nids && spec->input_mux) {
  1622. spec->adc_nids = vt1709_adc_nids;
  1623. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  1624. get_mux_nids(codec);
  1625. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  1626. spec->num_mixers++;
  1627. }
  1628. codec->patch_ops = via_patch_ops;
  1629. codec->patch_ops.init = via_auto_init;
  1630. codec->patch_ops.unsol_event = via_unsol_event;
  1631. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1632. spec->loopback.amplist = vt1709_loopbacks;
  1633. #endif
  1634. return 0;
  1635. }
  1636. /*
  1637. * generic initialization of ADC, input mixers and output mixers
  1638. */
  1639. static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
  1640. /*
  1641. * Unmute ADC0-2 and set the default input to mic-in
  1642. */
  1643. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1644. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1645. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1646. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1647. * mixer widget
  1648. */
  1649. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1650. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1651. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1652. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1653. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1654. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1655. /*
  1656. * Set up output selector (0x1a, 0x1b, 0x29)
  1657. */
  1658. /* set vol=0 to output mixers */
  1659. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1660. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1661. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1662. /*
  1663. * Unmute PW3 and PW4
  1664. */
  1665. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1666. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1667. /* Set input of PW4 as MW0 */
  1668. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  1669. /* PW9 Output enable */
  1670. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1671. { }
  1672. };
  1673. static int patch_vt1709_6ch(struct hda_codec *codec)
  1674. {
  1675. struct via_spec *spec;
  1676. int err;
  1677. /* create a codec specific record */
  1678. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1679. if (spec == NULL)
  1680. return -ENOMEM;
  1681. codec->spec = spec;
  1682. err = vt1709_parse_auto_config(codec);
  1683. if (err < 0) {
  1684. via_free(codec);
  1685. return err;
  1686. } else if (!err) {
  1687. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  1688. "Using genenic mode...\n");
  1689. }
  1690. spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
  1691. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  1692. spec->stream_name_analog = "VT1709 Analog";
  1693. spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
  1694. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  1695. spec->stream_name_digital = "VT1709 Digital";
  1696. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  1697. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  1698. if (!spec->adc_nids && spec->input_mux) {
  1699. spec->adc_nids = vt1709_adc_nids;
  1700. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  1701. get_mux_nids(codec);
  1702. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  1703. spec->num_mixers++;
  1704. }
  1705. codec->patch_ops = via_patch_ops;
  1706. codec->patch_ops.init = via_auto_init;
  1707. codec->patch_ops.unsol_event = via_unsol_event;
  1708. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1709. spec->loopback.amplist = vt1709_loopbacks;
  1710. #endif
  1711. return 0;
  1712. }
  1713. /* capture mixer elements */
  1714. static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
  1715. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  1716. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  1717. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  1718. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  1719. {
  1720. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1721. /* The multiple "Capture Source" controls confuse alsamixer
  1722. * So call somewhat different..
  1723. */
  1724. /* .name = "Capture Source", */
  1725. .name = "Input Source",
  1726. .count = 1,
  1727. .info = via_mux_enum_info,
  1728. .get = via_mux_enum_get,
  1729. .put = via_mux_enum_put,
  1730. },
  1731. { } /* end */
  1732. };
  1733. /*
  1734. * generic initialization of ADC, input mixers and output mixers
  1735. */
  1736. static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
  1737. /*
  1738. * Unmute ADC0-1 and set the default input to mic-in
  1739. */
  1740. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1741. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1742. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1743. * mixer widget
  1744. */
  1745. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1746. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1747. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1748. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1749. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1750. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1751. /*
  1752. * Set up output mixers
  1753. */
  1754. /* set vol=0 to output mixers */
  1755. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1756. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1757. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1758. /* Setup default input to PW4 */
  1759. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1760. /* PW9 Output enable */
  1761. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1762. /* PW10 Input enable */
  1763. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  1764. { }
  1765. };
  1766. static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
  1767. /*
  1768. * Unmute ADC0-1 and set the default input to mic-in
  1769. */
  1770. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1771. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1772. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1773. * mixer widget
  1774. */
  1775. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1776. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1777. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1778. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1779. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1780. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1781. /*
  1782. * Set up output mixers
  1783. */
  1784. /* set vol=0 to output mixers */
  1785. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1786. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1787. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1788. /* Setup default input of PW4 to MW0 */
  1789. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  1790. /* PW9 Output enable */
  1791. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1792. /* PW10 Input enable */
  1793. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  1794. { }
  1795. };
  1796. static struct hda_verb vt1708B_uniwill_init_verbs[] = {
  1797. {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  1798. { }
  1799. };
  1800. static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
  1801. .substreams = 2,
  1802. .channels_min = 2,
  1803. .channels_max = 8,
  1804. .nid = 0x10, /* NID to query formats and rates */
  1805. .ops = {
  1806. .open = via_playback_pcm_open,
  1807. .prepare = via_playback_multi_pcm_prepare,
  1808. .cleanup = via_playback_multi_pcm_cleanup
  1809. },
  1810. };
  1811. static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
  1812. .substreams = 2,
  1813. .channels_min = 2,
  1814. .channels_max = 4,
  1815. .nid = 0x10, /* NID to query formats and rates */
  1816. .ops = {
  1817. .open = via_playback_pcm_open,
  1818. .prepare = via_playback_multi_pcm_prepare,
  1819. .cleanup = via_playback_multi_pcm_cleanup
  1820. },
  1821. };
  1822. static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
  1823. .substreams = 2,
  1824. .channels_min = 2,
  1825. .channels_max = 2,
  1826. .nid = 0x13, /* NID to query formats and rates */
  1827. .ops = {
  1828. .prepare = via_capture_pcm_prepare,
  1829. .cleanup = via_capture_pcm_cleanup
  1830. },
  1831. };
  1832. static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
  1833. .substreams = 1,
  1834. .channels_min = 2,
  1835. .channels_max = 2,
  1836. /* NID is set in via_build_pcms */
  1837. .ops = {
  1838. .open = via_dig_playback_pcm_open,
  1839. .close = via_dig_playback_pcm_close,
  1840. .prepare = via_dig_playback_pcm_prepare,
  1841. .cleanup = via_dig_playback_pcm_cleanup
  1842. },
  1843. };
  1844. static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
  1845. .substreams = 1,
  1846. .channels_min = 2,
  1847. .channels_max = 2,
  1848. };
  1849. /* fill in the dac_nids table from the parsed pin configuration */
  1850. static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
  1851. const struct auto_pin_cfg *cfg)
  1852. {
  1853. int i;
  1854. hda_nid_t nid;
  1855. spec->multiout.num_dacs = cfg->line_outs;
  1856. spec->multiout.dac_nids = spec->private_dac_nids;
  1857. for (i = 0; i < 4; i++) {
  1858. nid = cfg->line_out_pins[i];
  1859. if (nid) {
  1860. /* config dac list */
  1861. switch (i) {
  1862. case AUTO_SEQ_FRONT:
  1863. spec->multiout.dac_nids[i] = 0x10;
  1864. break;
  1865. case AUTO_SEQ_CENLFE:
  1866. spec->multiout.dac_nids[i] = 0x24;
  1867. break;
  1868. case AUTO_SEQ_SURROUND:
  1869. spec->multiout.dac_nids[i] = 0x11;
  1870. break;
  1871. case AUTO_SEQ_SIDE:
  1872. spec->multiout.dac_nids[i] = 0x25;
  1873. break;
  1874. }
  1875. }
  1876. }
  1877. return 0;
  1878. }
  1879. /* add playback controls from the parsed DAC table */
  1880. static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
  1881. const struct auto_pin_cfg *cfg)
  1882. {
  1883. char name[32];
  1884. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  1885. hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
  1886. hda_nid_t nid, nid_vol = 0;
  1887. int i, err;
  1888. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  1889. nid = cfg->line_out_pins[i];
  1890. if (!nid)
  1891. continue;
  1892. nid_vol = nid_vols[i];
  1893. if (i == AUTO_SEQ_CENLFE) {
  1894. /* Center/LFE */
  1895. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1896. "Center Playback Volume",
  1897. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  1898. HDA_OUTPUT));
  1899. if (err < 0)
  1900. return err;
  1901. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1902. "LFE Playback Volume",
  1903. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  1904. HDA_OUTPUT));
  1905. if (err < 0)
  1906. return err;
  1907. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1908. "Center Playback Switch",
  1909. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  1910. HDA_OUTPUT));
  1911. if (err < 0)
  1912. return err;
  1913. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1914. "LFE Playback Switch",
  1915. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  1916. HDA_OUTPUT));
  1917. if (err < 0)
  1918. return err;
  1919. } else if (i == AUTO_SEQ_FRONT) {
  1920. /* add control to mixer index 0 */
  1921. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1922. "Master Front Playback Volume",
  1923. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1924. HDA_INPUT));
  1925. if (err < 0)
  1926. return err;
  1927. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1928. "Master Front Playback Switch",
  1929. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1930. HDA_INPUT));
  1931. if (err < 0)
  1932. return err;
  1933. /* add control to PW3 */
  1934. sprintf(name, "%s Playback Volume", chname[i]);
  1935. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1936. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1937. HDA_OUTPUT));
  1938. if (err < 0)
  1939. return err;
  1940. sprintf(name, "%s Playback Switch", chname[i]);
  1941. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1942. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1943. HDA_OUTPUT));
  1944. if (err < 0)
  1945. return err;
  1946. } else {
  1947. sprintf(name, "%s Playback Volume", chname[i]);
  1948. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1949. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1950. HDA_OUTPUT));
  1951. if (err < 0)
  1952. return err;
  1953. sprintf(name, "%s Playback Switch", chname[i]);
  1954. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1955. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1956. HDA_OUTPUT));
  1957. if (err < 0)
  1958. return err;
  1959. }
  1960. }
  1961. return 0;
  1962. }
  1963. static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  1964. {
  1965. int err;
  1966. if (!pin)
  1967. return 0;
  1968. spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
  1969. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1970. "Headphone Playback Volume",
  1971. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1972. if (err < 0)
  1973. return err;
  1974. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1975. "Headphone Playback Switch",
  1976. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1977. if (err < 0)
  1978. return err;
  1979. create_hp_imux(spec);
  1980. return 0;
  1981. }
  1982. /* create playback/capture controls for input pins */
  1983. static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
  1984. const struct auto_pin_cfg *cfg)
  1985. {
  1986. static char *labels[] = {
  1987. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  1988. };
  1989. struct hda_input_mux *imux = &spec->private_imux[0];
  1990. int i, err, idx = 0;
  1991. /* for internal loopback recording select */
  1992. imux->items[imux->num_items].label = "Stereo Mixer";
  1993. imux->items[imux->num_items].index = idx;
  1994. imux->num_items++;
  1995. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1996. if (!cfg->input_pins[i])
  1997. continue;
  1998. switch (cfg->input_pins[i]) {
  1999. case 0x1a: /* Mic */
  2000. idx = 2;
  2001. break;
  2002. case 0x1b: /* Line In */
  2003. idx = 3;
  2004. break;
  2005. case 0x1e: /* Front Mic */
  2006. idx = 4;
  2007. break;
  2008. case 0x1f: /* CD */
  2009. idx = 1;
  2010. break;
  2011. }
  2012. err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
  2013. idx, 0x16);
  2014. if (err < 0)
  2015. return err;
  2016. imux->items[imux->num_items].label = labels[i];
  2017. imux->items[imux->num_items].index = idx;
  2018. imux->num_items++;
  2019. }
  2020. return 0;
  2021. }
  2022. static int vt1708B_parse_auto_config(struct hda_codec *codec)
  2023. {
  2024. struct via_spec *spec = codec->spec;
  2025. int err;
  2026. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2027. if (err < 0)
  2028. return err;
  2029. err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
  2030. if (err < 0)
  2031. return err;
  2032. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2033. return 0; /* can't find valid BIOS pin config */
  2034. err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2035. if (err < 0)
  2036. return err;
  2037. err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2038. if (err < 0)
  2039. return err;
  2040. err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2041. if (err < 0)
  2042. return err;
  2043. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2044. if (spec->autocfg.dig_outs)
  2045. spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
  2046. spec->dig_in_pin = VT1708B_DIGIN_PIN;
  2047. if (spec->autocfg.dig_in_pin)
  2048. spec->dig_in_nid = VT1708B_DIGIN_NID;
  2049. if (spec->kctls.list)
  2050. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2051. spec->input_mux = &spec->private_imux[0];
  2052. if (spec->hp_mux)
  2053. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2054. return 1;
  2055. }
  2056. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2057. static struct hda_amp_list vt1708B_loopbacks[] = {
  2058. { 0x16, HDA_INPUT, 1 },
  2059. { 0x16, HDA_INPUT, 2 },
  2060. { 0x16, HDA_INPUT, 3 },
  2061. { 0x16, HDA_INPUT, 4 },
  2062. { } /* end */
  2063. };
  2064. #endif
  2065. static int patch_vt1708B_8ch(struct hda_codec *codec)
  2066. {
  2067. struct via_spec *spec;
  2068. int err;
  2069. /* create a codec specific record */
  2070. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2071. if (spec == NULL)
  2072. return -ENOMEM;
  2073. codec->spec = spec;
  2074. /* automatic parse from the BIOS config */
  2075. err = vt1708B_parse_auto_config(codec);
  2076. if (err < 0) {
  2077. via_free(codec);
  2078. return err;
  2079. } else if (!err) {
  2080. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2081. "from BIOS. Using genenic mode...\n");
  2082. }
  2083. spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
  2084. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  2085. spec->stream_name_analog = "VT1708B Analog";
  2086. spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
  2087. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  2088. spec->stream_name_digital = "VT1708B Digital";
  2089. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  2090. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  2091. if (!spec->adc_nids && spec->input_mux) {
  2092. spec->adc_nids = vt1708B_adc_nids;
  2093. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  2094. get_mux_nids(codec);
  2095. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  2096. spec->num_mixers++;
  2097. }
  2098. codec->patch_ops = via_patch_ops;
  2099. codec->patch_ops.init = via_auto_init;
  2100. codec->patch_ops.unsol_event = via_unsol_event;
  2101. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2102. spec->loopback.amplist = vt1708B_loopbacks;
  2103. #endif
  2104. return 0;
  2105. }
  2106. static int patch_vt1708B_4ch(struct hda_codec *codec)
  2107. {
  2108. struct via_spec *spec;
  2109. int err;
  2110. /* create a codec specific record */
  2111. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2112. if (spec == NULL)
  2113. return -ENOMEM;
  2114. codec->spec = spec;
  2115. /* automatic parse from the BIOS config */
  2116. err = vt1708B_parse_auto_config(codec);
  2117. if (err < 0) {
  2118. via_free(codec);
  2119. return err;
  2120. } else if (!err) {
  2121. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2122. "from BIOS. Using genenic mode...\n");
  2123. }
  2124. spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
  2125. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  2126. spec->stream_name_analog = "VT1708B Analog";
  2127. spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
  2128. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  2129. spec->stream_name_digital = "VT1708B Digital";
  2130. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  2131. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  2132. if (!spec->adc_nids && spec->input_mux) {
  2133. spec->adc_nids = vt1708B_adc_nids;
  2134. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  2135. get_mux_nids(codec);
  2136. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  2137. spec->num_mixers++;
  2138. }
  2139. codec->patch_ops = via_patch_ops;
  2140. codec->patch_ops.init = via_auto_init;
  2141. codec->patch_ops.unsol_event = via_unsol_event;
  2142. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2143. spec->loopback.amplist = vt1708B_loopbacks;
  2144. #endif
  2145. return 0;
  2146. }
  2147. /* Patch for VT1708S */
  2148. /* VT1708S software backdoor based override for buggy hardware micboost
  2149. * setting */
  2150. #define MIC_BOOST_VOLUME(xname, nid) { \
  2151. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2152. .name = xname, \
  2153. .index = 0, \
  2154. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  2155. SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  2156. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  2157. .info = mic_boost_volume_info, \
  2158. .get = snd_hda_mixer_amp_volume_get, \
  2159. .put = snd_hda_mixer_amp_volume_put, \
  2160. .tlv = { .c = mic_boost_tlv }, \
  2161. .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
  2162. /* capture mixer elements */
  2163. static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
  2164. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  2165. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  2166. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  2167. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  2168. MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
  2169. MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
  2170. {
  2171. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2172. /* The multiple "Capture Source" controls confuse alsamixer
  2173. * So call somewhat different..
  2174. */
  2175. /* .name = "Capture Source", */
  2176. .name = "Input Source",
  2177. .count = 1,
  2178. .info = via_mux_enum_info,
  2179. .get = via_mux_enum_get,
  2180. .put = via_mux_enum_put,
  2181. },
  2182. { } /* end */
  2183. };
  2184. static struct hda_verb vt1708S_volume_init_verbs[] = {
  2185. /* Unmute ADC0-1 and set the default input to mic-in */
  2186. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2187. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2188. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
  2189. * analog-loopback mixer widget */
  2190. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2191. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2192. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2193. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2194. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2195. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2196. /* Setup default input of PW4 to MW0 */
  2197. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  2198. /* PW9, PW10 Output enable */
  2199. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2200. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2201. /* Enable Mic Boost Volume backdoor */
  2202. {0x1, 0xf98, 0x1},
  2203. { }
  2204. };
  2205. static struct hda_verb vt1708S_uniwill_init_verbs[] = {
  2206. {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  2207. { }
  2208. };
  2209. static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
  2210. .substreams = 2,
  2211. .channels_min = 2,
  2212. .channels_max = 8,
  2213. .nid = 0x10, /* NID to query formats and rates */
  2214. .ops = {
  2215. .open = via_playback_pcm_open,
  2216. .prepare = via_playback_pcm_prepare,
  2217. .cleanup = via_playback_pcm_cleanup
  2218. },
  2219. };
  2220. static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
  2221. .substreams = 2,
  2222. .channels_min = 2,
  2223. .channels_max = 2,
  2224. .nid = 0x13, /* NID to query formats and rates */
  2225. .ops = {
  2226. .prepare = via_capture_pcm_prepare,
  2227. .cleanup = via_capture_pcm_cleanup
  2228. },
  2229. };
  2230. static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
  2231. .substreams = 1,
  2232. .channels_min = 2,
  2233. .channels_max = 2,
  2234. /* NID is set in via_build_pcms */
  2235. .ops = {
  2236. .open = via_dig_playback_pcm_open,
  2237. .close = via_dig_playback_pcm_close,
  2238. .prepare = via_dig_playback_pcm_prepare,
  2239. .cleanup = via_dig_playback_pcm_cleanup
  2240. },
  2241. };
  2242. /* fill in the dac_nids table from the parsed pin configuration */
  2243. static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
  2244. const struct auto_pin_cfg *cfg)
  2245. {
  2246. int i;
  2247. hda_nid_t nid;
  2248. spec->multiout.num_dacs = cfg->line_outs;
  2249. spec->multiout.dac_nids = spec->private_dac_nids;
  2250. for (i = 0; i < 4; i++) {
  2251. nid = cfg->line_out_pins[i];
  2252. if (nid) {
  2253. /* config dac list */
  2254. switch (i) {
  2255. case AUTO_SEQ_FRONT:
  2256. spec->multiout.dac_nids[i] = 0x10;
  2257. break;
  2258. case AUTO_SEQ_CENLFE:
  2259. spec->multiout.dac_nids[i] = 0x24;
  2260. break;
  2261. case AUTO_SEQ_SURROUND:
  2262. spec->multiout.dac_nids[i] = 0x11;
  2263. break;
  2264. case AUTO_SEQ_SIDE:
  2265. spec->multiout.dac_nids[i] = 0x25;
  2266. break;
  2267. }
  2268. }
  2269. }
  2270. return 0;
  2271. }
  2272. /* add playback controls from the parsed DAC table */
  2273. static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
  2274. const struct auto_pin_cfg *cfg)
  2275. {
  2276. char name[32];
  2277. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  2278. hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
  2279. hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
  2280. hda_nid_t nid, nid_vol, nid_mute;
  2281. int i, err;
  2282. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2283. nid = cfg->line_out_pins[i];
  2284. if (!nid)
  2285. continue;
  2286. nid_vol = nid_vols[i];
  2287. nid_mute = nid_mutes[i];
  2288. if (i == AUTO_SEQ_CENLFE) {
  2289. /* Center/LFE */
  2290. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2291. "Center Playback Volume",
  2292. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2293. HDA_OUTPUT));
  2294. if (err < 0)
  2295. return err;
  2296. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2297. "LFE Playback Volume",
  2298. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2299. HDA_OUTPUT));
  2300. if (err < 0)
  2301. return err;
  2302. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2303. "Center Playback Switch",
  2304. HDA_COMPOSE_AMP_VAL(nid_mute,
  2305. 1, 0,
  2306. HDA_OUTPUT));
  2307. if (err < 0)
  2308. return err;
  2309. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2310. "LFE Playback Switch",
  2311. HDA_COMPOSE_AMP_VAL(nid_mute,
  2312. 2, 0,
  2313. HDA_OUTPUT));
  2314. if (err < 0)
  2315. return err;
  2316. } else if (i == AUTO_SEQ_FRONT) {
  2317. /* add control to mixer index 0 */
  2318. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2319. "Master Front Playback Volume",
  2320. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  2321. HDA_INPUT));
  2322. if (err < 0)
  2323. return err;
  2324. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2325. "Master Front Playback Switch",
  2326. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  2327. HDA_INPUT));
  2328. if (err < 0)
  2329. return err;
  2330. /* Front */
  2331. sprintf(name, "%s Playback Volume", chname[i]);
  2332. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2333. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2334. HDA_OUTPUT));
  2335. if (err < 0)
  2336. return err;
  2337. sprintf(name, "%s Playback Switch", chname[i]);
  2338. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2339. HDA_COMPOSE_AMP_VAL(nid_mute,
  2340. 3, 0,
  2341. HDA_OUTPUT));
  2342. if (err < 0)
  2343. return err;
  2344. } else {
  2345. sprintf(name, "%s Playback Volume", chname[i]);
  2346. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2347. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2348. HDA_OUTPUT));
  2349. if (err < 0)
  2350. return err;
  2351. sprintf(name, "%s Playback Switch", chname[i]);
  2352. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2353. HDA_COMPOSE_AMP_VAL(nid_mute,
  2354. 3, 0,
  2355. HDA_OUTPUT));
  2356. if (err < 0)
  2357. return err;
  2358. }
  2359. }
  2360. return 0;
  2361. }
  2362. static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2363. {
  2364. int err;
  2365. if (!pin)
  2366. return 0;
  2367. spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
  2368. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2369. "Headphone Playback Volume",
  2370. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  2371. if (err < 0)
  2372. return err;
  2373. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2374. "Headphone Playback Switch",
  2375. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2376. if (err < 0)
  2377. return err;
  2378. create_hp_imux(spec);
  2379. return 0;
  2380. }
  2381. /* create playback/capture controls for input pins */
  2382. static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
  2383. const struct auto_pin_cfg *cfg)
  2384. {
  2385. static char *labels[] = {
  2386. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2387. };
  2388. struct hda_input_mux *imux = &spec->private_imux[0];
  2389. int i, err, idx = 0;
  2390. /* for internal loopback recording select */
  2391. imux->items[imux->num_items].label = "Stereo Mixer";
  2392. imux->items[imux->num_items].index = 5;
  2393. imux->num_items++;
  2394. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2395. if (!cfg->input_pins[i])
  2396. continue;
  2397. switch (cfg->input_pins[i]) {
  2398. case 0x1a: /* Mic */
  2399. idx = 2;
  2400. break;
  2401. case 0x1b: /* Line In */
  2402. idx = 3;
  2403. break;
  2404. case 0x1e: /* Front Mic */
  2405. idx = 4;
  2406. break;
  2407. case 0x1f: /* CD */
  2408. idx = 1;
  2409. break;
  2410. }
  2411. err = via_new_analog_input(spec, cfg->input_pins[i], labels[i],
  2412. idx, 0x16);
  2413. if (err < 0)
  2414. return err;
  2415. imux->items[imux->num_items].label = labels[i];
  2416. imux->items[imux->num_items].index = idx-1;
  2417. imux->num_items++;
  2418. }
  2419. return 0;
  2420. }
  2421. /* fill out digital output widgets; one for master and one for slave outputs */
  2422. static void fill_dig_outs(struct hda_codec *codec)
  2423. {
  2424. struct via_spec *spec = codec->spec;
  2425. int i;
  2426. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  2427. hda_nid_t nid;
  2428. int conn;
  2429. nid = spec->autocfg.dig_out_pins[i];
  2430. if (!nid)
  2431. continue;
  2432. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  2433. if (conn < 1)
  2434. continue;
  2435. if (!spec->multiout.dig_out_nid)
  2436. spec->multiout.dig_out_nid = nid;
  2437. else {
  2438. spec->slave_dig_outs[0] = nid;
  2439. break; /* at most two dig outs */
  2440. }
  2441. }
  2442. }
  2443. static int vt1708S_parse_auto_config(struct hda_codec *codec)
  2444. {
  2445. struct via_spec *spec = codec->spec;
  2446. int err;
  2447. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2448. if (err < 0)
  2449. return err;
  2450. err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
  2451. if (err < 0)
  2452. return err;
  2453. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2454. return 0; /* can't find valid BIOS pin config */
  2455. err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2456. if (err < 0)
  2457. return err;
  2458. err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2459. if (err < 0)
  2460. return err;
  2461. err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2462. if (err < 0)
  2463. return err;
  2464. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2465. fill_dig_outs(codec);
  2466. if (spec->kctls.list)
  2467. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2468. spec->input_mux = &spec->private_imux[0];
  2469. if (spec->hp_mux)
  2470. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2471. return 1;
  2472. }
  2473. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2474. static struct hda_amp_list vt1708S_loopbacks[] = {
  2475. { 0x16, HDA_INPUT, 1 },
  2476. { 0x16, HDA_INPUT, 2 },
  2477. { 0x16, HDA_INPUT, 3 },
  2478. { 0x16, HDA_INPUT, 4 },
  2479. { } /* end */
  2480. };
  2481. #endif
  2482. static int patch_vt1708S(struct hda_codec *codec)
  2483. {
  2484. struct via_spec *spec;
  2485. int err;
  2486. /* create a codec specific record */
  2487. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2488. if (spec == NULL)
  2489. return -ENOMEM;
  2490. codec->spec = spec;
  2491. /* automatic parse from the BIOS config */
  2492. err = vt1708S_parse_auto_config(codec);
  2493. if (err < 0) {
  2494. via_free(codec);
  2495. return err;
  2496. } else if (!err) {
  2497. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2498. "from BIOS. Using genenic mode...\n");
  2499. }
  2500. spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
  2501. spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
  2502. spec->stream_name_analog = "VT1708S Analog";
  2503. spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
  2504. spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
  2505. spec->stream_name_digital = "VT1708S Digital";
  2506. spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
  2507. if (!spec->adc_nids && spec->input_mux) {
  2508. spec->adc_nids = vt1708S_adc_nids;
  2509. spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
  2510. get_mux_nids(codec);
  2511. spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
  2512. spec->num_mixers++;
  2513. }
  2514. codec->patch_ops = via_patch_ops;
  2515. codec->patch_ops.init = via_auto_init;
  2516. codec->patch_ops.unsol_event = via_unsol_event;
  2517. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2518. spec->loopback.amplist = vt1708S_loopbacks;
  2519. #endif
  2520. return 0;
  2521. }
  2522. /* Patch for VT1702 */
  2523. /* capture mixer elements */
  2524. static struct snd_kcontrol_new vt1702_capture_mixer[] = {
  2525. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
  2526. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
  2527. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
  2528. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
  2529. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
  2530. HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
  2531. HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
  2532. HDA_INPUT),
  2533. {
  2534. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2535. /* The multiple "Capture Source" controls confuse alsamixer
  2536. * So call somewhat different..
  2537. */
  2538. /* .name = "Capture Source", */
  2539. .name = "Input Source",
  2540. .count = 1,
  2541. .info = via_mux_enum_info,
  2542. .get = via_mux_enum_get,
  2543. .put = via_mux_enum_put,
  2544. },
  2545. { } /* end */
  2546. };
  2547. static struct hda_verb vt1702_volume_init_verbs[] = {
  2548. /*
  2549. * Unmute ADC0-1 and set the default input to mic-in
  2550. */
  2551. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2552. {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2553. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2554. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2555. * mixer widget
  2556. */
  2557. /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
  2558. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2559. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2560. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2561. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2562. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2563. /* Setup default input of PW4 to MW0 */
  2564. {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
  2565. /* PW6 PW7 Output enable */
  2566. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2567. {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2568. { }
  2569. };
  2570. static struct hda_verb vt1702_uniwill_init_verbs[] = {
  2571. {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
  2572. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  2573. { }
  2574. };
  2575. static struct hda_pcm_stream vt1702_pcm_analog_playback = {
  2576. .substreams = 2,
  2577. .channels_min = 2,
  2578. .channels_max = 2,
  2579. .nid = 0x10, /* NID to query formats and rates */
  2580. .ops = {
  2581. .open = via_playback_pcm_open,
  2582. .prepare = via_playback_multi_pcm_prepare,
  2583. .cleanup = via_playback_multi_pcm_cleanup
  2584. },
  2585. };
  2586. static struct hda_pcm_stream vt1702_pcm_analog_capture = {
  2587. .substreams = 3,
  2588. .channels_min = 2,
  2589. .channels_max = 2,
  2590. .nid = 0x12, /* NID to query formats and rates */
  2591. .ops = {
  2592. .prepare = via_capture_pcm_prepare,
  2593. .cleanup = via_capture_pcm_cleanup
  2594. },
  2595. };
  2596. static struct hda_pcm_stream vt1702_pcm_digital_playback = {
  2597. .substreams = 2,
  2598. .channels_min = 2,
  2599. .channels_max = 2,
  2600. /* NID is set in via_build_pcms */
  2601. .ops = {
  2602. .open = via_dig_playback_pcm_open,
  2603. .close = via_dig_playback_pcm_close,
  2604. .prepare = via_dig_playback_pcm_prepare,
  2605. .cleanup = via_dig_playback_pcm_cleanup
  2606. },
  2607. };
  2608. /* fill in the dac_nids table from the parsed pin configuration */
  2609. static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
  2610. const struct auto_pin_cfg *cfg)
  2611. {
  2612. spec->multiout.num_dacs = 1;
  2613. spec->multiout.dac_nids = spec->private_dac_nids;
  2614. if (cfg->line_out_pins[0]) {
  2615. /* config dac list */
  2616. spec->multiout.dac_nids[0] = 0x10;
  2617. }
  2618. return 0;
  2619. }
  2620. /* add playback controls from the parsed DAC table */
  2621. static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
  2622. const struct auto_pin_cfg *cfg)
  2623. {
  2624. int err;
  2625. if (!cfg->line_out_pins[0])
  2626. return -1;
  2627. /* add control to mixer index 0 */
  2628. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2629. "Master Front Playback Volume",
  2630. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  2631. if (err < 0)
  2632. return err;
  2633. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2634. "Master Front Playback Switch",
  2635. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  2636. if (err < 0)
  2637. return err;
  2638. /* Front */
  2639. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2640. "Front Playback Volume",
  2641. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
  2642. if (err < 0)
  2643. return err;
  2644. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2645. "Front Playback Switch",
  2646. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
  2647. if (err < 0)
  2648. return err;
  2649. return 0;
  2650. }
  2651. static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2652. {
  2653. int err;
  2654. if (!pin)
  2655. return 0;
  2656. spec->multiout.hp_nid = 0x1D;
  2657. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2658. "Headphone Playback Volume",
  2659. HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
  2660. if (err < 0)
  2661. return err;
  2662. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2663. "Headphone Playback Switch",
  2664. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2665. if (err < 0)
  2666. return err;
  2667. create_hp_imux(spec);
  2668. return 0;
  2669. }
  2670. /* create playback/capture controls for input pins */
  2671. static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
  2672. const struct auto_pin_cfg *cfg)
  2673. {
  2674. static char *labels[] = {
  2675. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2676. };
  2677. struct hda_input_mux *imux = &spec->private_imux[0];
  2678. int i, err, idx = 0;
  2679. /* for internal loopback recording select */
  2680. imux->items[imux->num_items].label = "Stereo Mixer";
  2681. imux->items[imux->num_items].index = 3;
  2682. imux->num_items++;
  2683. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2684. if (!cfg->input_pins[i])
  2685. continue;
  2686. switch (cfg->input_pins[i]) {
  2687. case 0x14: /* Mic */
  2688. idx = 1;
  2689. break;
  2690. case 0x15: /* Line In */
  2691. idx = 2;
  2692. break;
  2693. case 0x18: /* Front Mic */
  2694. idx = 3;
  2695. break;
  2696. }
  2697. err = via_new_analog_input(spec, cfg->input_pins[i],
  2698. labels[i], idx, 0x1A);
  2699. if (err < 0)
  2700. return err;
  2701. imux->items[imux->num_items].label = labels[i];
  2702. imux->items[imux->num_items].index = idx-1;
  2703. imux->num_items++;
  2704. }
  2705. return 0;
  2706. }
  2707. static int vt1702_parse_auto_config(struct hda_codec *codec)
  2708. {
  2709. struct via_spec *spec = codec->spec;
  2710. int err;
  2711. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2712. if (err < 0)
  2713. return err;
  2714. err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
  2715. if (err < 0)
  2716. return err;
  2717. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2718. return 0; /* can't find valid BIOS pin config */
  2719. err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
  2720. if (err < 0)
  2721. return err;
  2722. err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2723. if (err < 0)
  2724. return err;
  2725. err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2726. if (err < 0)
  2727. return err;
  2728. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2729. fill_dig_outs(codec);
  2730. if (spec->kctls.list)
  2731. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2732. spec->input_mux = &spec->private_imux[0];
  2733. if (spec->hp_mux)
  2734. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2735. return 1;
  2736. }
  2737. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2738. static struct hda_amp_list vt1702_loopbacks[] = {
  2739. { 0x1A, HDA_INPUT, 1 },
  2740. { 0x1A, HDA_INPUT, 2 },
  2741. { 0x1A, HDA_INPUT, 3 },
  2742. { 0x1A, HDA_INPUT, 4 },
  2743. { } /* end */
  2744. };
  2745. #endif
  2746. static int patch_vt1702(struct hda_codec *codec)
  2747. {
  2748. struct via_spec *spec;
  2749. int err;
  2750. unsigned int response;
  2751. unsigned char control;
  2752. /* create a codec specific record */
  2753. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2754. if (spec == NULL)
  2755. return -ENOMEM;
  2756. codec->spec = spec;
  2757. /* automatic parse from the BIOS config */
  2758. err = vt1702_parse_auto_config(codec);
  2759. if (err < 0) {
  2760. via_free(codec);
  2761. return err;
  2762. } else if (!err) {
  2763. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2764. "from BIOS. Using genenic mode...\n");
  2765. }
  2766. spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
  2767. spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
  2768. spec->stream_name_analog = "VT1702 Analog";
  2769. spec->stream_analog_playback = &vt1702_pcm_analog_playback;
  2770. spec->stream_analog_capture = &vt1702_pcm_analog_capture;
  2771. spec->stream_name_digital = "VT1702 Digital";
  2772. spec->stream_digital_playback = &vt1702_pcm_digital_playback;
  2773. if (!spec->adc_nids && spec->input_mux) {
  2774. spec->adc_nids = vt1702_adc_nids;
  2775. spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
  2776. get_mux_nids(codec);
  2777. spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
  2778. spec->num_mixers++;
  2779. }
  2780. codec->patch_ops = via_patch_ops;
  2781. codec->patch_ops.init = via_auto_init;
  2782. codec->patch_ops.unsol_event = via_unsol_event;
  2783. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2784. spec->loopback.amplist = vt1702_loopbacks;
  2785. #endif
  2786. /* Open backdoor */
  2787. response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
  2788. control = (unsigned char)(response & 0xff);
  2789. control |= 0x3;
  2790. snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
  2791. /* Enable GPIO 0&1 for volume&mute control */
  2792. /* Enable GPIO 2 for DMIC-DATA */
  2793. response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
  2794. control = (unsigned char)((response >> 16) & 0x3f);
  2795. snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
  2796. return 0;
  2797. }
  2798. /*
  2799. * patch entries
  2800. */
  2801. static struct hda_codec_preset snd_hda_preset_via[] = {
  2802. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  2803. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  2804. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  2805. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  2806. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  2807. .patch = patch_vt1709_10ch},
  2808. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  2809. .patch = patch_vt1709_10ch},
  2810. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  2811. .patch = patch_vt1709_10ch},
  2812. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  2813. .patch = patch_vt1709_10ch},
  2814. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  2815. .patch = patch_vt1709_6ch},
  2816. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  2817. .patch = patch_vt1709_6ch},
  2818. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  2819. .patch = patch_vt1709_6ch},
  2820. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  2821. .patch = patch_vt1709_6ch},
  2822. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  2823. .patch = patch_vt1708B_8ch},
  2824. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  2825. .patch = patch_vt1708B_8ch},
  2826. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  2827. .patch = patch_vt1708B_8ch},
  2828. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  2829. .patch = patch_vt1708B_8ch},
  2830. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  2831. .patch = patch_vt1708B_4ch},
  2832. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  2833. .patch = patch_vt1708B_4ch},
  2834. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  2835. .patch = patch_vt1708B_4ch},
  2836. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  2837. .patch = patch_vt1708B_4ch},
  2838. { .id = 0x11060397, .name = "VT1708S",
  2839. .patch = patch_vt1708S},
  2840. { .id = 0x11061397, .name = "VT1708S",
  2841. .patch = patch_vt1708S},
  2842. { .id = 0x11062397, .name = "VT1708S",
  2843. .patch = patch_vt1708S},
  2844. { .id = 0x11063397, .name = "VT1708S",
  2845. .patch = patch_vt1708S},
  2846. { .id = 0x11064397, .name = "VT1708S",
  2847. .patch = patch_vt1708S},
  2848. { .id = 0x11065397, .name = "VT1708S",
  2849. .patch = patch_vt1708S},
  2850. { .id = 0x11066397, .name = "VT1708S",
  2851. .patch = patch_vt1708S},
  2852. { .id = 0x11067397, .name = "VT1708S",
  2853. .patch = patch_vt1708S},
  2854. { .id = 0x11060398, .name = "VT1702",
  2855. .patch = patch_vt1702},
  2856. { .id = 0x11061398, .name = "VT1702",
  2857. .patch = patch_vt1702},
  2858. { .id = 0x11062398, .name = "VT1702",
  2859. .patch = patch_vt1702},
  2860. { .id = 0x11063398, .name = "VT1702",
  2861. .patch = patch_vt1702},
  2862. { .id = 0x11064398, .name = "VT1702",
  2863. .patch = patch_vt1702},
  2864. { .id = 0x11065398, .name = "VT1702",
  2865. .patch = patch_vt1702},
  2866. { .id = 0x11066398, .name = "VT1702",
  2867. .patch = patch_vt1702},
  2868. { .id = 0x11067398, .name = "VT1702",
  2869. .patch = patch_vt1702},
  2870. {} /* terminator */
  2871. };
  2872. MODULE_ALIAS("snd-hda-codec-id:1106*");
  2873. static struct hda_codec_preset_list via_list = {
  2874. .preset = snd_hda_preset_via,
  2875. .owner = THIS_MODULE,
  2876. };
  2877. MODULE_LICENSE("GPL");
  2878. MODULE_DESCRIPTION("VIA HD-audio codec");
  2879. static int __init patch_via_init(void)
  2880. {
  2881. return snd_hda_add_codec_preset(&via_list);
  2882. }
  2883. static void __exit patch_via_exit(void)
  2884. {
  2885. snd_hda_delete_codec_preset(&via_list);
  2886. }
  2887. module_init(patch_via_init)
  2888. module_exit(patch_via_exit)