patch_via.c 102 KB

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