patch_via.c 90 KB

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