patch_via.c 107 KB

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