patch_via.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627
  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, const char *ctlname,
  274. 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. int idle = substream->pstr->substream_opened == 1
  695. && substream->ref_count == 0;
  696. analog_low_current_mode(codec, idle);
  697. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  698. hinfo);
  699. }
  700. static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  701. struct hda_codec *codec,
  702. unsigned int stream_tag,
  703. unsigned int format,
  704. struct snd_pcm_substream *substream)
  705. {
  706. struct via_spec *spec = codec->spec;
  707. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  708. stream_tag, format, substream);
  709. }
  710. static int via_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  711. struct hda_codec *codec,
  712. struct snd_pcm_substream *substream)
  713. {
  714. struct via_spec *spec = codec->spec;
  715. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  716. }
  717. static void playback_multi_pcm_prep_0(struct hda_codec *codec,
  718. unsigned int stream_tag,
  719. unsigned int format,
  720. struct snd_pcm_substream *substream)
  721. {
  722. struct via_spec *spec = codec->spec;
  723. struct hda_multi_out *mout = &spec->multiout;
  724. hda_nid_t *nids = mout->dac_nids;
  725. int chs = substream->runtime->channels;
  726. int i;
  727. mutex_lock(&codec->spdif_mutex);
  728. if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
  729. if (chs == 2 &&
  730. snd_hda_is_supported_format(codec, mout->dig_out_nid,
  731. format) &&
  732. !(codec->spdif_status & IEC958_AES0_NONAUDIO)) {
  733. mout->dig_out_used = HDA_DIG_ANALOG_DUP;
  734. /* turn off SPDIF once; otherwise the IEC958 bits won't
  735. * be updated */
  736. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  737. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  738. AC_VERB_SET_DIGI_CONVERT_1,
  739. codec->spdif_ctls &
  740. ~AC_DIG1_ENABLE & 0xff);
  741. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  742. stream_tag, 0, format);
  743. /* turn on again (if needed) */
  744. if (codec->spdif_ctls & AC_DIG1_ENABLE)
  745. snd_hda_codec_write(codec, mout->dig_out_nid, 0,
  746. AC_VERB_SET_DIGI_CONVERT_1,
  747. codec->spdif_ctls & 0xff);
  748. } else {
  749. mout->dig_out_used = 0;
  750. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  751. 0, 0, 0);
  752. }
  753. }
  754. mutex_unlock(&codec->spdif_mutex);
  755. /* front */
  756. snd_hda_codec_setup_stream(codec, nids[HDA_FRONT], stream_tag,
  757. 0, format);
  758. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  759. !spec->hp_independent_mode)
  760. /* headphone out will just decode front left/right (stereo) */
  761. snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
  762. 0, format);
  763. /* extra outputs copied from front */
  764. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  765. if (mout->extra_out_nid[i])
  766. snd_hda_codec_setup_stream(codec,
  767. mout->extra_out_nid[i],
  768. stream_tag, 0, format);
  769. /* surrounds */
  770. for (i = 1; i < mout->num_dacs; i++) {
  771. if (chs >= (i + 1) * 2) /* independent out */
  772. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  773. i * 2, format);
  774. else /* copy front */
  775. snd_hda_codec_setup_stream(codec, nids[i], stream_tag,
  776. 0, format);
  777. }
  778. }
  779. static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
  780. struct hda_codec *codec,
  781. unsigned int stream_tag,
  782. unsigned int format,
  783. struct snd_pcm_substream *substream)
  784. {
  785. struct via_spec *spec = codec->spec;
  786. struct hda_multi_out *mout = &spec->multiout;
  787. hda_nid_t *nids = mout->dac_nids;
  788. if (substream->number == 0)
  789. playback_multi_pcm_prep_0(codec, stream_tag, format,
  790. substream);
  791. else {
  792. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  793. spec->hp_independent_mode)
  794. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  795. stream_tag, 0, format);
  796. }
  797. return 0;
  798. }
  799. static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  800. struct hda_codec *codec,
  801. struct snd_pcm_substream *substream)
  802. {
  803. struct via_spec *spec = codec->spec;
  804. struct hda_multi_out *mout = &spec->multiout;
  805. hda_nid_t *nids = mout->dac_nids;
  806. int i;
  807. if (substream->number == 0) {
  808. for (i = 0; i < mout->num_dacs; i++)
  809. snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0);
  810. if (mout->hp_nid && !spec->hp_independent_mode)
  811. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  812. 0, 0, 0);
  813. for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
  814. if (mout->extra_out_nid[i])
  815. snd_hda_codec_setup_stream(codec,
  816. mout->extra_out_nid[i],
  817. 0, 0, 0);
  818. mutex_lock(&codec->spdif_mutex);
  819. if (mout->dig_out_nid &&
  820. mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
  821. snd_hda_codec_setup_stream(codec, mout->dig_out_nid,
  822. 0, 0, 0);
  823. mout->dig_out_used = 0;
  824. }
  825. mutex_unlock(&codec->spdif_mutex);
  826. } else {
  827. if (mout->hp_nid && mout->hp_nid != nids[HDA_FRONT] &&
  828. spec->hp_independent_mode)
  829. snd_hda_codec_setup_stream(codec, mout->hp_nid,
  830. 0, 0, 0);
  831. }
  832. return 0;
  833. }
  834. /*
  835. * Digital out
  836. */
  837. static int via_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  838. struct hda_codec *codec,
  839. struct snd_pcm_substream *substream)
  840. {
  841. struct via_spec *spec = codec->spec;
  842. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  843. }
  844. static int via_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  845. struct hda_codec *codec,
  846. struct snd_pcm_substream *substream)
  847. {
  848. struct via_spec *spec = codec->spec;
  849. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  850. }
  851. static int via_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  852. struct hda_codec *codec,
  853. unsigned int stream_tag,
  854. unsigned int format,
  855. struct snd_pcm_substream *substream)
  856. {
  857. struct via_spec *spec = codec->spec;
  858. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  859. stream_tag, format, substream);
  860. }
  861. static int via_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  862. struct hda_codec *codec,
  863. struct snd_pcm_substream *substream)
  864. {
  865. struct via_spec *spec = codec->spec;
  866. snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
  867. return 0;
  868. }
  869. /*
  870. * Analog capture
  871. */
  872. static int via_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  873. struct hda_codec *codec,
  874. unsigned int stream_tag,
  875. unsigned int format,
  876. struct snd_pcm_substream *substream)
  877. {
  878. struct via_spec *spec = codec->spec;
  879. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  880. stream_tag, 0, format);
  881. return 0;
  882. }
  883. static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  884. struct hda_codec *codec,
  885. struct snd_pcm_substream *substream)
  886. {
  887. struct via_spec *spec = codec->spec;
  888. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  889. return 0;
  890. }
  891. static struct hda_pcm_stream vt1708_pcm_analog_playback = {
  892. .substreams = 2,
  893. .channels_min = 2,
  894. .channels_max = 8,
  895. .nid = 0x10, /* NID to query formats and rates */
  896. .ops = {
  897. .open = via_playback_pcm_open,
  898. .prepare = via_playback_multi_pcm_prepare,
  899. .cleanup = via_playback_multi_pcm_cleanup
  900. },
  901. };
  902. static struct hda_pcm_stream vt1708_pcm_analog_s16_playback = {
  903. .substreams = 1,
  904. .channels_min = 2,
  905. .channels_max = 8,
  906. .nid = 0x10, /* NID to query formats and rates */
  907. /* We got noisy outputs on the right channel on VT1708 when
  908. * 24bit samples are used. Until any workaround is found,
  909. * disable the 24bit format, so far.
  910. */
  911. .formats = SNDRV_PCM_FMTBIT_S16_LE,
  912. .ops = {
  913. .open = via_playback_pcm_open,
  914. .prepare = via_playback_pcm_prepare,
  915. .cleanup = via_playback_pcm_cleanup
  916. },
  917. };
  918. static struct hda_pcm_stream vt1708_pcm_analog_capture = {
  919. .substreams = 2,
  920. .channels_min = 2,
  921. .channels_max = 2,
  922. .nid = 0x15, /* NID to query formats and rates */
  923. .ops = {
  924. .prepare = via_capture_pcm_prepare,
  925. .cleanup = via_capture_pcm_cleanup
  926. },
  927. };
  928. static struct hda_pcm_stream vt1708_pcm_digital_playback = {
  929. .substreams = 1,
  930. .channels_min = 2,
  931. .channels_max = 2,
  932. /* NID is set in via_build_pcms */
  933. .ops = {
  934. .open = via_dig_playback_pcm_open,
  935. .close = via_dig_playback_pcm_close,
  936. .prepare = via_dig_playback_pcm_prepare,
  937. .cleanup = via_dig_playback_pcm_cleanup
  938. },
  939. };
  940. static struct hda_pcm_stream vt1708_pcm_digital_capture = {
  941. .substreams = 1,
  942. .channels_min = 2,
  943. .channels_max = 2,
  944. };
  945. static int via_build_controls(struct hda_codec *codec)
  946. {
  947. struct via_spec *spec = codec->spec;
  948. int err;
  949. int i;
  950. for (i = 0; i < spec->num_mixers; i++) {
  951. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  952. if (err < 0)
  953. return err;
  954. }
  955. if (spec->multiout.dig_out_nid) {
  956. err = snd_hda_create_spdif_out_ctls(codec,
  957. spec->multiout.dig_out_nid);
  958. if (err < 0)
  959. return err;
  960. err = snd_hda_create_spdif_share_sw(codec,
  961. &spec->multiout);
  962. if (err < 0)
  963. return err;
  964. spec->multiout.share_spdif = 1;
  965. }
  966. if (spec->dig_in_nid) {
  967. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  968. if (err < 0)
  969. return err;
  970. }
  971. /* init power states */
  972. set_jack_power_state(codec);
  973. analog_low_current_mode(codec, 1);
  974. via_free_kctls(codec); /* no longer needed */
  975. return 0;
  976. }
  977. static int via_build_pcms(struct hda_codec *codec)
  978. {
  979. struct via_spec *spec = codec->spec;
  980. struct hda_pcm *info = spec->pcm_rec;
  981. codec->num_pcms = 1;
  982. codec->pcm_info = info;
  983. info->name = spec->stream_name_analog;
  984. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
  985. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  986. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  987. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  988. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  989. spec->multiout.max_channels;
  990. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  991. codec->num_pcms++;
  992. info++;
  993. info->name = spec->stream_name_digital;
  994. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  995. if (spec->multiout.dig_out_nid) {
  996. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  997. *(spec->stream_digital_playback);
  998. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  999. spec->multiout.dig_out_nid;
  1000. }
  1001. if (spec->dig_in_nid) {
  1002. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  1003. *(spec->stream_digital_capture);
  1004. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  1005. spec->dig_in_nid;
  1006. }
  1007. }
  1008. return 0;
  1009. }
  1010. static void via_free(struct hda_codec *codec)
  1011. {
  1012. struct via_spec *spec = codec->spec;
  1013. if (!spec)
  1014. return;
  1015. via_free_kctls(codec);
  1016. kfree(codec->spec);
  1017. }
  1018. /* mute internal speaker if HP is plugged */
  1019. static void via_hp_automute(struct hda_codec *codec)
  1020. {
  1021. unsigned int present;
  1022. struct via_spec *spec = codec->spec;
  1023. present = snd_hda_codec_read(codec, spec->autocfg.hp_pins[0], 0,
  1024. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1025. snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
  1026. HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1027. present ? HDA_AMP_MUTE : 0);
  1028. }
  1029. static void via_gpio_control(struct hda_codec *codec)
  1030. {
  1031. unsigned int gpio_data;
  1032. unsigned int vol_counter;
  1033. unsigned int vol;
  1034. unsigned int master_vol;
  1035. struct via_spec *spec = codec->spec;
  1036. gpio_data = snd_hda_codec_read(codec, codec->afg, 0,
  1037. AC_VERB_GET_GPIO_DATA, 0) & 0x03;
  1038. vol_counter = (snd_hda_codec_read(codec, codec->afg, 0,
  1039. 0xF84, 0) & 0x3F0000) >> 16;
  1040. vol = vol_counter & 0x1F;
  1041. master_vol = snd_hda_codec_read(codec, 0x1A, 0,
  1042. AC_VERB_GET_AMP_GAIN_MUTE,
  1043. AC_AMP_GET_INPUT);
  1044. if (gpio_data == 0x02) {
  1045. /* unmute line out */
  1046. snd_hda_codec_amp_stereo(codec, spec->autocfg.line_out_pins[0],
  1047. HDA_OUTPUT, 0, HDA_AMP_MUTE, 0);
  1048. if (vol_counter & 0x20) {
  1049. /* decrease volume */
  1050. if (vol > master_vol)
  1051. vol = master_vol;
  1052. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT,
  1053. 0, HDA_AMP_VOLMASK,
  1054. master_vol-vol);
  1055. } else {
  1056. /* increase volume */
  1057. snd_hda_codec_amp_stereo(codec, 0x1A, HDA_INPUT, 0,
  1058. HDA_AMP_VOLMASK,
  1059. ((master_vol+vol) > 0x2A) ? 0x2A :
  1060. (master_vol+vol));
  1061. }
  1062. } else if (!(gpio_data & 0x02)) {
  1063. /* mute line out */
  1064. snd_hda_codec_amp_stereo(codec,
  1065. spec->autocfg.line_out_pins[0],
  1066. HDA_OUTPUT, 0, HDA_AMP_MUTE,
  1067. HDA_AMP_MUTE);
  1068. }
  1069. }
  1070. /* unsolicited event for jack sensing */
  1071. static void via_unsol_event(struct hda_codec *codec,
  1072. unsigned int res)
  1073. {
  1074. res >>= 26;
  1075. if (res == VIA_HP_EVENT)
  1076. via_hp_automute(codec);
  1077. else if (res == VIA_GPIO_EVENT)
  1078. via_gpio_control(codec);
  1079. }
  1080. static int via_init(struct hda_codec *codec)
  1081. {
  1082. struct via_spec *spec = codec->spec;
  1083. int i;
  1084. for (i = 0; i < spec->num_iverbs; i++)
  1085. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  1086. spec->codec_type = get_codec_type(codec);
  1087. if (spec->codec_type == VT1708BCE)
  1088. spec->codec_type = VT1708S; /* VT1708BCE & VT1708S are almost
  1089. same */
  1090. /* Lydia Add for EAPD enable */
  1091. if (!spec->dig_in_nid) { /* No Digital In connection */
  1092. if (spec->dig_in_pin) {
  1093. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  1094. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1095. PIN_OUT);
  1096. snd_hda_codec_write(codec, spec->dig_in_pin, 0,
  1097. AC_VERB_SET_EAPD_BTLENABLE, 0x02);
  1098. }
  1099. } else /* enable SPDIF-input pin */
  1100. snd_hda_codec_write(codec, spec->autocfg.dig_in_pin, 0,
  1101. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  1102. /* assign slave outs */
  1103. if (spec->slave_dig_outs[0])
  1104. codec->slave_dig_outs = spec->slave_dig_outs;
  1105. return 0;
  1106. }
  1107. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1108. static int via_check_power_status(struct hda_codec *codec, hda_nid_t nid)
  1109. {
  1110. struct via_spec *spec = codec->spec;
  1111. return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
  1112. }
  1113. #endif
  1114. /*
  1115. */
  1116. static struct hda_codec_ops via_patch_ops = {
  1117. .build_controls = via_build_controls,
  1118. .build_pcms = via_build_pcms,
  1119. .init = via_init,
  1120. .free = via_free,
  1121. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1122. .check_power_status = via_check_power_status,
  1123. #endif
  1124. };
  1125. /* fill in the dac_nids table from the parsed pin configuration */
  1126. static int vt1708_auto_fill_dac_nids(struct via_spec *spec,
  1127. const struct auto_pin_cfg *cfg)
  1128. {
  1129. int i;
  1130. hda_nid_t nid;
  1131. spec->multiout.num_dacs = cfg->line_outs;
  1132. spec->multiout.dac_nids = spec->private_dac_nids;
  1133. for(i = 0; i < 4; i++) {
  1134. nid = cfg->line_out_pins[i];
  1135. if (nid) {
  1136. /* config dac list */
  1137. switch (i) {
  1138. case AUTO_SEQ_FRONT:
  1139. spec->multiout.dac_nids[i] = 0x10;
  1140. break;
  1141. case AUTO_SEQ_CENLFE:
  1142. spec->multiout.dac_nids[i] = 0x12;
  1143. break;
  1144. case AUTO_SEQ_SURROUND:
  1145. spec->multiout.dac_nids[i] = 0x11;
  1146. break;
  1147. case AUTO_SEQ_SIDE:
  1148. spec->multiout.dac_nids[i] = 0x13;
  1149. break;
  1150. }
  1151. }
  1152. }
  1153. return 0;
  1154. }
  1155. /* add playback controls from the parsed DAC table */
  1156. static int vt1708_auto_create_multi_out_ctls(struct via_spec *spec,
  1157. const struct auto_pin_cfg *cfg)
  1158. {
  1159. char name[32];
  1160. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  1161. hda_nid_t nid, nid_vol = 0;
  1162. int i, err;
  1163. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  1164. nid = cfg->line_out_pins[i];
  1165. if (!nid)
  1166. continue;
  1167. if (i != AUTO_SEQ_FRONT)
  1168. nid_vol = 0x18 + i;
  1169. if (i == AUTO_SEQ_CENLFE) {
  1170. /* Center/LFE */
  1171. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1172. "Center Playback Volume",
  1173. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  1174. HDA_OUTPUT));
  1175. if (err < 0)
  1176. return err;
  1177. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1178. "LFE Playback Volume",
  1179. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  1180. HDA_OUTPUT));
  1181. if (err < 0)
  1182. return err;
  1183. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1184. "Center Playback Switch",
  1185. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  1186. HDA_OUTPUT));
  1187. if (err < 0)
  1188. return err;
  1189. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1190. "LFE Playback Switch",
  1191. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  1192. HDA_OUTPUT));
  1193. if (err < 0)
  1194. return err;
  1195. } else if (i == AUTO_SEQ_FRONT){
  1196. /* add control to mixer index 0 */
  1197. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1198. "Master Front Playback Volume",
  1199. HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
  1200. HDA_INPUT));
  1201. if (err < 0)
  1202. return err;
  1203. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1204. "Master Front Playback Switch",
  1205. HDA_COMPOSE_AMP_VAL(0x17, 3, 0,
  1206. HDA_INPUT));
  1207. if (err < 0)
  1208. return err;
  1209. /* add control to PW3 */
  1210. sprintf(name, "%s Playback Volume", chname[i]);
  1211. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1212. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1213. HDA_OUTPUT));
  1214. if (err < 0)
  1215. return err;
  1216. sprintf(name, "%s Playback Switch", chname[i]);
  1217. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1218. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1219. HDA_OUTPUT));
  1220. if (err < 0)
  1221. return err;
  1222. } else {
  1223. sprintf(name, "%s Playback Volume", chname[i]);
  1224. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1225. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1226. HDA_OUTPUT));
  1227. if (err < 0)
  1228. return err;
  1229. sprintf(name, "%s Playback Switch", chname[i]);
  1230. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1231. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  1232. HDA_OUTPUT));
  1233. if (err < 0)
  1234. return err;
  1235. }
  1236. }
  1237. return 0;
  1238. }
  1239. static void create_hp_imux(struct via_spec *spec)
  1240. {
  1241. int i;
  1242. struct hda_input_mux *imux = &spec->private_imux[1];
  1243. static const char *texts[] = { "OFF", "ON", NULL};
  1244. /* for hp mode select */
  1245. i = 0;
  1246. while (texts[i] != NULL) {
  1247. imux->items[imux->num_items].label = texts[i];
  1248. imux->items[imux->num_items].index = i;
  1249. imux->num_items++;
  1250. i++;
  1251. }
  1252. spec->hp_mux = &spec->private_imux[1];
  1253. }
  1254. static int vt1708_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  1255. {
  1256. int err;
  1257. if (!pin)
  1258. return 0;
  1259. spec->multiout.hp_nid = VT1708_HP_NID; /* AOW3 */
  1260. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1261. "Headphone Playback Volume",
  1262. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1263. if (err < 0)
  1264. return err;
  1265. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1266. "Headphone Playback Switch",
  1267. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1268. if (err < 0)
  1269. return err;
  1270. create_hp_imux(spec);
  1271. return 0;
  1272. }
  1273. /* create playback/capture controls for input pins */
  1274. static int vt1708_auto_create_analog_input_ctls(struct via_spec *spec,
  1275. const struct auto_pin_cfg *cfg)
  1276. {
  1277. static char *labels[] = {
  1278. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  1279. };
  1280. struct hda_input_mux *imux = &spec->private_imux[0];
  1281. int i, err, idx = 0;
  1282. /* for internal loopback recording select */
  1283. imux->items[imux->num_items].label = "Stereo Mixer";
  1284. imux->items[imux->num_items].index = idx;
  1285. imux->num_items++;
  1286. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1287. if (!cfg->input_pins[i])
  1288. continue;
  1289. switch (cfg->input_pins[i]) {
  1290. case 0x1d: /* Mic */
  1291. idx = 2;
  1292. break;
  1293. case 0x1e: /* Line In */
  1294. idx = 3;
  1295. break;
  1296. case 0x21: /* Front Mic */
  1297. idx = 4;
  1298. break;
  1299. case 0x24: /* CD */
  1300. idx = 1;
  1301. break;
  1302. }
  1303. err = via_new_analog_input(spec, labels[i], idx, 0x17);
  1304. if (err < 0)
  1305. return err;
  1306. imux->items[imux->num_items].label = labels[i];
  1307. imux->items[imux->num_items].index = idx;
  1308. imux->num_items++;
  1309. }
  1310. return 0;
  1311. }
  1312. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1313. static struct hda_amp_list vt1708_loopbacks[] = {
  1314. { 0x17, HDA_INPUT, 1 },
  1315. { 0x17, HDA_INPUT, 2 },
  1316. { 0x17, HDA_INPUT, 3 },
  1317. { 0x17, HDA_INPUT, 4 },
  1318. { } /* end */
  1319. };
  1320. #endif
  1321. static void vt1708_set_pinconfig_connect(struct hda_codec *codec, hda_nid_t nid)
  1322. {
  1323. unsigned int def_conf;
  1324. unsigned char seqassoc;
  1325. def_conf = snd_hda_codec_get_pincfg(codec, nid);
  1326. seqassoc = (unsigned char) get_defcfg_association(def_conf);
  1327. seqassoc = (seqassoc << 4) | get_defcfg_sequence(def_conf);
  1328. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE) {
  1329. if (seqassoc == 0xff) {
  1330. def_conf = def_conf & (~(AC_JACK_PORT_BOTH << 30));
  1331. snd_hda_codec_set_pincfg(codec, nid, def_conf);
  1332. }
  1333. }
  1334. return;
  1335. }
  1336. static int vt1708_parse_auto_config(struct hda_codec *codec)
  1337. {
  1338. struct via_spec *spec = codec->spec;
  1339. int err;
  1340. /* Add HP and CD pin config connect bit re-config action */
  1341. vt1708_set_pinconfig_connect(codec, VT1708_HP_PIN_NID);
  1342. vt1708_set_pinconfig_connect(codec, VT1708_CD_PIN_NID);
  1343. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  1344. if (err < 0)
  1345. return err;
  1346. err = vt1708_auto_fill_dac_nids(spec, &spec->autocfg);
  1347. if (err < 0)
  1348. return err;
  1349. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  1350. return 0; /* can't find valid BIOS pin config */
  1351. err = vt1708_auto_create_multi_out_ctls(spec, &spec->autocfg);
  1352. if (err < 0)
  1353. return err;
  1354. err = vt1708_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  1355. if (err < 0)
  1356. return err;
  1357. err = vt1708_auto_create_analog_input_ctls(spec, &spec->autocfg);
  1358. if (err < 0)
  1359. return err;
  1360. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1361. if (spec->autocfg.dig_outs)
  1362. spec->multiout.dig_out_nid = VT1708_DIGOUT_NID;
  1363. spec->dig_in_pin = VT1708_DIGIN_PIN;
  1364. if (spec->autocfg.dig_in_pin)
  1365. spec->dig_in_nid = VT1708_DIGIN_NID;
  1366. if (spec->kctls.list)
  1367. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  1368. spec->init_verbs[spec->num_iverbs++] = vt1708_volume_init_verbs;
  1369. spec->input_mux = &spec->private_imux[0];
  1370. if (spec->hp_mux)
  1371. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  1372. return 1;
  1373. }
  1374. /* init callback for auto-configuration model -- overriding the default init */
  1375. static int via_auto_init(struct hda_codec *codec)
  1376. {
  1377. via_init(codec);
  1378. via_auto_init_multi_out(codec);
  1379. via_auto_init_hp_out(codec);
  1380. via_auto_init_analog_input(codec);
  1381. return 0;
  1382. }
  1383. static int get_mux_nids(struct hda_codec *codec)
  1384. {
  1385. struct via_spec *spec = codec->spec;
  1386. hda_nid_t nid, conn[8];
  1387. unsigned int type;
  1388. int i, n;
  1389. for (i = 0; i < spec->num_adc_nids; i++) {
  1390. nid = spec->adc_nids[i];
  1391. while (nid) {
  1392. type = get_wcaps_type(get_wcaps(codec, nid));
  1393. if (type == AC_WID_PIN)
  1394. break;
  1395. n = snd_hda_get_connections(codec, nid, conn,
  1396. ARRAY_SIZE(conn));
  1397. if (n <= 0)
  1398. break;
  1399. if (n > 1) {
  1400. spec->mux_nids[i] = nid;
  1401. break;
  1402. }
  1403. nid = conn[0];
  1404. }
  1405. }
  1406. return 0;
  1407. }
  1408. static int patch_vt1708(struct hda_codec *codec)
  1409. {
  1410. struct via_spec *spec;
  1411. int err;
  1412. /* create a codec specific record */
  1413. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1414. if (spec == NULL)
  1415. return -ENOMEM;
  1416. codec->spec = spec;
  1417. /* automatic parse from the BIOS config */
  1418. err = vt1708_parse_auto_config(codec);
  1419. if (err < 0) {
  1420. via_free(codec);
  1421. return err;
  1422. } else if (!err) {
  1423. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  1424. "from BIOS. Using genenic mode...\n");
  1425. }
  1426. spec->stream_name_analog = "VT1708 Analog";
  1427. spec->stream_analog_playback = &vt1708_pcm_analog_playback;
  1428. /* disable 32bit format on VT1708 */
  1429. if (codec->vendor_id == 0x11061708)
  1430. spec->stream_analog_playback = &vt1708_pcm_analog_s16_playback;
  1431. spec->stream_analog_capture = &vt1708_pcm_analog_capture;
  1432. spec->stream_name_digital = "VT1708 Digital";
  1433. spec->stream_digital_playback = &vt1708_pcm_digital_playback;
  1434. spec->stream_digital_capture = &vt1708_pcm_digital_capture;
  1435. if (!spec->adc_nids && spec->input_mux) {
  1436. spec->adc_nids = vt1708_adc_nids;
  1437. spec->num_adc_nids = ARRAY_SIZE(vt1708_adc_nids);
  1438. get_mux_nids(codec);
  1439. spec->mixers[spec->num_mixers] = vt1708_capture_mixer;
  1440. spec->num_mixers++;
  1441. }
  1442. codec->patch_ops = via_patch_ops;
  1443. codec->patch_ops.init = via_auto_init;
  1444. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1445. spec->loopback.amplist = vt1708_loopbacks;
  1446. #endif
  1447. return 0;
  1448. }
  1449. /* capture mixer elements */
  1450. static struct snd_kcontrol_new vt1709_capture_mixer[] = {
  1451. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x0, HDA_INPUT),
  1452. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x0, HDA_INPUT),
  1453. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x15, 0x0, HDA_INPUT),
  1454. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x15, 0x0, HDA_INPUT),
  1455. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x16, 0x0, HDA_INPUT),
  1456. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x16, 0x0, HDA_INPUT),
  1457. {
  1458. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1459. /* The multiple "Capture Source" controls confuse alsamixer
  1460. * So call somewhat different..
  1461. */
  1462. /* .name = "Capture Source", */
  1463. .name = "Input Source",
  1464. .count = 1,
  1465. .info = via_mux_enum_info,
  1466. .get = via_mux_enum_get,
  1467. .put = via_mux_enum_put,
  1468. },
  1469. { } /* end */
  1470. };
  1471. static struct hda_verb vt1709_uniwill_init_verbs[] = {
  1472. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  1473. { }
  1474. };
  1475. /*
  1476. * generic initialization of ADC, input mixers and output mixers
  1477. */
  1478. static struct hda_verb vt1709_10ch_volume_init_verbs[] = {
  1479. /*
  1480. * Unmute ADC0-2 and set the default input to mic-in
  1481. */
  1482. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1483. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1484. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1485. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1486. * mixer widget
  1487. */
  1488. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1489. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1490. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1491. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1492. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1493. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1494. /*
  1495. * Set up output selector (0x1a, 0x1b, 0x29)
  1496. */
  1497. /* set vol=0 to output mixers */
  1498. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1499. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1500. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1501. /*
  1502. * Unmute PW3 and PW4
  1503. */
  1504. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1505. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1506. /* Set input of PW4 as AOW4 */
  1507. {0x20, AC_VERB_SET_CONNECT_SEL, 0x1},
  1508. /* PW9 Output enable */
  1509. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1510. { }
  1511. };
  1512. static struct hda_pcm_stream vt1709_10ch_pcm_analog_playback = {
  1513. .substreams = 1,
  1514. .channels_min = 2,
  1515. .channels_max = 10,
  1516. .nid = 0x10, /* NID to query formats and rates */
  1517. .ops = {
  1518. .open = via_playback_pcm_open,
  1519. .prepare = via_playback_pcm_prepare,
  1520. .cleanup = via_playback_pcm_cleanup
  1521. },
  1522. };
  1523. static struct hda_pcm_stream vt1709_6ch_pcm_analog_playback = {
  1524. .substreams = 1,
  1525. .channels_min = 2,
  1526. .channels_max = 6,
  1527. .nid = 0x10, /* NID to query formats and rates */
  1528. .ops = {
  1529. .open = via_playback_pcm_open,
  1530. .prepare = via_playback_pcm_prepare,
  1531. .cleanup = via_playback_pcm_cleanup
  1532. },
  1533. };
  1534. static struct hda_pcm_stream vt1709_pcm_analog_capture = {
  1535. .substreams = 2,
  1536. .channels_min = 2,
  1537. .channels_max = 2,
  1538. .nid = 0x14, /* NID to query formats and rates */
  1539. .ops = {
  1540. .prepare = via_capture_pcm_prepare,
  1541. .cleanup = via_capture_pcm_cleanup
  1542. },
  1543. };
  1544. static struct hda_pcm_stream vt1709_pcm_digital_playback = {
  1545. .substreams = 1,
  1546. .channels_min = 2,
  1547. .channels_max = 2,
  1548. /* NID is set in via_build_pcms */
  1549. .ops = {
  1550. .open = via_dig_playback_pcm_open,
  1551. .close = via_dig_playback_pcm_close
  1552. },
  1553. };
  1554. static struct hda_pcm_stream vt1709_pcm_digital_capture = {
  1555. .substreams = 1,
  1556. .channels_min = 2,
  1557. .channels_max = 2,
  1558. };
  1559. static int vt1709_auto_fill_dac_nids(struct via_spec *spec,
  1560. const struct auto_pin_cfg *cfg)
  1561. {
  1562. int i;
  1563. hda_nid_t nid;
  1564. if (cfg->line_outs == 4) /* 10 channels */
  1565. spec->multiout.num_dacs = cfg->line_outs+1; /* AOW0~AOW4 */
  1566. else if (cfg->line_outs == 3) /* 6 channels */
  1567. spec->multiout.num_dacs = cfg->line_outs; /* AOW0~AOW2 */
  1568. spec->multiout.dac_nids = spec->private_dac_nids;
  1569. if (cfg->line_outs == 4) { /* 10 channels */
  1570. for (i = 0; i < cfg->line_outs; i++) {
  1571. nid = cfg->line_out_pins[i];
  1572. if (nid) {
  1573. /* config dac list */
  1574. switch (i) {
  1575. case AUTO_SEQ_FRONT:
  1576. /* AOW0 */
  1577. spec->multiout.dac_nids[i] = 0x10;
  1578. break;
  1579. case AUTO_SEQ_CENLFE:
  1580. /* AOW2 */
  1581. spec->multiout.dac_nids[i] = 0x12;
  1582. break;
  1583. case AUTO_SEQ_SURROUND:
  1584. /* AOW3 */
  1585. spec->multiout.dac_nids[i] = 0x11;
  1586. break;
  1587. case AUTO_SEQ_SIDE:
  1588. /* AOW1 */
  1589. spec->multiout.dac_nids[i] = 0x27;
  1590. break;
  1591. default:
  1592. break;
  1593. }
  1594. }
  1595. }
  1596. spec->multiout.dac_nids[cfg->line_outs] = 0x28; /* AOW4 */
  1597. } else if (cfg->line_outs == 3) { /* 6 channels */
  1598. for(i = 0; i < cfg->line_outs; i++) {
  1599. nid = cfg->line_out_pins[i];
  1600. if (nid) {
  1601. /* config dac list */
  1602. switch(i) {
  1603. case AUTO_SEQ_FRONT:
  1604. /* AOW0 */
  1605. spec->multiout.dac_nids[i] = 0x10;
  1606. break;
  1607. case AUTO_SEQ_CENLFE:
  1608. /* AOW2 */
  1609. spec->multiout.dac_nids[i] = 0x12;
  1610. break;
  1611. case AUTO_SEQ_SURROUND:
  1612. /* AOW1 */
  1613. spec->multiout.dac_nids[i] = 0x11;
  1614. break;
  1615. default:
  1616. break;
  1617. }
  1618. }
  1619. }
  1620. }
  1621. return 0;
  1622. }
  1623. /* add playback controls from the parsed DAC table */
  1624. static int vt1709_auto_create_multi_out_ctls(struct via_spec *spec,
  1625. const struct auto_pin_cfg *cfg)
  1626. {
  1627. char name[32];
  1628. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  1629. hda_nid_t nid = 0;
  1630. int i, err;
  1631. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  1632. nid = cfg->line_out_pins[i];
  1633. if (!nid)
  1634. continue;
  1635. if (i == AUTO_SEQ_CENLFE) {
  1636. /* Center/LFE */
  1637. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1638. "Center Playback Volume",
  1639. HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
  1640. HDA_OUTPUT));
  1641. if (err < 0)
  1642. return err;
  1643. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1644. "LFE Playback Volume",
  1645. HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
  1646. HDA_OUTPUT));
  1647. if (err < 0)
  1648. return err;
  1649. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1650. "Center Playback Switch",
  1651. HDA_COMPOSE_AMP_VAL(0x1b, 1, 0,
  1652. HDA_OUTPUT));
  1653. if (err < 0)
  1654. return err;
  1655. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1656. "LFE Playback Switch",
  1657. HDA_COMPOSE_AMP_VAL(0x1b, 2, 0,
  1658. HDA_OUTPUT));
  1659. if (err < 0)
  1660. return err;
  1661. } else if (i == AUTO_SEQ_FRONT){
  1662. /* add control to mixer index 0 */
  1663. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1664. "Master Front Playback Volume",
  1665. HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
  1666. HDA_INPUT));
  1667. if (err < 0)
  1668. return err;
  1669. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1670. "Master Front Playback Switch",
  1671. HDA_COMPOSE_AMP_VAL(0x18, 3, 0,
  1672. HDA_INPUT));
  1673. if (err < 0)
  1674. return err;
  1675. /* add control to PW3 */
  1676. sprintf(name, "%s Playback Volume", chname[i]);
  1677. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1678. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1679. HDA_OUTPUT));
  1680. if (err < 0)
  1681. return err;
  1682. sprintf(name, "%s Playback Switch", chname[i]);
  1683. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1684. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  1685. HDA_OUTPUT));
  1686. if (err < 0)
  1687. return err;
  1688. } else if (i == AUTO_SEQ_SURROUND) {
  1689. sprintf(name, "%s Playback Volume", chname[i]);
  1690. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1691. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
  1692. HDA_OUTPUT));
  1693. if (err < 0)
  1694. return err;
  1695. sprintf(name, "%s Playback Switch", chname[i]);
  1696. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1697. HDA_COMPOSE_AMP_VAL(0x1a, 3, 0,
  1698. HDA_OUTPUT));
  1699. if (err < 0)
  1700. return err;
  1701. } else if (i == AUTO_SEQ_SIDE) {
  1702. sprintf(name, "%s Playback Volume", chname[i]);
  1703. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  1704. HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
  1705. HDA_OUTPUT));
  1706. if (err < 0)
  1707. return err;
  1708. sprintf(name, "%s Playback Switch", chname[i]);
  1709. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  1710. HDA_COMPOSE_AMP_VAL(0x29, 3, 0,
  1711. HDA_OUTPUT));
  1712. if (err < 0)
  1713. return err;
  1714. }
  1715. }
  1716. return 0;
  1717. }
  1718. static int vt1709_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  1719. {
  1720. int err;
  1721. if (!pin)
  1722. return 0;
  1723. if (spec->multiout.num_dacs == 5) /* 10 channels */
  1724. spec->multiout.hp_nid = VT1709_HP_DAC_NID;
  1725. else if (spec->multiout.num_dacs == 3) /* 6 channels */
  1726. spec->multiout.hp_nid = 0;
  1727. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  1728. "Headphone Playback Volume",
  1729. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1730. if (err < 0)
  1731. return err;
  1732. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  1733. "Headphone Playback Switch",
  1734. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  1735. if (err < 0)
  1736. return err;
  1737. return 0;
  1738. }
  1739. /* create playback/capture controls for input pins */
  1740. static int vt1709_auto_create_analog_input_ctls(struct via_spec *spec,
  1741. const struct auto_pin_cfg *cfg)
  1742. {
  1743. static char *labels[] = {
  1744. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  1745. };
  1746. struct hda_input_mux *imux = &spec->private_imux[0];
  1747. int i, err, idx = 0;
  1748. /* for internal loopback recording select */
  1749. imux->items[imux->num_items].label = "Stereo Mixer";
  1750. imux->items[imux->num_items].index = idx;
  1751. imux->num_items++;
  1752. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1753. if (!cfg->input_pins[i])
  1754. continue;
  1755. switch (cfg->input_pins[i]) {
  1756. case 0x1d: /* Mic */
  1757. idx = 2;
  1758. break;
  1759. case 0x1e: /* Line In */
  1760. idx = 3;
  1761. break;
  1762. case 0x21: /* Front Mic */
  1763. idx = 4;
  1764. break;
  1765. case 0x23: /* CD */
  1766. idx = 1;
  1767. break;
  1768. }
  1769. err = via_new_analog_input(spec, labels[i], idx, 0x18);
  1770. if (err < 0)
  1771. return err;
  1772. imux->items[imux->num_items].label = labels[i];
  1773. imux->items[imux->num_items].index = idx;
  1774. imux->num_items++;
  1775. }
  1776. return 0;
  1777. }
  1778. static int vt1709_parse_auto_config(struct hda_codec *codec)
  1779. {
  1780. struct via_spec *spec = codec->spec;
  1781. int err;
  1782. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  1783. if (err < 0)
  1784. return err;
  1785. err = vt1709_auto_fill_dac_nids(spec, &spec->autocfg);
  1786. if (err < 0)
  1787. return err;
  1788. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  1789. return 0; /* can't find valid BIOS pin config */
  1790. err = vt1709_auto_create_multi_out_ctls(spec, &spec->autocfg);
  1791. if (err < 0)
  1792. return err;
  1793. err = vt1709_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  1794. if (err < 0)
  1795. return err;
  1796. err = vt1709_auto_create_analog_input_ctls(spec, &spec->autocfg);
  1797. if (err < 0)
  1798. return err;
  1799. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1800. if (spec->autocfg.dig_outs)
  1801. spec->multiout.dig_out_nid = VT1709_DIGOUT_NID;
  1802. spec->dig_in_pin = VT1709_DIGIN_PIN;
  1803. if (spec->autocfg.dig_in_pin)
  1804. spec->dig_in_nid = VT1709_DIGIN_NID;
  1805. if (spec->kctls.list)
  1806. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  1807. spec->input_mux = &spec->private_imux[0];
  1808. if (spec->hp_mux)
  1809. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  1810. return 1;
  1811. }
  1812. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1813. static struct hda_amp_list vt1709_loopbacks[] = {
  1814. { 0x18, HDA_INPUT, 1 },
  1815. { 0x18, HDA_INPUT, 2 },
  1816. { 0x18, HDA_INPUT, 3 },
  1817. { 0x18, HDA_INPUT, 4 },
  1818. { } /* end */
  1819. };
  1820. #endif
  1821. static int patch_vt1709_10ch(struct hda_codec *codec)
  1822. {
  1823. struct via_spec *spec;
  1824. int err;
  1825. /* create a codec specific record */
  1826. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1827. if (spec == NULL)
  1828. return -ENOMEM;
  1829. codec->spec = spec;
  1830. err = vt1709_parse_auto_config(codec);
  1831. if (err < 0) {
  1832. via_free(codec);
  1833. return err;
  1834. } else if (!err) {
  1835. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  1836. "Using genenic mode...\n");
  1837. }
  1838. spec->init_verbs[spec->num_iverbs++] = vt1709_10ch_volume_init_verbs;
  1839. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  1840. spec->stream_name_analog = "VT1709 Analog";
  1841. spec->stream_analog_playback = &vt1709_10ch_pcm_analog_playback;
  1842. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  1843. spec->stream_name_digital = "VT1709 Digital";
  1844. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  1845. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  1846. if (!spec->adc_nids && spec->input_mux) {
  1847. spec->adc_nids = vt1709_adc_nids;
  1848. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  1849. get_mux_nids(codec);
  1850. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  1851. spec->num_mixers++;
  1852. }
  1853. codec->patch_ops = via_patch_ops;
  1854. codec->patch_ops.init = via_auto_init;
  1855. codec->patch_ops.unsol_event = via_unsol_event;
  1856. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1857. spec->loopback.amplist = vt1709_loopbacks;
  1858. #endif
  1859. return 0;
  1860. }
  1861. /*
  1862. * generic initialization of ADC, input mixers and output mixers
  1863. */
  1864. static struct hda_verb vt1709_6ch_volume_init_verbs[] = {
  1865. /*
  1866. * Unmute ADC0-2 and set the default input to mic-in
  1867. */
  1868. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1869. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1870. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1871. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1872. * mixer widget
  1873. */
  1874. /* Amp Indices: AOW0=0, CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1875. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1876. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1877. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1878. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1879. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1880. /*
  1881. * Set up output selector (0x1a, 0x1b, 0x29)
  1882. */
  1883. /* set vol=0 to output mixers */
  1884. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1885. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1886. {0x29, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1887. /*
  1888. * Unmute PW3 and PW4
  1889. */
  1890. {0x1f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1891. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1892. /* Set input of PW4 as MW0 */
  1893. {0x20, AC_VERB_SET_CONNECT_SEL, 0},
  1894. /* PW9 Output enable */
  1895. {0x24, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1896. { }
  1897. };
  1898. static int patch_vt1709_6ch(struct hda_codec *codec)
  1899. {
  1900. struct via_spec *spec;
  1901. int err;
  1902. /* create a codec specific record */
  1903. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1904. if (spec == NULL)
  1905. return -ENOMEM;
  1906. codec->spec = spec;
  1907. err = vt1709_parse_auto_config(codec);
  1908. if (err < 0) {
  1909. via_free(codec);
  1910. return err;
  1911. } else if (!err) {
  1912. printk(KERN_INFO "hda_codec: Cannot set up configuration. "
  1913. "Using genenic mode...\n");
  1914. }
  1915. spec->init_verbs[spec->num_iverbs++] = vt1709_6ch_volume_init_verbs;
  1916. spec->init_verbs[spec->num_iverbs++] = vt1709_uniwill_init_verbs;
  1917. spec->stream_name_analog = "VT1709 Analog";
  1918. spec->stream_analog_playback = &vt1709_6ch_pcm_analog_playback;
  1919. spec->stream_analog_capture = &vt1709_pcm_analog_capture;
  1920. spec->stream_name_digital = "VT1709 Digital";
  1921. spec->stream_digital_playback = &vt1709_pcm_digital_playback;
  1922. spec->stream_digital_capture = &vt1709_pcm_digital_capture;
  1923. if (!spec->adc_nids && spec->input_mux) {
  1924. spec->adc_nids = vt1709_adc_nids;
  1925. spec->num_adc_nids = ARRAY_SIZE(vt1709_adc_nids);
  1926. get_mux_nids(codec);
  1927. spec->mixers[spec->num_mixers] = vt1709_capture_mixer;
  1928. spec->num_mixers++;
  1929. }
  1930. codec->patch_ops = via_patch_ops;
  1931. codec->patch_ops.init = via_auto_init;
  1932. codec->patch_ops.unsol_event = via_unsol_event;
  1933. #ifdef CONFIG_SND_HDA_POWER_SAVE
  1934. spec->loopback.amplist = vt1709_loopbacks;
  1935. #endif
  1936. return 0;
  1937. }
  1938. /* capture mixer elements */
  1939. static struct snd_kcontrol_new vt1708B_capture_mixer[] = {
  1940. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  1941. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  1942. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  1943. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  1944. {
  1945. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1946. /* The multiple "Capture Source" controls confuse alsamixer
  1947. * So call somewhat different..
  1948. */
  1949. /* .name = "Capture Source", */
  1950. .name = "Input Source",
  1951. .count = 1,
  1952. .info = via_mux_enum_info,
  1953. .get = via_mux_enum_get,
  1954. .put = via_mux_enum_put,
  1955. },
  1956. { } /* end */
  1957. };
  1958. /*
  1959. * generic initialization of ADC, input mixers and output mixers
  1960. */
  1961. static struct hda_verb vt1708B_8ch_volume_init_verbs[] = {
  1962. /*
  1963. * Unmute ADC0-1 and set the default input to mic-in
  1964. */
  1965. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1966. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1967. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1968. * mixer widget
  1969. */
  1970. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  1971. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1972. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1973. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  1974. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  1975. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  1976. /*
  1977. * Set up output mixers
  1978. */
  1979. /* set vol=0 to output mixers */
  1980. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1981. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1982. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1983. /* Setup default input to PW4 */
  1984. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1},
  1985. /* PW9 Output enable */
  1986. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  1987. /* PW10 Input enable */
  1988. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  1989. { }
  1990. };
  1991. static struct hda_verb vt1708B_4ch_volume_init_verbs[] = {
  1992. /*
  1993. * Unmute ADC0-1 and set the default input to mic-in
  1994. */
  1995. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1996. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1997. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  1998. * mixer widget
  1999. */
  2000. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2001. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2002. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2003. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2004. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2005. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2006. /*
  2007. * Set up output mixers
  2008. */
  2009. /* set vol=0 to output mixers */
  2010. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2011. {0x26, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2012. {0x27, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2013. /* Setup default input of PW4 to MW0 */
  2014. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  2015. /* PW9 Output enable */
  2016. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2017. /* PW10 Input enable */
  2018. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
  2019. { }
  2020. };
  2021. static struct hda_verb vt1708B_uniwill_init_verbs[] = {
  2022. {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  2023. { }
  2024. };
  2025. static int via_pcm_open_close(struct hda_pcm_stream *hinfo,
  2026. struct hda_codec *codec,
  2027. struct snd_pcm_substream *substream)
  2028. {
  2029. int idle = substream->pstr->substream_opened == 1
  2030. && substream->ref_count == 0;
  2031. analog_low_current_mode(codec, idle);
  2032. return 0;
  2033. }
  2034. static struct hda_pcm_stream vt1708B_8ch_pcm_analog_playback = {
  2035. .substreams = 2,
  2036. .channels_min = 2,
  2037. .channels_max = 8,
  2038. .nid = 0x10, /* NID to query formats and rates */
  2039. .ops = {
  2040. .open = via_playback_pcm_open,
  2041. .prepare = via_playback_multi_pcm_prepare,
  2042. .cleanup = via_playback_multi_pcm_cleanup,
  2043. .close = via_pcm_open_close
  2044. },
  2045. };
  2046. static struct hda_pcm_stream vt1708B_4ch_pcm_analog_playback = {
  2047. .substreams = 2,
  2048. .channels_min = 2,
  2049. .channels_max = 4,
  2050. .nid = 0x10, /* NID to query formats and rates */
  2051. .ops = {
  2052. .open = via_playback_pcm_open,
  2053. .prepare = via_playback_multi_pcm_prepare,
  2054. .cleanup = via_playback_multi_pcm_cleanup
  2055. },
  2056. };
  2057. static struct hda_pcm_stream vt1708B_pcm_analog_capture = {
  2058. .substreams = 2,
  2059. .channels_min = 2,
  2060. .channels_max = 2,
  2061. .nid = 0x13, /* NID to query formats and rates */
  2062. .ops = {
  2063. .open = via_pcm_open_close,
  2064. .prepare = via_capture_pcm_prepare,
  2065. .cleanup = via_capture_pcm_cleanup,
  2066. .close = via_pcm_open_close
  2067. },
  2068. };
  2069. static struct hda_pcm_stream vt1708B_pcm_digital_playback = {
  2070. .substreams = 1,
  2071. .channels_min = 2,
  2072. .channels_max = 2,
  2073. /* NID is set in via_build_pcms */
  2074. .ops = {
  2075. .open = via_dig_playback_pcm_open,
  2076. .close = via_dig_playback_pcm_close,
  2077. .prepare = via_dig_playback_pcm_prepare,
  2078. .cleanup = via_dig_playback_pcm_cleanup
  2079. },
  2080. };
  2081. static struct hda_pcm_stream vt1708B_pcm_digital_capture = {
  2082. .substreams = 1,
  2083. .channels_min = 2,
  2084. .channels_max = 2,
  2085. };
  2086. /* fill in the dac_nids table from the parsed pin configuration */
  2087. static int vt1708B_auto_fill_dac_nids(struct via_spec *spec,
  2088. const struct auto_pin_cfg *cfg)
  2089. {
  2090. int i;
  2091. hda_nid_t nid;
  2092. spec->multiout.num_dacs = cfg->line_outs;
  2093. spec->multiout.dac_nids = spec->private_dac_nids;
  2094. for (i = 0; i < 4; i++) {
  2095. nid = cfg->line_out_pins[i];
  2096. if (nid) {
  2097. /* config dac list */
  2098. switch (i) {
  2099. case AUTO_SEQ_FRONT:
  2100. spec->multiout.dac_nids[i] = 0x10;
  2101. break;
  2102. case AUTO_SEQ_CENLFE:
  2103. spec->multiout.dac_nids[i] = 0x24;
  2104. break;
  2105. case AUTO_SEQ_SURROUND:
  2106. spec->multiout.dac_nids[i] = 0x11;
  2107. break;
  2108. case AUTO_SEQ_SIDE:
  2109. spec->multiout.dac_nids[i] = 0x25;
  2110. break;
  2111. }
  2112. }
  2113. }
  2114. return 0;
  2115. }
  2116. /* add playback controls from the parsed DAC table */
  2117. static int vt1708B_auto_create_multi_out_ctls(struct via_spec *spec,
  2118. const struct auto_pin_cfg *cfg)
  2119. {
  2120. char name[32];
  2121. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  2122. hda_nid_t nid_vols[] = {0x16, 0x18, 0x26, 0x27};
  2123. hda_nid_t nid, nid_vol = 0;
  2124. int i, err;
  2125. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2126. nid = cfg->line_out_pins[i];
  2127. if (!nid)
  2128. continue;
  2129. nid_vol = nid_vols[i];
  2130. if (i == AUTO_SEQ_CENLFE) {
  2131. /* Center/LFE */
  2132. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2133. "Center Playback Volume",
  2134. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2135. HDA_OUTPUT));
  2136. if (err < 0)
  2137. return err;
  2138. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2139. "LFE Playback Volume",
  2140. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2141. HDA_OUTPUT));
  2142. if (err < 0)
  2143. return err;
  2144. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2145. "Center Playback Switch",
  2146. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2147. HDA_OUTPUT));
  2148. if (err < 0)
  2149. return err;
  2150. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2151. "LFE Playback Switch",
  2152. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2153. HDA_OUTPUT));
  2154. if (err < 0)
  2155. return err;
  2156. } else if (i == AUTO_SEQ_FRONT) {
  2157. /* add control to mixer index 0 */
  2158. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2159. "Master Front Playback Volume",
  2160. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2161. HDA_INPUT));
  2162. if (err < 0)
  2163. return err;
  2164. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2165. "Master Front Playback Switch",
  2166. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2167. HDA_INPUT));
  2168. if (err < 0)
  2169. return err;
  2170. /* add control to PW3 */
  2171. sprintf(name, "%s Playback Volume", chname[i]);
  2172. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2173. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2174. HDA_OUTPUT));
  2175. if (err < 0)
  2176. return err;
  2177. sprintf(name, "%s Playback Switch", chname[i]);
  2178. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2179. HDA_COMPOSE_AMP_VAL(nid, 3, 0,
  2180. HDA_OUTPUT));
  2181. if (err < 0)
  2182. return err;
  2183. } else {
  2184. sprintf(name, "%s Playback Volume", chname[i]);
  2185. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2186. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2187. HDA_OUTPUT));
  2188. if (err < 0)
  2189. return err;
  2190. sprintf(name, "%s Playback Switch", chname[i]);
  2191. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2192. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2193. HDA_OUTPUT));
  2194. if (err < 0)
  2195. return err;
  2196. }
  2197. }
  2198. return 0;
  2199. }
  2200. static int vt1708B_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2201. {
  2202. int err;
  2203. if (!pin)
  2204. return 0;
  2205. spec->multiout.hp_nid = VT1708B_HP_NID; /* AOW3 */
  2206. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2207. "Headphone Playback Volume",
  2208. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2209. if (err < 0)
  2210. return err;
  2211. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2212. "Headphone Playback Switch",
  2213. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2214. if (err < 0)
  2215. return err;
  2216. create_hp_imux(spec);
  2217. return 0;
  2218. }
  2219. /* create playback/capture controls for input pins */
  2220. static int vt1708B_auto_create_analog_input_ctls(struct via_spec *spec,
  2221. const struct auto_pin_cfg *cfg)
  2222. {
  2223. static char *labels[] = {
  2224. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2225. };
  2226. struct hda_input_mux *imux = &spec->private_imux[0];
  2227. int i, err, idx = 0;
  2228. /* for internal loopback recording select */
  2229. imux->items[imux->num_items].label = "Stereo Mixer";
  2230. imux->items[imux->num_items].index = idx;
  2231. imux->num_items++;
  2232. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2233. if (!cfg->input_pins[i])
  2234. continue;
  2235. switch (cfg->input_pins[i]) {
  2236. case 0x1a: /* Mic */
  2237. idx = 2;
  2238. break;
  2239. case 0x1b: /* Line In */
  2240. idx = 3;
  2241. break;
  2242. case 0x1e: /* Front Mic */
  2243. idx = 4;
  2244. break;
  2245. case 0x1f: /* CD */
  2246. idx = 1;
  2247. break;
  2248. }
  2249. err = via_new_analog_input(spec, labels[i], idx, 0x16);
  2250. if (err < 0)
  2251. return err;
  2252. imux->items[imux->num_items].label = labels[i];
  2253. imux->items[imux->num_items].index = idx;
  2254. imux->num_items++;
  2255. }
  2256. return 0;
  2257. }
  2258. static int vt1708B_parse_auto_config(struct hda_codec *codec)
  2259. {
  2260. struct via_spec *spec = codec->spec;
  2261. int err;
  2262. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2263. if (err < 0)
  2264. return err;
  2265. err = vt1708B_auto_fill_dac_nids(spec, &spec->autocfg);
  2266. if (err < 0)
  2267. return err;
  2268. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2269. return 0; /* can't find valid BIOS pin config */
  2270. err = vt1708B_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2271. if (err < 0)
  2272. return err;
  2273. err = vt1708B_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2274. if (err < 0)
  2275. return err;
  2276. err = vt1708B_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2277. if (err < 0)
  2278. return err;
  2279. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2280. if (spec->autocfg.dig_outs)
  2281. spec->multiout.dig_out_nid = VT1708B_DIGOUT_NID;
  2282. spec->dig_in_pin = VT1708B_DIGIN_PIN;
  2283. if (spec->autocfg.dig_in_pin)
  2284. spec->dig_in_nid = VT1708B_DIGIN_NID;
  2285. if (spec->kctls.list)
  2286. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2287. spec->input_mux = &spec->private_imux[0];
  2288. if (spec->hp_mux)
  2289. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2290. return 1;
  2291. }
  2292. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2293. static struct hda_amp_list vt1708B_loopbacks[] = {
  2294. { 0x16, HDA_INPUT, 1 },
  2295. { 0x16, HDA_INPUT, 2 },
  2296. { 0x16, HDA_INPUT, 3 },
  2297. { 0x16, HDA_INPUT, 4 },
  2298. { } /* end */
  2299. };
  2300. #endif
  2301. static int patch_vt1708S(struct hda_codec *codec);
  2302. static int patch_vt1708B_8ch(struct hda_codec *codec)
  2303. {
  2304. struct via_spec *spec;
  2305. int err;
  2306. if (get_codec_type(codec) == VT1708BCE)
  2307. return patch_vt1708S(codec);
  2308. /* create a codec specific record */
  2309. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2310. if (spec == NULL)
  2311. return -ENOMEM;
  2312. codec->spec = spec;
  2313. /* automatic parse from the BIOS config */
  2314. err = vt1708B_parse_auto_config(codec);
  2315. if (err < 0) {
  2316. via_free(codec);
  2317. return err;
  2318. } else if (!err) {
  2319. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2320. "from BIOS. Using genenic mode...\n");
  2321. }
  2322. spec->init_verbs[spec->num_iverbs++] = vt1708B_8ch_volume_init_verbs;
  2323. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  2324. spec->stream_name_analog = "VT1708B Analog";
  2325. spec->stream_analog_playback = &vt1708B_8ch_pcm_analog_playback;
  2326. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  2327. spec->stream_name_digital = "VT1708B Digital";
  2328. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  2329. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  2330. if (!spec->adc_nids && spec->input_mux) {
  2331. spec->adc_nids = vt1708B_adc_nids;
  2332. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  2333. get_mux_nids(codec);
  2334. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  2335. spec->num_mixers++;
  2336. }
  2337. codec->patch_ops = via_patch_ops;
  2338. codec->patch_ops.init = via_auto_init;
  2339. codec->patch_ops.unsol_event = via_unsol_event;
  2340. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2341. spec->loopback.amplist = vt1708B_loopbacks;
  2342. #endif
  2343. return 0;
  2344. }
  2345. static int patch_vt1708B_4ch(struct hda_codec *codec)
  2346. {
  2347. struct via_spec *spec;
  2348. int err;
  2349. /* create a codec specific record */
  2350. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2351. if (spec == NULL)
  2352. return -ENOMEM;
  2353. codec->spec = spec;
  2354. /* automatic parse from the BIOS config */
  2355. err = vt1708B_parse_auto_config(codec);
  2356. if (err < 0) {
  2357. via_free(codec);
  2358. return err;
  2359. } else if (!err) {
  2360. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2361. "from BIOS. Using genenic mode...\n");
  2362. }
  2363. spec->init_verbs[spec->num_iverbs++] = vt1708B_4ch_volume_init_verbs;
  2364. spec->init_verbs[spec->num_iverbs++] = vt1708B_uniwill_init_verbs;
  2365. spec->stream_name_analog = "VT1708B Analog";
  2366. spec->stream_analog_playback = &vt1708B_4ch_pcm_analog_playback;
  2367. spec->stream_analog_capture = &vt1708B_pcm_analog_capture;
  2368. spec->stream_name_digital = "VT1708B Digital";
  2369. spec->stream_digital_playback = &vt1708B_pcm_digital_playback;
  2370. spec->stream_digital_capture = &vt1708B_pcm_digital_capture;
  2371. if (!spec->adc_nids && spec->input_mux) {
  2372. spec->adc_nids = vt1708B_adc_nids;
  2373. spec->num_adc_nids = ARRAY_SIZE(vt1708B_adc_nids);
  2374. get_mux_nids(codec);
  2375. spec->mixers[spec->num_mixers] = vt1708B_capture_mixer;
  2376. spec->num_mixers++;
  2377. }
  2378. codec->patch_ops = via_patch_ops;
  2379. codec->patch_ops.init = via_auto_init;
  2380. codec->patch_ops.unsol_event = via_unsol_event;
  2381. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2382. spec->loopback.amplist = vt1708B_loopbacks;
  2383. #endif
  2384. return 0;
  2385. }
  2386. /* Patch for VT1708S */
  2387. /* VT1708S software backdoor based override for buggy hardware micboost
  2388. * setting */
  2389. #define MIC_BOOST_VOLUME(xname, nid) { \
  2390. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  2391. .name = xname, \
  2392. .index = 0, \
  2393. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
  2394. SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  2395. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
  2396. .info = mic_boost_volume_info, \
  2397. .get = snd_hda_mixer_amp_volume_get, \
  2398. .put = snd_hda_mixer_amp_volume_put, \
  2399. .tlv = { .c = mic_boost_tlv }, \
  2400. .private_value = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT) }
  2401. /* capture mixer elements */
  2402. static struct snd_kcontrol_new vt1708S_capture_mixer[] = {
  2403. HDA_CODEC_VOLUME("Capture Volume", 0x13, 0x0, HDA_INPUT),
  2404. HDA_CODEC_MUTE("Capture Switch", 0x13, 0x0, HDA_INPUT),
  2405. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x14, 0x0, HDA_INPUT),
  2406. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x14, 0x0, HDA_INPUT),
  2407. MIC_BOOST_VOLUME("Mic Boost Capture Volume", 0x1A),
  2408. MIC_BOOST_VOLUME("Front Mic Boost Capture Volume", 0x1E),
  2409. {
  2410. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2411. /* The multiple "Capture Source" controls confuse alsamixer
  2412. * So call somewhat different..
  2413. */
  2414. /* .name = "Capture Source", */
  2415. .name = "Input Source",
  2416. .count = 1,
  2417. .info = via_mux_enum_info,
  2418. .get = via_mux_enum_get,
  2419. .put = via_mux_enum_put,
  2420. },
  2421. { } /* end */
  2422. };
  2423. static struct hda_verb vt1708S_volume_init_verbs[] = {
  2424. /* Unmute ADC0-1 and set the default input to mic-in */
  2425. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2426. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2427. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the
  2428. * analog-loopback mixer widget */
  2429. /* Amp Indices: CD = 1, Mic1 = 2, Line = 3, Mic2 = 4 */
  2430. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2431. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2432. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2433. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2434. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2435. /* Setup default input of PW4 to MW0 */
  2436. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x0},
  2437. /* PW9, PW10 Output enable */
  2438. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2439. {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2440. /* Enable Mic Boost Volume backdoor */
  2441. {0x1, 0xf98, 0x1},
  2442. { }
  2443. };
  2444. static struct hda_verb vt1708S_uniwill_init_verbs[] = {
  2445. {0x1D, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  2446. { }
  2447. };
  2448. static struct hda_pcm_stream vt1708S_pcm_analog_playback = {
  2449. .substreams = 2,
  2450. .channels_min = 2,
  2451. .channels_max = 8,
  2452. .nid = 0x10, /* NID to query formats and rates */
  2453. .ops = {
  2454. .open = via_playback_pcm_open,
  2455. .prepare = via_playback_pcm_prepare,
  2456. .cleanup = via_playback_pcm_cleanup,
  2457. .close = via_pcm_open_close
  2458. },
  2459. };
  2460. static struct hda_pcm_stream vt1708S_pcm_analog_capture = {
  2461. .substreams = 2,
  2462. .channels_min = 2,
  2463. .channels_max = 2,
  2464. .nid = 0x13, /* NID to query formats and rates */
  2465. .ops = {
  2466. .open = via_pcm_open_close,
  2467. .prepare = via_capture_pcm_prepare,
  2468. .cleanup = via_capture_pcm_cleanup,
  2469. .close = via_pcm_open_close
  2470. },
  2471. };
  2472. static struct hda_pcm_stream vt1708S_pcm_digital_playback = {
  2473. .substreams = 1,
  2474. .channels_min = 2,
  2475. .channels_max = 2,
  2476. /* NID is set in via_build_pcms */
  2477. .ops = {
  2478. .open = via_dig_playback_pcm_open,
  2479. .close = via_dig_playback_pcm_close,
  2480. .prepare = via_dig_playback_pcm_prepare,
  2481. .cleanup = via_dig_playback_pcm_cleanup
  2482. },
  2483. };
  2484. /* fill in the dac_nids table from the parsed pin configuration */
  2485. static int vt1708S_auto_fill_dac_nids(struct via_spec *spec,
  2486. const struct auto_pin_cfg *cfg)
  2487. {
  2488. int i;
  2489. hda_nid_t nid;
  2490. spec->multiout.num_dacs = cfg->line_outs;
  2491. spec->multiout.dac_nids = spec->private_dac_nids;
  2492. for (i = 0; i < 4; i++) {
  2493. nid = cfg->line_out_pins[i];
  2494. if (nid) {
  2495. /* config dac list */
  2496. switch (i) {
  2497. case AUTO_SEQ_FRONT:
  2498. spec->multiout.dac_nids[i] = 0x10;
  2499. break;
  2500. case AUTO_SEQ_CENLFE:
  2501. spec->multiout.dac_nids[i] = 0x24;
  2502. break;
  2503. case AUTO_SEQ_SURROUND:
  2504. spec->multiout.dac_nids[i] = 0x11;
  2505. break;
  2506. case AUTO_SEQ_SIDE:
  2507. spec->multiout.dac_nids[i] = 0x25;
  2508. break;
  2509. }
  2510. }
  2511. }
  2512. return 0;
  2513. }
  2514. /* add playback controls from the parsed DAC table */
  2515. static int vt1708S_auto_create_multi_out_ctls(struct via_spec *spec,
  2516. const struct auto_pin_cfg *cfg)
  2517. {
  2518. char name[32];
  2519. static const char *chname[4] = { "Front", "Surround", "C/LFE", "Side" };
  2520. hda_nid_t nid_vols[] = {0x10, 0x11, 0x24, 0x25};
  2521. hda_nid_t nid_mutes[] = {0x1C, 0x18, 0x26, 0x27};
  2522. hda_nid_t nid, nid_vol, nid_mute;
  2523. int i, err;
  2524. for (i = 0; i <= AUTO_SEQ_SIDE; i++) {
  2525. nid = cfg->line_out_pins[i];
  2526. if (!nid)
  2527. continue;
  2528. nid_vol = nid_vols[i];
  2529. nid_mute = nid_mutes[i];
  2530. if (i == AUTO_SEQ_CENLFE) {
  2531. /* Center/LFE */
  2532. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2533. "Center Playback Volume",
  2534. HDA_COMPOSE_AMP_VAL(nid_vol, 1, 0,
  2535. HDA_OUTPUT));
  2536. if (err < 0)
  2537. return err;
  2538. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2539. "LFE Playback Volume",
  2540. HDA_COMPOSE_AMP_VAL(nid_vol, 2, 0,
  2541. HDA_OUTPUT));
  2542. if (err < 0)
  2543. return err;
  2544. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2545. "Center Playback Switch",
  2546. HDA_COMPOSE_AMP_VAL(nid_mute,
  2547. 1, 0,
  2548. HDA_OUTPUT));
  2549. if (err < 0)
  2550. return err;
  2551. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2552. "LFE Playback Switch",
  2553. HDA_COMPOSE_AMP_VAL(nid_mute,
  2554. 2, 0,
  2555. HDA_OUTPUT));
  2556. if (err < 0)
  2557. return err;
  2558. } else if (i == AUTO_SEQ_FRONT) {
  2559. /* add control to mixer index 0 */
  2560. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2561. "Master Front Playback Volume",
  2562. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  2563. HDA_INPUT));
  2564. if (err < 0)
  2565. return err;
  2566. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2567. "Master Front Playback Switch",
  2568. HDA_COMPOSE_AMP_VAL(0x16, 3, 0,
  2569. HDA_INPUT));
  2570. if (err < 0)
  2571. return err;
  2572. /* Front */
  2573. sprintf(name, "%s Playback Volume", chname[i]);
  2574. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2575. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2576. HDA_OUTPUT));
  2577. if (err < 0)
  2578. return err;
  2579. sprintf(name, "%s Playback Switch", chname[i]);
  2580. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2581. HDA_COMPOSE_AMP_VAL(nid_mute,
  2582. 3, 0,
  2583. HDA_OUTPUT));
  2584. if (err < 0)
  2585. return err;
  2586. } else {
  2587. sprintf(name, "%s Playback Volume", chname[i]);
  2588. err = via_add_control(spec, VIA_CTL_WIDGET_VOL, name,
  2589. HDA_COMPOSE_AMP_VAL(nid_vol, 3, 0,
  2590. HDA_OUTPUT));
  2591. if (err < 0)
  2592. return err;
  2593. sprintf(name, "%s Playback Switch", chname[i]);
  2594. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE, name,
  2595. HDA_COMPOSE_AMP_VAL(nid_mute,
  2596. 3, 0,
  2597. HDA_OUTPUT));
  2598. if (err < 0)
  2599. return err;
  2600. }
  2601. }
  2602. return 0;
  2603. }
  2604. static int vt1708S_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2605. {
  2606. int err;
  2607. if (!pin)
  2608. return 0;
  2609. spec->multiout.hp_nid = VT1708S_HP_NID; /* AOW3 */
  2610. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2611. "Headphone Playback Volume",
  2612. HDA_COMPOSE_AMP_VAL(0x25, 3, 0, HDA_OUTPUT));
  2613. if (err < 0)
  2614. return err;
  2615. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2616. "Headphone Playback Switch",
  2617. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2618. if (err < 0)
  2619. return err;
  2620. create_hp_imux(spec);
  2621. return 0;
  2622. }
  2623. /* create playback/capture controls for input pins */
  2624. static int vt1708S_auto_create_analog_input_ctls(struct via_spec *spec,
  2625. const struct auto_pin_cfg *cfg)
  2626. {
  2627. static char *labels[] = {
  2628. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2629. };
  2630. struct hda_input_mux *imux = &spec->private_imux[0];
  2631. int i, err, idx = 0;
  2632. /* for internal loopback recording select */
  2633. imux->items[imux->num_items].label = "Stereo Mixer";
  2634. imux->items[imux->num_items].index = 5;
  2635. imux->num_items++;
  2636. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2637. if (!cfg->input_pins[i])
  2638. continue;
  2639. switch (cfg->input_pins[i]) {
  2640. case 0x1a: /* Mic */
  2641. idx = 2;
  2642. break;
  2643. case 0x1b: /* Line In */
  2644. idx = 3;
  2645. break;
  2646. case 0x1e: /* Front Mic */
  2647. idx = 4;
  2648. break;
  2649. case 0x1f: /* CD */
  2650. idx = 1;
  2651. break;
  2652. }
  2653. err = via_new_analog_input(spec, labels[i], idx, 0x16);
  2654. if (err < 0)
  2655. return err;
  2656. imux->items[imux->num_items].label = labels[i];
  2657. imux->items[imux->num_items].index = idx-1;
  2658. imux->num_items++;
  2659. }
  2660. return 0;
  2661. }
  2662. /* fill out digital output widgets; one for master and one for slave outputs */
  2663. static void fill_dig_outs(struct hda_codec *codec)
  2664. {
  2665. struct via_spec *spec = codec->spec;
  2666. int i;
  2667. for (i = 0; i < spec->autocfg.dig_outs; i++) {
  2668. hda_nid_t nid;
  2669. int conn;
  2670. nid = spec->autocfg.dig_out_pins[i];
  2671. if (!nid)
  2672. continue;
  2673. conn = snd_hda_get_connections(codec, nid, &nid, 1);
  2674. if (conn < 1)
  2675. continue;
  2676. if (!spec->multiout.dig_out_nid)
  2677. spec->multiout.dig_out_nid = nid;
  2678. else {
  2679. spec->slave_dig_outs[0] = nid;
  2680. break; /* at most two dig outs */
  2681. }
  2682. }
  2683. }
  2684. static int vt1708S_parse_auto_config(struct hda_codec *codec)
  2685. {
  2686. struct via_spec *spec = codec->spec;
  2687. int err;
  2688. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2689. if (err < 0)
  2690. return err;
  2691. err = vt1708S_auto_fill_dac_nids(spec, &spec->autocfg);
  2692. if (err < 0)
  2693. return err;
  2694. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2695. return 0; /* can't find valid BIOS pin config */
  2696. err = vt1708S_auto_create_multi_out_ctls(spec, &spec->autocfg);
  2697. if (err < 0)
  2698. return err;
  2699. err = vt1708S_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2700. if (err < 0)
  2701. return err;
  2702. err = vt1708S_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2703. if (err < 0)
  2704. return err;
  2705. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2706. fill_dig_outs(codec);
  2707. if (spec->kctls.list)
  2708. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2709. spec->input_mux = &spec->private_imux[0];
  2710. if (spec->hp_mux)
  2711. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2712. return 1;
  2713. }
  2714. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2715. static struct hda_amp_list vt1708S_loopbacks[] = {
  2716. { 0x16, HDA_INPUT, 1 },
  2717. { 0x16, HDA_INPUT, 2 },
  2718. { 0x16, HDA_INPUT, 3 },
  2719. { 0x16, HDA_INPUT, 4 },
  2720. { } /* end */
  2721. };
  2722. #endif
  2723. static int patch_vt1708S(struct hda_codec *codec)
  2724. {
  2725. struct via_spec *spec;
  2726. int err;
  2727. /* create a codec specific record */
  2728. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2729. if (spec == NULL)
  2730. return -ENOMEM;
  2731. codec->spec = spec;
  2732. /* automatic parse from the BIOS config */
  2733. err = vt1708S_parse_auto_config(codec);
  2734. if (err < 0) {
  2735. via_free(codec);
  2736. return err;
  2737. } else if (!err) {
  2738. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  2739. "from BIOS. Using genenic mode...\n");
  2740. }
  2741. spec->init_verbs[spec->num_iverbs++] = vt1708S_volume_init_verbs;
  2742. spec->init_verbs[spec->num_iverbs++] = vt1708S_uniwill_init_verbs;
  2743. spec->stream_name_analog = "VT1708S Analog";
  2744. spec->stream_analog_playback = &vt1708S_pcm_analog_playback;
  2745. spec->stream_analog_capture = &vt1708S_pcm_analog_capture;
  2746. spec->stream_name_digital = "VT1708S Digital";
  2747. spec->stream_digital_playback = &vt1708S_pcm_digital_playback;
  2748. if (!spec->adc_nids && spec->input_mux) {
  2749. spec->adc_nids = vt1708S_adc_nids;
  2750. spec->num_adc_nids = ARRAY_SIZE(vt1708S_adc_nids);
  2751. get_mux_nids(codec);
  2752. spec->mixers[spec->num_mixers] = vt1708S_capture_mixer;
  2753. spec->num_mixers++;
  2754. }
  2755. codec->patch_ops = via_patch_ops;
  2756. codec->patch_ops.init = via_auto_init;
  2757. codec->patch_ops.unsol_event = via_unsol_event;
  2758. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2759. spec->loopback.amplist = vt1708S_loopbacks;
  2760. #endif
  2761. /* correct names for VT1708BCE */
  2762. if (get_codec_type(codec) == VT1708BCE) {
  2763. kfree(codec->chip_name);
  2764. codec->chip_name = kstrdup("VT1708BCE", GFP_KERNEL);
  2765. snprintf(codec->bus->card->mixername,
  2766. sizeof(codec->bus->card->mixername),
  2767. "%s %s", codec->vendor_name, codec->chip_name);
  2768. spec->stream_name_analog = "VT1708BCE Analog";
  2769. spec->stream_name_digital = "VT1708BCE Digital";
  2770. }
  2771. return 0;
  2772. }
  2773. /* Patch for VT1702 */
  2774. /* capture mixer elements */
  2775. static struct snd_kcontrol_new vt1702_capture_mixer[] = {
  2776. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x0, HDA_INPUT),
  2777. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x0, HDA_INPUT),
  2778. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x20, 0x0, HDA_INPUT),
  2779. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x20, 0x0, HDA_INPUT),
  2780. HDA_CODEC_VOLUME("Digital Mic Capture Volume", 0x1F, 0x0, HDA_INPUT),
  2781. HDA_CODEC_MUTE("Digital Mic Capture Switch", 0x1F, 0x0, HDA_INPUT),
  2782. HDA_CODEC_VOLUME("Digital Mic Boost Capture Volume", 0x1E, 0x0,
  2783. HDA_INPUT),
  2784. {
  2785. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2786. /* The multiple "Capture Source" controls confuse alsamixer
  2787. * So call somewhat different..
  2788. */
  2789. /* .name = "Capture Source", */
  2790. .name = "Input Source",
  2791. .count = 1,
  2792. .info = via_mux_enum_info,
  2793. .get = via_mux_enum_get,
  2794. .put = via_mux_enum_put,
  2795. },
  2796. { } /* end */
  2797. };
  2798. static struct hda_verb vt1702_volume_init_verbs[] = {
  2799. /*
  2800. * Unmute ADC0-1 and set the default input to mic-in
  2801. */
  2802. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2803. {0x1F, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2804. {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2805. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  2806. * mixer widget
  2807. */
  2808. /* Amp Indices: Mic1 = 1, Line = 1, Mic2 = 3 */
  2809. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2810. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  2811. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2812. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  2813. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2814. /* Setup default input of PW4 to MW0 */
  2815. {0x17, AC_VERB_SET_CONNECT_SEL, 0x1},
  2816. /* PW6 PW7 Output enable */
  2817. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2818. {0x1C, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
  2819. { }
  2820. };
  2821. static struct hda_verb vt1702_uniwill_init_verbs[] = {
  2822. {0x01, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_GPIO_EVENT},
  2823. {0x17, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | VIA_HP_EVENT},
  2824. { }
  2825. };
  2826. static struct hda_pcm_stream vt1702_pcm_analog_playback = {
  2827. .substreams = 2,
  2828. .channels_min = 2,
  2829. .channels_max = 2,
  2830. .nid = 0x10, /* NID to query formats and rates */
  2831. .ops = {
  2832. .open = via_playback_pcm_open,
  2833. .prepare = via_playback_multi_pcm_prepare,
  2834. .cleanup = via_playback_multi_pcm_cleanup,
  2835. .close = via_pcm_open_close
  2836. },
  2837. };
  2838. static struct hda_pcm_stream vt1702_pcm_analog_capture = {
  2839. .substreams = 3,
  2840. .channels_min = 2,
  2841. .channels_max = 2,
  2842. .nid = 0x12, /* NID to query formats and rates */
  2843. .ops = {
  2844. .open = via_pcm_open_close,
  2845. .prepare = via_capture_pcm_prepare,
  2846. .cleanup = via_capture_pcm_cleanup,
  2847. .close = via_pcm_open_close
  2848. },
  2849. };
  2850. static struct hda_pcm_stream vt1702_pcm_digital_playback = {
  2851. .substreams = 2,
  2852. .channels_min = 2,
  2853. .channels_max = 2,
  2854. /* NID is set in via_build_pcms */
  2855. .ops = {
  2856. .open = via_dig_playback_pcm_open,
  2857. .close = via_dig_playback_pcm_close,
  2858. .prepare = via_dig_playback_pcm_prepare,
  2859. .cleanup = via_dig_playback_pcm_cleanup
  2860. },
  2861. };
  2862. /* fill in the dac_nids table from the parsed pin configuration */
  2863. static int vt1702_auto_fill_dac_nids(struct via_spec *spec,
  2864. const struct auto_pin_cfg *cfg)
  2865. {
  2866. spec->multiout.num_dacs = 1;
  2867. spec->multiout.dac_nids = spec->private_dac_nids;
  2868. if (cfg->line_out_pins[0]) {
  2869. /* config dac list */
  2870. spec->multiout.dac_nids[0] = 0x10;
  2871. }
  2872. return 0;
  2873. }
  2874. /* add playback controls from the parsed DAC table */
  2875. static int vt1702_auto_create_line_out_ctls(struct via_spec *spec,
  2876. const struct auto_pin_cfg *cfg)
  2877. {
  2878. int err;
  2879. if (!cfg->line_out_pins[0])
  2880. return -1;
  2881. /* add control to mixer index 0 */
  2882. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2883. "Master Front Playback Volume",
  2884. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  2885. if (err < 0)
  2886. return err;
  2887. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2888. "Master Front Playback Switch",
  2889. HDA_COMPOSE_AMP_VAL(0x1A, 3, 0, HDA_INPUT));
  2890. if (err < 0)
  2891. return err;
  2892. /* Front */
  2893. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2894. "Front Playback Volume",
  2895. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT));
  2896. if (err < 0)
  2897. return err;
  2898. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2899. "Front Playback Switch",
  2900. HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT));
  2901. if (err < 0)
  2902. return err;
  2903. return 0;
  2904. }
  2905. static int vt1702_auto_create_hp_ctls(struct via_spec *spec, hda_nid_t pin)
  2906. {
  2907. int err;
  2908. if (!pin)
  2909. return 0;
  2910. spec->multiout.hp_nid = 0x1D;
  2911. err = via_add_control(spec, VIA_CTL_WIDGET_VOL,
  2912. "Headphone Playback Volume",
  2913. HDA_COMPOSE_AMP_VAL(0x1D, 3, 0, HDA_OUTPUT));
  2914. if (err < 0)
  2915. return err;
  2916. err = via_add_control(spec, VIA_CTL_WIDGET_MUTE,
  2917. "Headphone Playback Switch",
  2918. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
  2919. if (err < 0)
  2920. return err;
  2921. create_hp_imux(spec);
  2922. return 0;
  2923. }
  2924. /* create playback/capture controls for input pins */
  2925. static int vt1702_auto_create_analog_input_ctls(struct via_spec *spec,
  2926. const struct auto_pin_cfg *cfg)
  2927. {
  2928. static char *labels[] = {
  2929. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux", NULL
  2930. };
  2931. struct hda_input_mux *imux = &spec->private_imux[0];
  2932. int i, err, idx = 0;
  2933. /* for internal loopback recording select */
  2934. imux->items[imux->num_items].label = "Stereo Mixer";
  2935. imux->items[imux->num_items].index = 3;
  2936. imux->num_items++;
  2937. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2938. if (!cfg->input_pins[i])
  2939. continue;
  2940. switch (cfg->input_pins[i]) {
  2941. case 0x14: /* Mic */
  2942. idx = 1;
  2943. break;
  2944. case 0x15: /* Line In */
  2945. idx = 2;
  2946. break;
  2947. case 0x18: /* Front Mic */
  2948. idx = 3;
  2949. break;
  2950. }
  2951. err = via_new_analog_input(spec, labels[i], idx, 0x1A);
  2952. if (err < 0)
  2953. return err;
  2954. imux->items[imux->num_items].label = labels[i];
  2955. imux->items[imux->num_items].index = idx-1;
  2956. imux->num_items++;
  2957. }
  2958. return 0;
  2959. }
  2960. static int vt1702_parse_auto_config(struct hda_codec *codec)
  2961. {
  2962. struct via_spec *spec = codec->spec;
  2963. int err;
  2964. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  2965. if (err < 0)
  2966. return err;
  2967. err = vt1702_auto_fill_dac_nids(spec, &spec->autocfg);
  2968. if (err < 0)
  2969. return err;
  2970. if (!spec->autocfg.line_outs && !spec->autocfg.hp_pins[0])
  2971. return 0; /* can't find valid BIOS pin config */
  2972. err = vt1702_auto_create_line_out_ctls(spec, &spec->autocfg);
  2973. if (err < 0)
  2974. return err;
  2975. err = vt1702_auto_create_hp_ctls(spec, spec->autocfg.hp_pins[0]);
  2976. if (err < 0)
  2977. return err;
  2978. /* limit AA path volume to 0 dB */
  2979. snd_hda_override_amp_caps(codec, 0x1A, HDA_INPUT,
  2980. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2981. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2982. (0x5 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2983. (1 << AC_AMPCAP_MUTE_SHIFT));
  2984. err = vt1702_auto_create_analog_input_ctls(spec, &spec->autocfg);
  2985. if (err < 0)
  2986. return err;
  2987. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2988. fill_dig_outs(codec);
  2989. if (spec->kctls.list)
  2990. spec->mixers[spec->num_mixers++] = spec->kctls.list;
  2991. spec->input_mux = &spec->private_imux[0];
  2992. if (spec->hp_mux)
  2993. spec->mixers[spec->num_mixers++] = via_hp_mixer;
  2994. return 1;
  2995. }
  2996. #ifdef CONFIG_SND_HDA_POWER_SAVE
  2997. static struct hda_amp_list vt1702_loopbacks[] = {
  2998. { 0x1A, HDA_INPUT, 1 },
  2999. { 0x1A, HDA_INPUT, 2 },
  3000. { 0x1A, HDA_INPUT, 3 },
  3001. { 0x1A, HDA_INPUT, 4 },
  3002. { } /* end */
  3003. };
  3004. #endif
  3005. static int patch_vt1702(struct hda_codec *codec)
  3006. {
  3007. struct via_spec *spec;
  3008. int err;
  3009. unsigned int response;
  3010. unsigned char control;
  3011. /* create a codec specific record */
  3012. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3013. if (spec == NULL)
  3014. return -ENOMEM;
  3015. codec->spec = spec;
  3016. /* automatic parse from the BIOS config */
  3017. err = vt1702_parse_auto_config(codec);
  3018. if (err < 0) {
  3019. via_free(codec);
  3020. return err;
  3021. } else if (!err) {
  3022. printk(KERN_INFO "hda_codec: Cannot set up configuration "
  3023. "from BIOS. Using genenic mode...\n");
  3024. }
  3025. spec->init_verbs[spec->num_iverbs++] = vt1702_volume_init_verbs;
  3026. spec->init_verbs[spec->num_iverbs++] = vt1702_uniwill_init_verbs;
  3027. spec->stream_name_analog = "VT1702 Analog";
  3028. spec->stream_analog_playback = &vt1702_pcm_analog_playback;
  3029. spec->stream_analog_capture = &vt1702_pcm_analog_capture;
  3030. spec->stream_name_digital = "VT1702 Digital";
  3031. spec->stream_digital_playback = &vt1702_pcm_digital_playback;
  3032. if (!spec->adc_nids && spec->input_mux) {
  3033. spec->adc_nids = vt1702_adc_nids;
  3034. spec->num_adc_nids = ARRAY_SIZE(vt1702_adc_nids);
  3035. get_mux_nids(codec);
  3036. spec->mixers[spec->num_mixers] = vt1702_capture_mixer;
  3037. spec->num_mixers++;
  3038. }
  3039. codec->patch_ops = via_patch_ops;
  3040. codec->patch_ops.init = via_auto_init;
  3041. codec->patch_ops.unsol_event = via_unsol_event;
  3042. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3043. spec->loopback.amplist = vt1702_loopbacks;
  3044. #endif
  3045. /* Open backdoor */
  3046. response = snd_hda_codec_read(codec, codec->afg, 0, 0xF8C, 0);
  3047. control = (unsigned char)(response & 0xff);
  3048. control |= 0x3;
  3049. snd_hda_codec_write(codec, codec->afg, 0, 0xF88, control);
  3050. /* Enable GPIO 0&1 for volume&mute control */
  3051. /* Enable GPIO 2 for DMIC-DATA */
  3052. response = snd_hda_codec_read(codec, codec->afg, 0, 0xF84, 0);
  3053. control = (unsigned char)((response >> 16) & 0x3f);
  3054. snd_hda_codec_write(codec, codec->afg, 0, 0xF82, control);
  3055. return 0;
  3056. }
  3057. /*
  3058. * patch entries
  3059. */
  3060. static struct hda_codec_preset snd_hda_preset_via[] = {
  3061. { .id = 0x11061708, .name = "VT1708", .patch = patch_vt1708},
  3062. { .id = 0x11061709, .name = "VT1708", .patch = patch_vt1708},
  3063. { .id = 0x1106170a, .name = "VT1708", .patch = patch_vt1708},
  3064. { .id = 0x1106170b, .name = "VT1708", .patch = patch_vt1708},
  3065. { .id = 0x1106e710, .name = "VT1709 10-Ch",
  3066. .patch = patch_vt1709_10ch},
  3067. { .id = 0x1106e711, .name = "VT1709 10-Ch",
  3068. .patch = patch_vt1709_10ch},
  3069. { .id = 0x1106e712, .name = "VT1709 10-Ch",
  3070. .patch = patch_vt1709_10ch},
  3071. { .id = 0x1106e713, .name = "VT1709 10-Ch",
  3072. .patch = patch_vt1709_10ch},
  3073. { .id = 0x1106e714, .name = "VT1709 6-Ch",
  3074. .patch = patch_vt1709_6ch},
  3075. { .id = 0x1106e715, .name = "VT1709 6-Ch",
  3076. .patch = patch_vt1709_6ch},
  3077. { .id = 0x1106e716, .name = "VT1709 6-Ch",
  3078. .patch = patch_vt1709_6ch},
  3079. { .id = 0x1106e717, .name = "VT1709 6-Ch",
  3080. .patch = patch_vt1709_6ch},
  3081. { .id = 0x1106e720, .name = "VT1708B 8-Ch",
  3082. .patch = patch_vt1708B_8ch},
  3083. { .id = 0x1106e721, .name = "VT1708B 8-Ch",
  3084. .patch = patch_vt1708B_8ch},
  3085. { .id = 0x1106e722, .name = "VT1708B 8-Ch",
  3086. .patch = patch_vt1708B_8ch},
  3087. { .id = 0x1106e723, .name = "VT1708B 8-Ch",
  3088. .patch = patch_vt1708B_8ch},
  3089. { .id = 0x1106e724, .name = "VT1708B 4-Ch",
  3090. .patch = patch_vt1708B_4ch},
  3091. { .id = 0x1106e725, .name = "VT1708B 4-Ch",
  3092. .patch = patch_vt1708B_4ch},
  3093. { .id = 0x1106e726, .name = "VT1708B 4-Ch",
  3094. .patch = patch_vt1708B_4ch},
  3095. { .id = 0x1106e727, .name = "VT1708B 4-Ch",
  3096. .patch = patch_vt1708B_4ch},
  3097. { .id = 0x11060397, .name = "VT1708S",
  3098. .patch = patch_vt1708S},
  3099. { .id = 0x11061397, .name = "VT1708S",
  3100. .patch = patch_vt1708S},
  3101. { .id = 0x11062397, .name = "VT1708S",
  3102. .patch = patch_vt1708S},
  3103. { .id = 0x11063397, .name = "VT1708S",
  3104. .patch = patch_vt1708S},
  3105. { .id = 0x11064397, .name = "VT1708S",
  3106. .patch = patch_vt1708S},
  3107. { .id = 0x11065397, .name = "VT1708S",
  3108. .patch = patch_vt1708S},
  3109. { .id = 0x11066397, .name = "VT1708S",
  3110. .patch = patch_vt1708S},
  3111. { .id = 0x11067397, .name = "VT1708S",
  3112. .patch = patch_vt1708S},
  3113. { .id = 0x11060398, .name = "VT1702",
  3114. .patch = patch_vt1702},
  3115. { .id = 0x11061398, .name = "VT1702",
  3116. .patch = patch_vt1702},
  3117. { .id = 0x11062398, .name = "VT1702",
  3118. .patch = patch_vt1702},
  3119. { .id = 0x11063398, .name = "VT1702",
  3120. .patch = patch_vt1702},
  3121. { .id = 0x11064398, .name = "VT1702",
  3122. .patch = patch_vt1702},
  3123. { .id = 0x11065398, .name = "VT1702",
  3124. .patch = patch_vt1702},
  3125. { .id = 0x11066398, .name = "VT1702",
  3126. .patch = patch_vt1702},
  3127. { .id = 0x11067398, .name = "VT1702",
  3128. .patch = patch_vt1702},
  3129. {} /* terminator */
  3130. };
  3131. MODULE_ALIAS("snd-hda-codec-id:1106*");
  3132. static struct hda_codec_preset_list via_list = {
  3133. .preset = snd_hda_preset_via,
  3134. .owner = THIS_MODULE,
  3135. };
  3136. MODULE_LICENSE("GPL");
  3137. MODULE_DESCRIPTION("VIA HD-audio codec");
  3138. static int __init patch_via_init(void)
  3139. {
  3140. return snd_hda_add_codec_preset(&via_list);
  3141. }
  3142. static void __exit patch_via_exit(void)
  3143. {
  3144. snd_hda_delete_codec_preset(&via_list);
  3145. }
  3146. module_init(patch_via_init)
  3147. module_exit(patch_via_exit)