patch_via.c 89 KB

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