patch_via.c 88 KB

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