patch_via.c 98 KB

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