patch_via.c 98 KB

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