patch_via.c 96 KB

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