patch_via.c 85 KB

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