patch_via.c 90 KB

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