patch_via.c 89 KB

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