patch_via.c 89 KB

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