patch_via.c 97 KB

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