patch_realtek.c 91 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for ALC 260/880/882 codecs
  5. *
  6. * Copyright (c) 2004 PeiSen Hou <pshou@realtek.com.tw>
  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. #include <sound/driver.h>
  24. #include <linux/init.h>
  25. #include <linux/delay.h>
  26. #include <linux/slab.h>
  27. #include <linux/pci.h>
  28. #include <sound/core.h>
  29. #include "hda_codec.h"
  30. #include "hda_local.h"
  31. /* ALC880 board config type */
  32. enum {
  33. ALC880_3ST,
  34. ALC880_3ST_DIG,
  35. ALC880_5ST,
  36. ALC880_5ST_DIG,
  37. ALC880_W810,
  38. ALC880_Z71V,
  39. ALC880_AUTO,
  40. ALC880_6ST,
  41. ALC880_6ST_DIG,
  42. ALC880_F1734,
  43. ALC880_ASUS,
  44. ALC880_ASUS_DIG,
  45. ALC880_ASUS_W1V,
  46. ALC880_UNIWILL_DIG,
  47. #ifdef CONFIG_SND_DEBUG
  48. ALC880_TEST,
  49. #endif
  50. ALC880_MODEL_LAST /* last tag */
  51. };
  52. /* ALC260 models */
  53. enum {
  54. ALC260_BASIC,
  55. ALC260_HP,
  56. ALC260_FUJITSU_S702x,
  57. ALC260_MODEL_LAST /* last tag */
  58. };
  59. /* amp values */
  60. #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
  61. #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
  62. #define AMP_OUT_MUTE 0xb080
  63. #define AMP_OUT_UNMUTE 0xb000
  64. #define AMP_OUT_ZERO 0xb000
  65. /* pinctl values */
  66. #define PIN_IN 0x20
  67. #define PIN_VREF80 0x24
  68. #define PIN_VREF50 0x21
  69. #define PIN_OUT 0x40
  70. #define PIN_HP 0xc0
  71. #define PIN_HP_AMP 0x80
  72. struct alc_spec {
  73. /* codec parameterization */
  74. snd_kcontrol_new_t *mixers[3]; /* mixer arrays */
  75. unsigned int num_mixers;
  76. const struct hda_verb *init_verbs[3]; /* initialization verbs
  77. * don't forget NULL termination!
  78. */
  79. unsigned int num_init_verbs;
  80. char *stream_name_analog; /* analog PCM stream */
  81. struct hda_pcm_stream *stream_analog_playback;
  82. struct hda_pcm_stream *stream_analog_capture;
  83. char *stream_name_digital; /* digital PCM stream */
  84. struct hda_pcm_stream *stream_digital_playback;
  85. struct hda_pcm_stream *stream_digital_capture;
  86. /* playback */
  87. struct hda_multi_out multiout; /* playback set-up
  88. * max_channels, dacs must be set
  89. * dig_out_nid and hp_nid are optional
  90. */
  91. /* capture */
  92. unsigned int num_adc_nids;
  93. hda_nid_t *adc_nids;
  94. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  95. /* capture source */
  96. const struct hda_input_mux *input_mux;
  97. unsigned int cur_mux[3];
  98. /* channel model */
  99. const struct hda_channel_mode *channel_mode;
  100. int num_channel_mode;
  101. /* PCM information */
  102. struct hda_pcm pcm_rec[2]; /* used in alc_build_pcms() */
  103. /* dynamic controls, init_verbs and input_mux */
  104. struct auto_pin_cfg autocfg;
  105. unsigned int num_kctl_alloc, num_kctl_used;
  106. snd_kcontrol_new_t *kctl_alloc;
  107. struct hda_input_mux private_imux;
  108. hda_nid_t private_dac_nids[4];
  109. };
  110. /*
  111. * input MUX handling
  112. */
  113. static int alc_mux_enum_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  114. {
  115. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  116. struct alc_spec *spec = codec->spec;
  117. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  118. }
  119. static int alc_mux_enum_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  120. {
  121. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  122. struct alc_spec *spec = codec->spec;
  123. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  124. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  125. return 0;
  126. }
  127. static int alc_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  128. {
  129. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  130. struct alc_spec *spec = codec->spec;
  131. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  132. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  133. spec->adc_nids[adc_idx], &spec->cur_mux[adc_idx]);
  134. }
  135. /*
  136. * channel mode setting
  137. */
  138. static int alc880_ch_mode_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  139. {
  140. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  141. struct alc_spec *spec = codec->spec;
  142. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  143. spec->num_channel_mode);
  144. }
  145. static int alc880_ch_mode_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  146. {
  147. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  148. struct alc_spec *spec = codec->spec;
  149. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  150. spec->num_channel_mode, spec->multiout.max_channels);
  151. }
  152. static int alc880_ch_mode_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  153. {
  154. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  155. struct alc_spec *spec = codec->spec;
  156. return snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  157. spec->num_channel_mode, &spec->multiout.max_channels);
  158. }
  159. /*
  160. * Control of pin widget settings via the mixer. Only boolean settings are
  161. * supported, so VrefEn can't be controlled using these functions as they
  162. * stand.
  163. */
  164. static int alc_pinctl_switch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  165. {
  166. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  167. uinfo->count = 1;
  168. uinfo->value.integer.min = 0;
  169. uinfo->value.integer.max = 1;
  170. return 0;
  171. }
  172. static int alc_pinctl_switch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  173. {
  174. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  175. hda_nid_t nid = kcontrol->private_value & 0xffff;
  176. long mask = (kcontrol->private_value >> 16) & 0xff;
  177. long *valp = ucontrol->value.integer.value;
  178. *valp = 0;
  179. if (snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00) & mask)
  180. *valp = 1;
  181. return 0;
  182. }
  183. static int alc_pinctl_switch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  184. {
  185. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  186. hda_nid_t nid = kcontrol->private_value & 0xffff;
  187. long mask = (kcontrol->private_value >> 16) & 0xff;
  188. long *valp = ucontrol->value.integer.value;
  189. unsigned int pinctl = snd_hda_codec_read(codec,nid,0,AC_VERB_GET_PIN_WIDGET_CONTROL,0x00);
  190. int change = ((pinctl & mask)!=0) != *valp;
  191. if (change)
  192. snd_hda_codec_write(codec,nid,0,AC_VERB_SET_PIN_WIDGET_CONTROL,
  193. *valp?(pinctl|mask):(pinctl&~mask));
  194. return change;
  195. }
  196. #define ALC_PINCTL_SWITCH(xname, nid, mask) \
  197. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  198. .info = alc_pinctl_switch_info, \
  199. .get = alc_pinctl_switch_get, \
  200. .put = alc_pinctl_switch_put, \
  201. .private_value = (nid) | (mask<<16) }
  202. /*
  203. * ALC880 3-stack model
  204. *
  205. * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0e)
  206. * Pin assignment: Front = 0x14, Line-In/Surr = 0x1a, Mic/CLFE = 0x18, F-Mic = 0x1b
  207. * HP = 0x19
  208. */
  209. static hda_nid_t alc880_dac_nids[4] = {
  210. /* front, rear, clfe, rear_surr */
  211. 0x02, 0x05, 0x04, 0x03
  212. };
  213. static hda_nid_t alc880_adc_nids[3] = {
  214. /* ADC0-2 */
  215. 0x07, 0x08, 0x09,
  216. };
  217. /* The datasheet says the node 0x07 is connected from inputs,
  218. * but it shows zero connection in the real implementation on some devices.
  219. */
  220. static hda_nid_t alc880_adc_nids_alt[2] = {
  221. /* ADC1-2 */
  222. 0x08, 0x09,
  223. };
  224. #define ALC880_DIGOUT_NID 0x06
  225. #define ALC880_DIGIN_NID 0x0a
  226. static struct hda_input_mux alc880_capture_source = {
  227. .num_items = 4,
  228. .items = {
  229. { "Mic", 0x0 },
  230. { "Front Mic", 0x3 },
  231. { "Line", 0x2 },
  232. { "CD", 0x4 },
  233. },
  234. };
  235. /* channel source setting (2/6 channel selection for 3-stack) */
  236. /* 2ch mode */
  237. static struct hda_verb alc880_threestack_ch2_init[] = {
  238. /* set line-in to input, mute it */
  239. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  240. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  241. /* set mic-in to input vref 80%, mute it */
  242. { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
  243. { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  244. { } /* end */
  245. };
  246. /* 6ch mode */
  247. static struct hda_verb alc880_threestack_ch6_init[] = {
  248. /* set line-in to output, unmute it */
  249. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  250. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  251. /* set mic-in to output, unmute it */
  252. { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  253. { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  254. { } /* end */
  255. };
  256. static struct hda_channel_mode alc880_threestack_modes[2] = {
  257. { 2, alc880_threestack_ch2_init },
  258. { 6, alc880_threestack_ch6_init },
  259. };
  260. static snd_kcontrol_new_t alc880_three_stack_mixer[] = {
  261. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  262. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  263. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  264. HDA_BIND_MUTE("Surround Playback Switch", 0x0f, 2, HDA_INPUT),
  265. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  266. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  267. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  268. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  269. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  270. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  271. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  272. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  273. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  274. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  275. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x3, HDA_INPUT),
  276. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x3, HDA_INPUT),
  277. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  278. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  279. HDA_CODEC_MUTE("Headphone Playback Switch", 0x19, 0x0, HDA_OUTPUT),
  280. {
  281. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  282. .name = "Channel Mode",
  283. .info = alc880_ch_mode_info,
  284. .get = alc880_ch_mode_get,
  285. .put = alc880_ch_mode_put,
  286. },
  287. { } /* end */
  288. };
  289. /* capture mixer elements */
  290. static snd_kcontrol_new_t alc880_capture_mixer[] = {
  291. HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
  292. HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
  293. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
  294. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
  295. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
  296. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
  297. {
  298. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  299. /* The multiple "Capture Source" controls confuse alsamixer
  300. * So call somewhat different..
  301. * FIXME: the controls appear in the "playback" view!
  302. */
  303. /* .name = "Capture Source", */
  304. .name = "Input Source",
  305. .count = 3,
  306. .info = alc_mux_enum_info,
  307. .get = alc_mux_enum_get,
  308. .put = alc_mux_enum_put,
  309. },
  310. { } /* end */
  311. };
  312. /* capture mixer elements (in case NID 0x07 not available) */
  313. static snd_kcontrol_new_t alc880_capture_alt_mixer[] = {
  314. HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
  315. HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
  316. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
  317. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
  318. {
  319. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  320. /* The multiple "Capture Source" controls confuse alsamixer
  321. * So call somewhat different..
  322. * FIXME: the controls appear in the "playback" view!
  323. */
  324. /* .name = "Capture Source", */
  325. .name = "Input Source",
  326. .count = 2,
  327. .info = alc_mux_enum_info,
  328. .get = alc_mux_enum_get,
  329. .put = alc_mux_enum_put,
  330. },
  331. { } /* end */
  332. };
  333. /*
  334. * ALC880 5-stack model
  335. *
  336. * DAC: Front = 0x02 (0x0c), Surr = 0x05 (0x0f), CLFE = 0x04 (0x0d), Side = 0x02 (0xd)
  337. * Pin assignment: Front = 0x14, Surr = 0x17, CLFE = 0x16
  338. * Line-In/Side = 0x1a, Mic = 0x18, F-Mic = 0x1b, HP = 0x19
  339. */
  340. /* additional mixers to alc880_three_stack_mixer */
  341. static snd_kcontrol_new_t alc880_five_stack_mixer[] = {
  342. HDA_CODEC_VOLUME("Side Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  343. HDA_BIND_MUTE("Side Playback Switch", 0x0d, 2, HDA_INPUT),
  344. { } /* end */
  345. };
  346. /* channel source setting (6/8 channel selection for 5-stack) */
  347. /* 6ch mode */
  348. static struct hda_verb alc880_fivestack_ch6_init[] = {
  349. /* set line-in to input, mute it */
  350. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  351. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  352. { } /* end */
  353. };
  354. /* 8ch mode */
  355. static struct hda_verb alc880_fivestack_ch8_init[] = {
  356. /* set line-in to output, unmute it */
  357. { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  358. { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
  359. { } /* end */
  360. };
  361. static struct hda_channel_mode alc880_fivestack_modes[2] = {
  362. { 6, alc880_fivestack_ch6_init },
  363. { 8, alc880_fivestack_ch8_init },
  364. };
  365. /*
  366. * ALC880 6-stack model
  367. *
  368. * DAC: Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e), Side = 0x05 (0x0f)
  369. * Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, Side = 0x17,
  370. * Mic = 0x18, F-Mic = 0x19, Line = 0x1a, HP = 0x1b
  371. */
  372. static hda_nid_t alc880_6st_dac_nids[4] = {
  373. /* front, rear, clfe, rear_surr */
  374. 0x02, 0x03, 0x04, 0x05
  375. };
  376. static struct hda_input_mux alc880_6stack_capture_source = {
  377. .num_items = 4,
  378. .items = {
  379. { "Mic", 0x0 },
  380. { "Front Mic", 0x1 },
  381. { "Line", 0x2 },
  382. { "CD", 0x4 },
  383. },
  384. };
  385. /* fixed 8-channels */
  386. static struct hda_channel_mode alc880_sixstack_modes[1] = {
  387. { 8, NULL },
  388. };
  389. static snd_kcontrol_new_t alc880_six_stack_mixer[] = {
  390. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  391. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  392. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  393. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  394. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  395. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  396. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  397. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  398. HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  399. HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
  400. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  401. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  402. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  403. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  404. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  405. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  406. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
  407. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
  408. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  409. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  410. {
  411. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  412. .name = "Channel Mode",
  413. .info = alc880_ch_mode_info,
  414. .get = alc880_ch_mode_get,
  415. .put = alc880_ch_mode_put,
  416. },
  417. { } /* end */
  418. };
  419. /*
  420. * ALC880 W810 model
  421. *
  422. * W810 has rear IO for:
  423. * Front (DAC 02)
  424. * Surround (DAC 03)
  425. * Center/LFE (DAC 04)
  426. * Digital out (06)
  427. *
  428. * The system also has a pair of internal speakers, and a headphone jack.
  429. * These are both connected to Line2 on the codec, hence to DAC 02.
  430. *
  431. * There is a variable resistor to control the speaker or headphone
  432. * volume. This is a hardware-only device without a software API.
  433. *
  434. * Plugging headphones in will disable the internal speakers. This is
  435. * implemented in hardware, not via the driver using jack sense. In
  436. * a similar fashion, plugging into the rear socket marked "front" will
  437. * disable both the speakers and headphones.
  438. *
  439. * For input, there's a microphone jack, and an "audio in" jack.
  440. * These may not do anything useful with this driver yet, because I
  441. * haven't setup any initialization verbs for these yet...
  442. */
  443. static hda_nid_t alc880_w810_dac_nids[3] = {
  444. /* front, rear/surround, clfe */
  445. 0x02, 0x03, 0x04
  446. };
  447. /* fixed 6 channels */
  448. static struct hda_channel_mode alc880_w810_modes[1] = {
  449. { 6, NULL }
  450. };
  451. /* Pin assignment: Front = 0x14, Surr = 0x15, CLFE = 0x16, HP = 0x1b */
  452. static snd_kcontrol_new_t alc880_w810_base_mixer[] = {
  453. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  454. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  455. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  456. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  457. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  458. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  459. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  460. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  461. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  462. { } /* end */
  463. };
  464. /*
  465. * Z710V model
  466. *
  467. * DAC: Front = 0x02 (0x0c), HP = 0x03 (0x0d)
  468. * Pin assignment: Front = 0x14, HP = 0x15, Mic = 0x18, Mic2 = 0x19(?), Line = 0x1a
  469. */
  470. static hda_nid_t alc880_z71v_dac_nids[1] = {
  471. 0x02
  472. };
  473. #define ALC880_Z71V_HP_DAC 0x03
  474. /* fixed 2 channels */
  475. static struct hda_channel_mode alc880_2_jack_modes[1] = {
  476. { 2, NULL }
  477. };
  478. static snd_kcontrol_new_t alc880_z71v_mixer[] = {
  479. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  480. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  481. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  482. HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
  483. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  484. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  485. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  486. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  487. { } /* end */
  488. };
  489. /* FIXME! */
  490. /*
  491. * ALC880 F1734 model
  492. *
  493. * DAC: HP = 0x02 (0x0c), Front = 0x03 (0x0d)
  494. * Pin assignment: HP = 0x14, Front = 0x15, Mic = 0x18
  495. */
  496. static hda_nid_t alc880_f1734_dac_nids[1] = {
  497. 0x03
  498. };
  499. #define ALC880_F1734_HP_DAC 0x02
  500. static snd_kcontrol_new_t alc880_f1734_mixer[] = {
  501. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  502. HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
  503. HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  504. HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
  505. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  506. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  507. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  508. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  509. { } /* end */
  510. };
  511. /* FIXME! */
  512. /*
  513. * ALC880 ASUS model
  514. *
  515. * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
  516. * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
  517. * Mic = 0x18, Line = 0x1a
  518. */
  519. #define alc880_asus_dac_nids alc880_w810_dac_nids /* identical with w810 */
  520. #define alc880_asus_modes alc880_threestack_modes /* 2/6 channel mode */
  521. static snd_kcontrol_new_t alc880_asus_mixer[] = {
  522. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  523. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  524. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  525. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  526. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  527. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  528. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  529. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  530. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  531. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  532. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  533. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  534. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  535. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  536. {
  537. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  538. .name = "Channel Mode",
  539. .info = alc880_ch_mode_info,
  540. .get = alc880_ch_mode_get,
  541. .put = alc880_ch_mode_put,
  542. },
  543. { } /* end */
  544. };
  545. /* FIXME! */
  546. /*
  547. * ALC880 ASUS W1V model
  548. *
  549. * DAC: HP/Front = 0x02 (0x0c), Surr = 0x03 (0x0d), CLFE = 0x04 (0x0e)
  550. * Pin assignment: HP/Front = 0x14, Surr = 0x15, CLFE = 0x16,
  551. * Mic = 0x18, Line = 0x1a, Line2 = 0x1b
  552. */
  553. /* additional mixers to alc880_asus_mixer */
  554. static snd_kcontrol_new_t alc880_asus_w1v_mixer[] = {
  555. HDA_CODEC_VOLUME("Line2 Playback Volume", 0x0b, 0x03, HDA_INPUT),
  556. HDA_CODEC_MUTE("Line2 Playback Switch", 0x0b, 0x03, HDA_INPUT),
  557. { } /* end */
  558. };
  559. /* additional mixers to alc880_asus_mixer */
  560. static snd_kcontrol_new_t alc880_pcbeep_mixer[] = {
  561. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  562. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  563. { } /* end */
  564. };
  565. /*
  566. * build control elements
  567. */
  568. static int alc_build_controls(struct hda_codec *codec)
  569. {
  570. struct alc_spec *spec = codec->spec;
  571. int err;
  572. int i;
  573. for (i = 0; i < spec->num_mixers; i++) {
  574. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  575. if (err < 0)
  576. return err;
  577. }
  578. if (spec->multiout.dig_out_nid) {
  579. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  580. if (err < 0)
  581. return err;
  582. }
  583. if (spec->dig_in_nid) {
  584. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  585. if (err < 0)
  586. return err;
  587. }
  588. return 0;
  589. }
  590. /*
  591. * initialize the codec volumes, etc
  592. */
  593. /*
  594. * generic initialization of ADC, input mixers and output mixers
  595. */
  596. static struct hda_verb alc880_volume_init_verbs[] = {
  597. /*
  598. * Unmute ADC0-2 and set the default input to mic-in
  599. */
  600. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  601. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  602. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  603. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  604. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  605. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  606. /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
  607. * mixer widget
  608. * Note: PASD motherboards uses the Line In 2 as the input for front panel
  609. * mic (mic 2)
  610. */
  611. /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
  612. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  613. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  614. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  615. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
  616. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  617. /*
  618. * Set up output mixers (0x0c - 0x0f)
  619. */
  620. /* set vol=0 to output mixers */
  621. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  622. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  623. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  624. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  625. /* set up input amps for analog loopback */
  626. /* Amp Indices: DAC = 0, mixer = 1 */
  627. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  628. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  629. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  630. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  631. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  632. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  633. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  634. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  635. { }
  636. };
  637. /*
  638. * 3-stack pin configuration:
  639. * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
  640. */
  641. static struct hda_verb alc880_pin_3stack_init_verbs[] = {
  642. /*
  643. * preset connection lists of input pins
  644. * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
  645. */
  646. {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, /* mic/clfe */
  647. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
  648. {0x12, AC_VERB_SET_CONNECT_SEL, 0x03}, /* line/surround */
  649. /*
  650. * Set pin mode and muting
  651. */
  652. /* set front pin widgets 0x14 for output */
  653. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  654. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  655. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  656. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  657. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  658. /* Mic2 (as headphone out) for HP output */
  659. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  660. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  661. /* Line In pin widget for input */
  662. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  663. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  664. /* Line2 (as front mic) pin widget for input and vref at 80% */
  665. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  666. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  667. /* CD pin widget for input */
  668. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  669. { }
  670. };
  671. /*
  672. * 5-stack pin configuration:
  673. * front = 0x14, surround = 0x17, clfe = 0x16, mic = 0x18, HP = 0x19,
  674. * line-in/side = 0x1a, f-mic = 0x1b
  675. */
  676. static struct hda_verb alc880_pin_5stack_init_verbs[] = {
  677. /*
  678. * preset connection lists of input pins
  679. * 0 = front, 1 = rear_surr, 2 = CLFE, 3 = surround
  680. */
  681. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
  682. {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, /* line/side */
  683. /*
  684. * Set pin mode and muting
  685. */
  686. /* set pin widgets 0x14-0x17 for output */
  687. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  688. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  689. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  690. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  691. /* unmute pins for output (no gain on this amp) */
  692. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  693. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  694. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  695. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  696. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  697. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  698. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  699. /* Mic2 (as headphone out) for HP output */
  700. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  701. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  702. /* Line In pin widget for input */
  703. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  704. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  705. /* Line2 (as front mic) pin widget for input and vref at 80% */
  706. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  707. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  708. /* CD pin widget for input */
  709. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  710. { }
  711. };
  712. /*
  713. * W810 pin configuration:
  714. * front = 0x14, surround = 0x15, clfe = 0x16, HP = 0x1b
  715. */
  716. static struct hda_verb alc880_pin_w810_init_verbs[] = {
  717. /* hphone/speaker input selector: front DAC */
  718. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  719. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  720. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  721. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  722. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  723. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  724. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  725. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  726. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  727. { }
  728. };
  729. /*
  730. * Z71V pin configuration:
  731. * Speaker-out = 0x14, HP = 0x15, Mic = 0x18, Line-in = 0x1a, Mic2 = 0x1b (?)
  732. */
  733. static struct hda_verb alc880_pin_z71v_init_verbs[] = {
  734. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  735. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  736. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  737. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  738. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  739. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  740. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  741. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  742. { }
  743. };
  744. /*
  745. * 6-stack pin configuration:
  746. * front = 0x14, surr = 0x15, clfe = 0x16, side = 0x17, mic = 0x18, f-mic = 0x19,
  747. * line = 0x1a, HP = 0x1b
  748. */
  749. static struct hda_verb alc880_pin_6stack_init_verbs[] = {
  750. {0x13, AC_VERB_SET_CONNECT_SEL, 0x00}, /* HP */
  751. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  752. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  753. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  754. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  755. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  756. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  757. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  758. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  759. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  760. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  761. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  762. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  763. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  764. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  765. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  766. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  767. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  768. { }
  769. };
  770. /* FIXME! */
  771. /*
  772. * F1734 pin configuration:
  773. * HP = 0x14, speaker-out = 0x15, mic = 0x18
  774. */
  775. static struct hda_verb alc880_pin_f1734_init_verbs[] = {
  776. {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
  777. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
  778. {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
  779. {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
  780. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  781. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  782. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  783. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  784. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  785. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  786. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  787. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  788. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  789. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  790. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  791. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  792. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  793. { }
  794. };
  795. /* FIXME! */
  796. /*
  797. * ASUS pin configuration:
  798. * HP/front = 0x14, surr = 0x15, clfe = 0x16, mic = 0x18, line = 0x1a
  799. */
  800. static struct hda_verb alc880_pin_asus_init_verbs[] = {
  801. {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
  802. {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
  803. {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
  804. {0x13, AC_VERB_SET_CONNECT_SEL, 0x00},
  805. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  806. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  807. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  808. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  809. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  810. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  811. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  812. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  813. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  814. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  815. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  816. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  817. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  818. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  819. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  820. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  821. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  822. { }
  823. };
  824. /* Enable GPIO mask and set output */
  825. static struct hda_verb alc880_gpio1_init_verbs[] = {
  826. {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
  827. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
  828. {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
  829. };
  830. /* Enable GPIO mask and set output */
  831. static struct hda_verb alc880_gpio2_init_verbs[] = {
  832. {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
  833. {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
  834. {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
  835. };
  836. /*
  837. */
  838. static int alc_init(struct hda_codec *codec)
  839. {
  840. struct alc_spec *spec = codec->spec;
  841. unsigned int i;
  842. for (i = 0; i < spec->num_init_verbs; i++)
  843. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  844. return 0;
  845. }
  846. #ifdef CONFIG_PM
  847. /*
  848. * resume
  849. */
  850. static int alc_resume(struct hda_codec *codec)
  851. {
  852. struct alc_spec *spec = codec->spec;
  853. int i;
  854. alc_init(codec);
  855. for (i = 0; i < spec->num_mixers; i++)
  856. snd_hda_resume_ctls(codec, spec->mixers[i]);
  857. if (spec->multiout.dig_out_nid)
  858. snd_hda_resume_spdif_out(codec);
  859. if (spec->dig_in_nid)
  860. snd_hda_resume_spdif_in(codec);
  861. return 0;
  862. }
  863. #endif
  864. /*
  865. * Analog playback callbacks
  866. */
  867. static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
  868. struct hda_codec *codec,
  869. snd_pcm_substream_t *substream)
  870. {
  871. struct alc_spec *spec = codec->spec;
  872. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  873. }
  874. static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  875. struct hda_codec *codec,
  876. unsigned int stream_tag,
  877. unsigned int format,
  878. snd_pcm_substream_t *substream)
  879. {
  880. struct alc_spec *spec = codec->spec;
  881. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag,
  882. format, substream);
  883. }
  884. static int alc880_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  885. struct hda_codec *codec,
  886. snd_pcm_substream_t *substream)
  887. {
  888. struct alc_spec *spec = codec->spec;
  889. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  890. }
  891. /*
  892. * Digital out
  893. */
  894. static int alc880_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  895. struct hda_codec *codec,
  896. snd_pcm_substream_t *substream)
  897. {
  898. struct alc_spec *spec = codec->spec;
  899. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  900. }
  901. static int alc880_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  902. struct hda_codec *codec,
  903. snd_pcm_substream_t *substream)
  904. {
  905. struct alc_spec *spec = codec->spec;
  906. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  907. }
  908. /*
  909. * Analog capture
  910. */
  911. static int alc880_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  912. struct hda_codec *codec,
  913. unsigned int stream_tag,
  914. unsigned int format,
  915. snd_pcm_substream_t *substream)
  916. {
  917. struct alc_spec *spec = codec->spec;
  918. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  919. stream_tag, 0, format);
  920. return 0;
  921. }
  922. static int alc880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  923. struct hda_codec *codec,
  924. snd_pcm_substream_t *substream)
  925. {
  926. struct alc_spec *spec = codec->spec;
  927. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  928. return 0;
  929. }
  930. /*
  931. */
  932. static struct hda_pcm_stream alc880_pcm_analog_playback = {
  933. .substreams = 1,
  934. .channels_min = 2,
  935. .channels_max = 8,
  936. /* NID is set in alc_build_pcms */
  937. .ops = {
  938. .open = alc880_playback_pcm_open,
  939. .prepare = alc880_playback_pcm_prepare,
  940. .cleanup = alc880_playback_pcm_cleanup
  941. },
  942. };
  943. static struct hda_pcm_stream alc880_pcm_analog_capture = {
  944. .substreams = 2,
  945. .channels_min = 2,
  946. .channels_max = 2,
  947. /* NID is set in alc_build_pcms */
  948. .ops = {
  949. .prepare = alc880_capture_pcm_prepare,
  950. .cleanup = alc880_capture_pcm_cleanup
  951. },
  952. };
  953. static struct hda_pcm_stream alc880_pcm_digital_playback = {
  954. .substreams = 1,
  955. .channels_min = 2,
  956. .channels_max = 2,
  957. /* NID is set in alc_build_pcms */
  958. .ops = {
  959. .open = alc880_dig_playback_pcm_open,
  960. .close = alc880_dig_playback_pcm_close
  961. },
  962. };
  963. static struct hda_pcm_stream alc880_pcm_digital_capture = {
  964. .substreams = 1,
  965. .channels_min = 2,
  966. .channels_max = 2,
  967. /* NID is set in alc_build_pcms */
  968. };
  969. static int alc_build_pcms(struct hda_codec *codec)
  970. {
  971. struct alc_spec *spec = codec->spec;
  972. struct hda_pcm *info = spec->pcm_rec;
  973. int i;
  974. codec->num_pcms = 1;
  975. codec->pcm_info = info;
  976. info->name = spec->stream_name_analog;
  977. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_analog_playback);
  978. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
  979. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_analog_capture);
  980. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  981. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
  982. for (i = 0; i < spec->num_channel_mode; i++) {
  983. if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
  984. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
  985. }
  986. }
  987. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  988. codec->num_pcms++;
  989. info++;
  990. info->name = spec->stream_name_digital;
  991. if (spec->multiout.dig_out_nid) {
  992. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
  993. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  994. }
  995. if (spec->dig_in_nid) {
  996. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *(spec->stream_digital_capture);
  997. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  998. }
  999. }
  1000. return 0;
  1001. }
  1002. static void alc_free(struct hda_codec *codec)
  1003. {
  1004. struct alc_spec *spec = codec->spec;
  1005. unsigned int i;
  1006. if (! spec)
  1007. return;
  1008. if (spec->kctl_alloc) {
  1009. for (i = 0; i < spec->num_kctl_used; i++)
  1010. kfree(spec->kctl_alloc[i].name);
  1011. kfree(spec->kctl_alloc);
  1012. }
  1013. kfree(spec);
  1014. }
  1015. /*
  1016. */
  1017. static struct hda_codec_ops alc_patch_ops = {
  1018. .build_controls = alc_build_controls,
  1019. .build_pcms = alc_build_pcms,
  1020. .init = alc_init,
  1021. .free = alc_free,
  1022. #ifdef CONFIG_PM
  1023. .resume = alc_resume,
  1024. #endif
  1025. };
  1026. /*
  1027. * Test configuration for debugging
  1028. *
  1029. * Almost all inputs/outputs are enabled. I/O pins can be configured via
  1030. * enum controls.
  1031. */
  1032. #ifdef CONFIG_SND_DEBUG
  1033. static hda_nid_t alc880_test_dac_nids[4] = {
  1034. 0x02, 0x03, 0x04, 0x05
  1035. };
  1036. static struct hda_input_mux alc880_test_capture_source = {
  1037. .num_items = 5,
  1038. .items = {
  1039. { "In-1", 0x0 },
  1040. { "In-2", 0x1 },
  1041. { "In-3", 0x2 },
  1042. { "In-4", 0x3 },
  1043. { "CD", 0x4 },
  1044. },
  1045. };
  1046. static struct hda_channel_mode alc880_test_modes[4] = {
  1047. { 2, NULL },
  1048. { 4, NULL },
  1049. { 6, NULL },
  1050. { 8, NULL },
  1051. };
  1052. static int alc_test_pin_ctl_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  1053. {
  1054. static char *texts[] = {
  1055. "N/A", "Line Out", "HP Out",
  1056. "In Hi-Z", "In 50%", "In Grd", "In 80%", "In 100%"
  1057. };
  1058. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1059. uinfo->count = 1;
  1060. uinfo->value.enumerated.items = 8;
  1061. if (uinfo->value.enumerated.item >= 8)
  1062. uinfo->value.enumerated.item = 7;
  1063. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1064. return 0;
  1065. }
  1066. static int alc_test_pin_ctl_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  1067. {
  1068. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1069. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1070. unsigned int pin_ctl, item = 0;
  1071. pin_ctl = snd_hda_codec_read(codec, nid, 0,
  1072. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1073. if (pin_ctl & AC_PINCTL_OUT_EN) {
  1074. if (pin_ctl & AC_PINCTL_HP_EN)
  1075. item = 2;
  1076. else
  1077. item = 1;
  1078. } else if (pin_ctl & AC_PINCTL_IN_EN) {
  1079. switch (pin_ctl & AC_PINCTL_VREFEN) {
  1080. case AC_PINCTL_VREF_HIZ: item = 3; break;
  1081. case AC_PINCTL_VREF_50: item = 4; break;
  1082. case AC_PINCTL_VREF_GRD: item = 5; break;
  1083. case AC_PINCTL_VREF_80: item = 6; break;
  1084. case AC_PINCTL_VREF_100: item = 7; break;
  1085. }
  1086. }
  1087. ucontrol->value.enumerated.item[0] = item;
  1088. return 0;
  1089. }
  1090. static int alc_test_pin_ctl_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  1091. {
  1092. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1093. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1094. static unsigned int ctls[] = {
  1095. 0, AC_PINCTL_OUT_EN, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN,
  1096. AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ,
  1097. AC_PINCTL_IN_EN | AC_PINCTL_VREF_50,
  1098. AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD,
  1099. AC_PINCTL_IN_EN | AC_PINCTL_VREF_80,
  1100. AC_PINCTL_IN_EN | AC_PINCTL_VREF_100,
  1101. };
  1102. unsigned int old_ctl, new_ctl;
  1103. old_ctl = snd_hda_codec_read(codec, nid, 0,
  1104. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1105. new_ctl = ctls[ucontrol->value.enumerated.item[0]];
  1106. if (old_ctl != new_ctl) {
  1107. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, new_ctl);
  1108. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1109. ucontrol->value.enumerated.item[0] >= 3 ? 0xb080 : 0xb000);
  1110. return 1;
  1111. }
  1112. return 0;
  1113. }
  1114. static int alc_test_pin_src_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
  1115. {
  1116. static char *texts[] = {
  1117. "Front", "Surround", "CLFE", "Side"
  1118. };
  1119. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  1120. uinfo->count = 1;
  1121. uinfo->value.enumerated.items = 4;
  1122. if (uinfo->value.enumerated.item >= 4)
  1123. uinfo->value.enumerated.item = 3;
  1124. strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
  1125. return 0;
  1126. }
  1127. static int alc_test_pin_src_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  1128. {
  1129. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1130. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1131. unsigned int sel;
  1132. sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0);
  1133. ucontrol->value.enumerated.item[0] = sel & 3;
  1134. return 0;
  1135. }
  1136. static int alc_test_pin_src_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  1137. {
  1138. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1139. hda_nid_t nid = (hda_nid_t)kcontrol->private_value;
  1140. unsigned int sel;
  1141. sel = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_CONNECT_SEL, 0) & 3;
  1142. if (ucontrol->value.enumerated.item[0] != sel) {
  1143. sel = ucontrol->value.enumerated.item[0] & 3;
  1144. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, sel);
  1145. return 1;
  1146. }
  1147. return 0;
  1148. }
  1149. #define PIN_CTL_TEST(xname,nid) { \
  1150. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1151. .name = xname, \
  1152. .info = alc_test_pin_ctl_info, \
  1153. .get = alc_test_pin_ctl_get, \
  1154. .put = alc_test_pin_ctl_put, \
  1155. .private_value = nid \
  1156. }
  1157. #define PIN_SRC_TEST(xname,nid) { \
  1158. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1159. .name = xname, \
  1160. .info = alc_test_pin_src_info, \
  1161. .get = alc_test_pin_src_get, \
  1162. .put = alc_test_pin_src_put, \
  1163. .private_value = nid \
  1164. }
  1165. static snd_kcontrol_new_t alc880_test_mixer[] = {
  1166. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  1167. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  1168. HDA_CODEC_VOLUME("CLFE Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
  1169. HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  1170. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  1171. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  1172. HDA_BIND_MUTE("CLFE Playback Switch", 0x0e, 2, HDA_INPUT),
  1173. HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
  1174. PIN_CTL_TEST("Front Pin Mode", 0x14),
  1175. PIN_CTL_TEST("Surround Pin Mode", 0x15),
  1176. PIN_CTL_TEST("CLFE Pin Mode", 0x16),
  1177. PIN_CTL_TEST("Side Pin Mode", 0x17),
  1178. PIN_CTL_TEST("In-1 Pin Mode", 0x18),
  1179. PIN_CTL_TEST("In-2 Pin Mode", 0x19),
  1180. PIN_CTL_TEST("In-3 Pin Mode", 0x1a),
  1181. PIN_CTL_TEST("In-4 Pin Mode", 0x1b),
  1182. PIN_SRC_TEST("In-1 Pin Source", 0x18),
  1183. PIN_SRC_TEST("In-2 Pin Source", 0x19),
  1184. PIN_SRC_TEST("In-3 Pin Source", 0x1a),
  1185. PIN_SRC_TEST("In-4 Pin Source", 0x1b),
  1186. HDA_CODEC_VOLUME("In-1 Playback Volume", 0x0b, 0x0, HDA_INPUT),
  1187. HDA_CODEC_MUTE("In-1 Playback Switch", 0x0b, 0x0, HDA_INPUT),
  1188. HDA_CODEC_VOLUME("In-2 Playback Volume", 0x0b, 0x1, HDA_INPUT),
  1189. HDA_CODEC_MUTE("In-2 Playback Switch", 0x0b, 0x1, HDA_INPUT),
  1190. HDA_CODEC_VOLUME("In-3 Playback Volume", 0x0b, 0x2, HDA_INPUT),
  1191. HDA_CODEC_MUTE("In-3 Playback Switch", 0x0b, 0x2, HDA_INPUT),
  1192. HDA_CODEC_VOLUME("In-4 Playback Volume", 0x0b, 0x3, HDA_INPUT),
  1193. HDA_CODEC_MUTE("In-4 Playback Switch", 0x0b, 0x3, HDA_INPUT),
  1194. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x4, HDA_INPUT),
  1195. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x4, HDA_INPUT),
  1196. {
  1197. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1198. .name = "Channel Mode",
  1199. .info = alc880_ch_mode_info,
  1200. .get = alc880_ch_mode_get,
  1201. .put = alc880_ch_mode_put,
  1202. },
  1203. { } /* end */
  1204. };
  1205. static struct hda_verb alc880_test_init_verbs[] = {
  1206. /* Unmute inputs of 0x0c - 0x0f */
  1207. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1208. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1209. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1210. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1211. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1212. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1213. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  1214. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
  1215. /* Vol output for 0x0c-0x0f */
  1216. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1217. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1218. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1219. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  1220. /* Set output pins 0x14-0x17 */
  1221. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1222. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1223. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1224. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1225. /* Unmute output pins 0x14-0x17 */
  1226. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1227. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1228. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1229. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1230. /* Set input pins 0x18-0x1c */
  1231. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1232. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1233. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1234. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1235. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1236. /* Mute input pins 0x18-0x1b */
  1237. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1238. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1239. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1240. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1241. /* ADC set up */
  1242. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1243. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  1244. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1245. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  1246. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1247. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  1248. /* Analog input/passthru */
  1249. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1250. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1251. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  1252. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1253. {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1254. { }
  1255. };
  1256. #endif
  1257. /*
  1258. */
  1259. static struct hda_board_config alc880_cfg_tbl[] = {
  1260. /* Back 3 jack, front 2 jack */
  1261. { .modelname = "3stack", .config = ALC880_3ST },
  1262. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe200, .config = ALC880_3ST },
  1263. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe201, .config = ALC880_3ST },
  1264. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe202, .config = ALC880_3ST },
  1265. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe203, .config = ALC880_3ST },
  1266. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe204, .config = ALC880_3ST },
  1267. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe205, .config = ALC880_3ST },
  1268. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe206, .config = ALC880_3ST },
  1269. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe207, .config = ALC880_3ST },
  1270. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe208, .config = ALC880_3ST },
  1271. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe209, .config = ALC880_3ST },
  1272. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20a, .config = ALC880_3ST },
  1273. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20b, .config = ALC880_3ST },
  1274. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20c, .config = ALC880_3ST },
  1275. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20d, .config = ALC880_3ST },
  1276. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20e, .config = ALC880_3ST },
  1277. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe20f, .config = ALC880_3ST },
  1278. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe210, .config = ALC880_3ST },
  1279. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe211, .config = ALC880_3ST },
  1280. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe214, .config = ALC880_3ST },
  1281. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe302, .config = ALC880_3ST },
  1282. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe303, .config = ALC880_3ST },
  1283. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe304, .config = ALC880_3ST },
  1284. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe306, .config = ALC880_3ST },
  1285. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe307, .config = ALC880_3ST },
  1286. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe404, .config = ALC880_3ST },
  1287. { .pci_subvendor = 0x8086, .pci_subdevice = 0xa101, .config = ALC880_3ST },
  1288. { .pci_subvendor = 0x107b, .pci_subdevice = 0x3031, .config = ALC880_3ST },
  1289. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4036, .config = ALC880_3ST },
  1290. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4037, .config = ALC880_3ST },
  1291. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4038, .config = ALC880_3ST },
  1292. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4040, .config = ALC880_3ST },
  1293. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4041, .config = ALC880_3ST },
  1294. /* Back 3 jack, front 2 jack (Internal add Aux-In) */
  1295. { .pci_subvendor = 0x1025, .pci_subdevice = 0xe310, .config = ALC880_3ST },
  1296. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81d6, .config = ALC880_3ST },
  1297. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81a0, .config = ALC880_3ST },
  1298. /* Back 3 jack plus 1 SPDIF out jack, front 2 jack */
  1299. { .modelname = "3stack-digout", .config = ALC880_3ST_DIG },
  1300. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe308, .config = ALC880_3ST_DIG },
  1301. { .pci_subvendor = 0x1025, .pci_subdevice = 0x0070, .config = ALC880_3ST_DIG },
  1302. /* Back 3 jack plus 1 SPDIF out jack, front 2 jack (Internal add Aux-In)*/
  1303. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe305, .config = ALC880_3ST_DIG },
  1304. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd402, .config = ALC880_3ST_DIG },
  1305. { .pci_subvendor = 0x1025, .pci_subdevice = 0xe309, .config = ALC880_3ST_DIG },
  1306. /* Back 5 jack, front 2 jack */
  1307. { .modelname = "5stack", .config = ALC880_5ST },
  1308. { .pci_subvendor = 0x107b, .pci_subdevice = 0x3033, .config = ALC880_5ST },
  1309. { .pci_subvendor = 0x107b, .pci_subdevice = 0x4039, .config = ALC880_5ST },
  1310. { .pci_subvendor = 0x107b, .pci_subdevice = 0x3032, .config = ALC880_5ST },
  1311. { .pci_subvendor = 0x103c, .pci_subdevice = 0x2a09, .config = ALC880_5ST },
  1312. { .pci_subvendor = 0x1043, .pci_subdevice = 0x814e, .config = ALC880_5ST },
  1313. /* Back 5 jack plus 1 SPDIF out jack, front 2 jack */
  1314. { .modelname = "5stack-digout", .config = ALC880_5ST_DIG },
  1315. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe224, .config = ALC880_5ST_DIG },
  1316. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe400, .config = ALC880_5ST_DIG },
  1317. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe401, .config = ALC880_5ST_DIG },
  1318. { .pci_subvendor = 0x8086, .pci_subdevice = 0xe402, .config = ALC880_5ST_DIG },
  1319. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd400, .config = ALC880_5ST_DIG },
  1320. { .pci_subvendor = 0x8086, .pci_subdevice = 0xd401, .config = ALC880_5ST_DIG },
  1321. { .pci_subvendor = 0x8086, .pci_subdevice = 0xa100, .config = ALC880_5ST_DIG },
  1322. { .pci_subvendor = 0x1565, .pci_subdevice = 0x8202, .config = ALC880_5ST_DIG },
  1323. { .pci_subvendor = 0x1019, .pci_subdevice = 0xa880, .config = ALC880_5ST_DIG },
  1324. /* { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_5ST_DIG }, */ /* conflict with 6stack */
  1325. { .pci_subvendor = 0x1695, .pci_subdevice = 0x400d, .config = ALC880_5ST_DIG },
  1326. /* note subvendor = 0 below */
  1327. /* { .pci_subvendor = 0x0000, .pci_subdevice = 0x8086, .config = ALC880_5ST_DIG }, */
  1328. { .modelname = "w810", .config = ALC880_W810 },
  1329. { .pci_subvendor = 0x161f, .pci_subdevice = 0x203d, .config = ALC880_W810 },
  1330. { .modelname = "z71v", .config = ALC880_Z71V },
  1331. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_Z71V },
  1332. { .modelname = "6stack", .config = ALC880_6ST },
  1333. { .pci_subvendor = 0x1019, .pci_subdevice = 0xa884, .config = ALC880_6ST }, /* Acer APFV */
  1334. { .modelname = "6stack-digout", .config = ALC880_6ST_DIG },
  1335. { .pci_subvendor = 0x2668, .pci_subdevice = 0x8086, .config = ALC880_6ST_DIG },
  1336. { .pci_subvendor = 0x8086, .pci_subdevice = 0x2668, .config = ALC880_6ST_DIG },
  1337. { .pci_subvendor = 0x1462, .pci_subdevice = 0x1150, .config = ALC880_6ST_DIG },
  1338. { .pci_subvendor = 0xe803, .pci_subdevice = 0x1019, .config = ALC880_6ST_DIG },
  1339. { .modelname = "asus", .config = ALC880_ASUS },
  1340. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1964, .config = ALC880_ASUS_DIG },
  1341. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1973, .config = ALC880_ASUS_DIG },
  1342. { .pci_subvendor = 0x1043, .pci_subdevice = 0x19b3, .config = ALC880_ASUS_DIG },
  1343. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1113, .config = ALC880_ASUS_DIG },
  1344. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1173, .config = ALC880_ASUS_DIG },
  1345. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1993, .config = ALC880_ASUS },
  1346. { .pci_subvendor = 0x1043, .pci_subdevice = 0x10c3, .config = ALC880_ASUS_DIG },
  1347. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1133, .config = ALC880_ASUS },
  1348. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1123, .config = ALC880_ASUS_DIG },
  1349. { .pci_subvendor = 0x1043, .pci_subdevice = 0x1143, .config = ALC880_ASUS },
  1350. { .pci_subvendor = 0x1043, .pci_subdevice = 0x10b3, .config = ALC880_ASUS_W1V },
  1351. { .modelname = "uniwill", .config = ALC880_UNIWILL_DIG },
  1352. { .pci_subvendor = 0x1584, .pci_subdevice = 0x9050, .config = ALC880_UNIWILL_DIG },
  1353. { .modelname = "F1734", .config = ALC880_F1734 },
  1354. { .pci_subvendor = 0x1734, .pci_subdevice = 0x107c, .config = ALC880_F1734 },
  1355. #ifdef CONFIG_SND_DEBUG
  1356. { .modelname = "test", .config = ALC880_TEST },
  1357. #endif
  1358. {}
  1359. };
  1360. /*
  1361. * configuration template - to be copied to the spec instance
  1362. */
  1363. struct alc_config_preset {
  1364. snd_kcontrol_new_t *mixers[4];
  1365. const struct hda_verb *init_verbs[4];
  1366. unsigned int num_dacs;
  1367. hda_nid_t *dac_nids;
  1368. hda_nid_t dig_out_nid; /* optional */
  1369. hda_nid_t hp_nid; /* optional */
  1370. unsigned int num_adc_nids;
  1371. hda_nid_t *adc_nids;
  1372. unsigned int num_channel_mode;
  1373. const struct hda_channel_mode *channel_mode;
  1374. const struct hda_input_mux *input_mux;
  1375. };
  1376. static struct alc_config_preset alc880_presets[] = {
  1377. [ALC880_3ST] = {
  1378. .mixers = { alc880_three_stack_mixer },
  1379. .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
  1380. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1381. .dac_nids = alc880_dac_nids,
  1382. .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
  1383. .channel_mode = alc880_threestack_modes,
  1384. .input_mux = &alc880_capture_source,
  1385. },
  1386. [ALC880_3ST_DIG] = {
  1387. .mixers = { alc880_three_stack_mixer },
  1388. .init_verbs = { alc880_volume_init_verbs, alc880_pin_3stack_init_verbs },
  1389. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1390. .dac_nids = alc880_dac_nids,
  1391. .dig_out_nid = ALC880_DIGOUT_NID,
  1392. .num_channel_mode = ARRAY_SIZE(alc880_threestack_modes),
  1393. .channel_mode = alc880_threestack_modes,
  1394. .input_mux = &alc880_capture_source,
  1395. },
  1396. [ALC880_5ST] = {
  1397. .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer},
  1398. .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
  1399. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1400. .dac_nids = alc880_dac_nids,
  1401. .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
  1402. .channel_mode = alc880_fivestack_modes,
  1403. .input_mux = &alc880_capture_source,
  1404. },
  1405. [ALC880_5ST_DIG] = {
  1406. .mixers = { alc880_three_stack_mixer, alc880_five_stack_mixer },
  1407. .init_verbs = { alc880_volume_init_verbs, alc880_pin_5stack_init_verbs },
  1408. .num_dacs = ARRAY_SIZE(alc880_dac_nids),
  1409. .dac_nids = alc880_dac_nids,
  1410. .dig_out_nid = ALC880_DIGOUT_NID,
  1411. .num_channel_mode = ARRAY_SIZE(alc880_fivestack_modes),
  1412. .channel_mode = alc880_fivestack_modes,
  1413. .input_mux = &alc880_capture_source,
  1414. },
  1415. [ALC880_6ST] = {
  1416. .mixers = { alc880_six_stack_mixer },
  1417. .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
  1418. .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
  1419. .dac_nids = alc880_6st_dac_nids,
  1420. .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
  1421. .channel_mode = alc880_sixstack_modes,
  1422. .input_mux = &alc880_6stack_capture_source,
  1423. },
  1424. [ALC880_6ST_DIG] = {
  1425. .mixers = { alc880_six_stack_mixer },
  1426. .init_verbs = { alc880_volume_init_verbs, alc880_pin_6stack_init_verbs },
  1427. .num_dacs = ARRAY_SIZE(alc880_6st_dac_nids),
  1428. .dac_nids = alc880_6st_dac_nids,
  1429. .dig_out_nid = ALC880_DIGOUT_NID,
  1430. .num_channel_mode = ARRAY_SIZE(alc880_sixstack_modes),
  1431. .channel_mode = alc880_sixstack_modes,
  1432. .input_mux = &alc880_6stack_capture_source,
  1433. },
  1434. [ALC880_W810] = {
  1435. .mixers = { alc880_w810_base_mixer },
  1436. .init_verbs = { alc880_volume_init_verbs, alc880_pin_w810_init_verbs,
  1437. alc880_gpio2_init_verbs },
  1438. .num_dacs = ARRAY_SIZE(alc880_w810_dac_nids),
  1439. .dac_nids = alc880_w810_dac_nids,
  1440. .dig_out_nid = ALC880_DIGOUT_NID,
  1441. .num_channel_mode = ARRAY_SIZE(alc880_w810_modes),
  1442. .channel_mode = alc880_w810_modes,
  1443. .input_mux = &alc880_capture_source,
  1444. },
  1445. [ALC880_Z71V] = {
  1446. .mixers = { alc880_z71v_mixer },
  1447. .init_verbs = { alc880_volume_init_verbs, alc880_pin_z71v_init_verbs },
  1448. .num_dacs = ARRAY_SIZE(alc880_z71v_dac_nids),
  1449. .dac_nids = alc880_z71v_dac_nids,
  1450. .dig_out_nid = ALC880_DIGOUT_NID,
  1451. .hp_nid = 0x03,
  1452. .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
  1453. .channel_mode = alc880_2_jack_modes,
  1454. .input_mux = &alc880_capture_source,
  1455. },
  1456. [ALC880_F1734] = {
  1457. .mixers = { alc880_f1734_mixer },
  1458. .init_verbs = { alc880_volume_init_verbs, alc880_pin_f1734_init_verbs },
  1459. .num_dacs = ARRAY_SIZE(alc880_f1734_dac_nids),
  1460. .dac_nids = alc880_f1734_dac_nids,
  1461. .hp_nid = 0x02,
  1462. .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
  1463. .channel_mode = alc880_2_jack_modes,
  1464. .input_mux = &alc880_capture_source,
  1465. },
  1466. [ALC880_ASUS] = {
  1467. .mixers = { alc880_asus_mixer },
  1468. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1469. alc880_gpio1_init_verbs },
  1470. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1471. .dac_nids = alc880_asus_dac_nids,
  1472. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1473. .channel_mode = alc880_asus_modes,
  1474. .input_mux = &alc880_capture_source,
  1475. },
  1476. [ALC880_ASUS_DIG] = {
  1477. .mixers = { alc880_asus_mixer },
  1478. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1479. alc880_gpio1_init_verbs },
  1480. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1481. .dac_nids = alc880_asus_dac_nids,
  1482. .dig_out_nid = ALC880_DIGOUT_NID,
  1483. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1484. .channel_mode = alc880_asus_modes,
  1485. .input_mux = &alc880_capture_source,
  1486. },
  1487. [ALC880_ASUS_W1V] = {
  1488. .mixers = { alc880_asus_mixer, alc880_asus_w1v_mixer },
  1489. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs,
  1490. alc880_gpio1_init_verbs },
  1491. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1492. .dac_nids = alc880_asus_dac_nids,
  1493. .dig_out_nid = ALC880_DIGOUT_NID,
  1494. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1495. .channel_mode = alc880_asus_modes,
  1496. .input_mux = &alc880_capture_source,
  1497. },
  1498. [ALC880_UNIWILL_DIG] = {
  1499. .mixers = { alc880_asus_mixer, alc880_pcbeep_mixer },
  1500. .init_verbs = { alc880_volume_init_verbs, alc880_pin_asus_init_verbs },
  1501. .num_dacs = ARRAY_SIZE(alc880_asus_dac_nids),
  1502. .dac_nids = alc880_asus_dac_nids,
  1503. .dig_out_nid = ALC880_DIGOUT_NID,
  1504. .num_channel_mode = ARRAY_SIZE(alc880_asus_modes),
  1505. .channel_mode = alc880_asus_modes,
  1506. .input_mux = &alc880_capture_source,
  1507. },
  1508. #ifdef CONFIG_SND_DEBUG
  1509. [ALC880_TEST] = {
  1510. .mixers = { alc880_test_mixer },
  1511. .init_verbs = { alc880_test_init_verbs },
  1512. .num_dacs = ARRAY_SIZE(alc880_test_dac_nids),
  1513. .dac_nids = alc880_test_dac_nids,
  1514. .dig_out_nid = ALC880_DIGOUT_NID,
  1515. .num_channel_mode = ARRAY_SIZE(alc880_test_modes),
  1516. .channel_mode = alc880_test_modes,
  1517. .input_mux = &alc880_test_capture_source,
  1518. },
  1519. #endif
  1520. };
  1521. /*
  1522. * Automatic parse of I/O pins from the BIOS configuration
  1523. */
  1524. #define NUM_CONTROL_ALLOC 32
  1525. #define NUM_VERB_ALLOC 32
  1526. enum {
  1527. ALC_CTL_WIDGET_VOL,
  1528. ALC_CTL_WIDGET_MUTE,
  1529. ALC_CTL_BIND_MUTE,
  1530. };
  1531. static snd_kcontrol_new_t alc880_control_templates[] = {
  1532. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  1533. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  1534. HDA_BIND_MUTE(NULL, 0, 0, 0),
  1535. };
  1536. /* add dynamic controls */
  1537. static int add_control(struct alc_spec *spec, int type, const char *name, unsigned long val)
  1538. {
  1539. snd_kcontrol_new_t *knew;
  1540. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  1541. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  1542. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  1543. if (! knew)
  1544. return -ENOMEM;
  1545. if (spec->kctl_alloc) {
  1546. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1547. kfree(spec->kctl_alloc);
  1548. }
  1549. spec->kctl_alloc = knew;
  1550. spec->num_kctl_alloc = num;
  1551. }
  1552. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1553. *knew = alc880_control_templates[type];
  1554. knew->name = kstrdup(name, GFP_KERNEL);
  1555. if (! knew->name)
  1556. return -ENOMEM;
  1557. knew->private_value = val;
  1558. spec->num_kctl_used++;
  1559. return 0;
  1560. }
  1561. #define alc880_is_fixed_pin(nid) ((nid) >= 0x14 && (nid) <= 0x17)
  1562. #define alc880_fixed_pin_idx(nid) ((nid) - 0x14)
  1563. #define alc880_is_multi_pin(nid) ((nid) >= 0x18)
  1564. #define alc880_multi_pin_idx(nid) ((nid) - 0x18)
  1565. #define alc880_is_input_pin(nid) ((nid) >= 0x18)
  1566. #define alc880_input_pin_idx(nid) ((nid) - 0x18)
  1567. #define alc880_idx_to_dac(nid) ((nid) + 0x02)
  1568. #define alc880_dac_to_idx(nid) ((nid) - 0x02)
  1569. #define alc880_idx_to_mixer(nid) ((nid) + 0x0c)
  1570. #define alc880_idx_to_selector(nid) ((nid) + 0x10)
  1571. #define ALC880_PIN_CD_NID 0x1c
  1572. /* fill in the dac_nids table from the parsed pin configuration */
  1573. static int alc880_auto_fill_dac_nids(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  1574. {
  1575. hda_nid_t nid;
  1576. int assigned[4];
  1577. int i, j;
  1578. memset(assigned, 0, sizeof(assigned));
  1579. spec->multiout.dac_nids = spec->private_dac_nids;
  1580. /* check the pins hardwired to audio widget */
  1581. for (i = 0; i < cfg->line_outs; i++) {
  1582. nid = cfg->line_out_pins[i];
  1583. if (alc880_is_fixed_pin(nid)) {
  1584. int idx = alc880_fixed_pin_idx(nid);
  1585. spec->multiout.dac_nids[i] = alc880_dac_to_idx(idx);
  1586. assigned[idx] = 1;
  1587. }
  1588. }
  1589. /* left pins can be connect to any audio widget */
  1590. for (i = 0; i < cfg->line_outs; i++) {
  1591. nid = cfg->line_out_pins[i];
  1592. if (alc880_is_fixed_pin(nid))
  1593. continue;
  1594. /* search for an empty channel */
  1595. for (j = 0; j < cfg->line_outs; j++) {
  1596. if (! assigned[j]) {
  1597. spec->multiout.dac_nids[i] = alc880_idx_to_dac(j);
  1598. assigned[j] = 1;
  1599. break;
  1600. }
  1601. }
  1602. }
  1603. spec->multiout.num_dacs = cfg->line_outs;
  1604. return 0;
  1605. }
  1606. /* add playback controls from the parsed DAC table */
  1607. static int alc880_auto_create_multi_out_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  1608. {
  1609. char name[32];
  1610. static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
  1611. hda_nid_t nid;
  1612. int i, err;
  1613. for (i = 0; i < cfg->line_outs; i++) {
  1614. if (! spec->multiout.dac_nids[i])
  1615. continue;
  1616. nid = alc880_idx_to_mixer(alc880_dac_to_idx(spec->multiout.dac_nids[i]));
  1617. if (i == 2) {
  1618. /* Center/LFE */
  1619. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Center Playback Volume",
  1620. HDA_COMPOSE_AMP_VAL(nid, 1, 0, HDA_OUTPUT))) < 0)
  1621. return err;
  1622. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "LFE Playback Volume",
  1623. HDA_COMPOSE_AMP_VAL(nid, 2, 0, HDA_OUTPUT))) < 0)
  1624. return err;
  1625. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Center Playback Switch",
  1626. HDA_COMPOSE_AMP_VAL(nid, 1, 2, HDA_INPUT))) < 0)
  1627. return err;
  1628. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "LFE Playback Switch",
  1629. HDA_COMPOSE_AMP_VAL(nid, 2, 2, HDA_INPUT))) < 0)
  1630. return err;
  1631. } else {
  1632. sprintf(name, "%s Playback Volume", chname[i]);
  1633. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
  1634. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  1635. return err;
  1636. sprintf(name, "%s Playback Switch", chname[i]);
  1637. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, name,
  1638. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  1639. return err;
  1640. }
  1641. }
  1642. return 0;
  1643. }
  1644. /* add playback controls for HP output */
  1645. static int alc880_auto_create_hp_ctls(struct alc_spec *spec, hda_nid_t pin)
  1646. {
  1647. hda_nid_t nid;
  1648. int err;
  1649. if (! pin)
  1650. return 0;
  1651. if (alc880_is_fixed_pin(pin)) {
  1652. nid = alc880_idx_to_dac(alc880_fixed_pin_idx(pin));
  1653. if (! spec->multiout.dac_nids[0]) {
  1654. /* use this as the primary output */
  1655. spec->multiout.dac_nids[0] = nid;
  1656. if (! spec->multiout.num_dacs)
  1657. spec->multiout.num_dacs = 1;
  1658. } else
  1659. /* specify the DAC as the extra HP output */
  1660. spec->multiout.hp_nid = nid;
  1661. /* control HP volume/switch on the output mixer amp */
  1662. nid = alc880_idx_to_mixer(alc880_fixed_pin_idx(pin));
  1663. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, "Headphone Playback Volume",
  1664. HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT))) < 0)
  1665. return err;
  1666. if ((err = add_control(spec, ALC_CTL_BIND_MUTE, "Headphone Playback Switch",
  1667. HDA_COMPOSE_AMP_VAL(nid, 3, 2, HDA_INPUT))) < 0)
  1668. return err;
  1669. } else if (alc880_is_multi_pin(pin)) {
  1670. /* set manual connection */
  1671. if (! spec->multiout.dac_nids[0]) {
  1672. /* use this as the primary output */
  1673. spec->multiout.dac_nids[0] = alc880_idx_to_dac(alc880_multi_pin_idx(pin));
  1674. if (! spec->multiout.num_dacs)
  1675. spec->multiout.num_dacs = 1;
  1676. }
  1677. /* we have only a switch on HP-out PIN */
  1678. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, "Headphone Playback Switch",
  1679. HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT))) < 0)
  1680. return err;
  1681. }
  1682. return 0;
  1683. }
  1684. /* create input playback/capture controls for the given pin */
  1685. static int new_analog_input(struct alc_spec *spec, hda_nid_t pin, const char *ctlname)
  1686. {
  1687. char name[32];
  1688. int err, idx;
  1689. sprintf(name, "%s Playback Volume", ctlname);
  1690. idx = alc880_input_pin_idx(pin);
  1691. if ((err = add_control(spec, ALC_CTL_WIDGET_VOL, name,
  1692. HDA_COMPOSE_AMP_VAL(0x0b, 3, idx, HDA_INPUT))) < 0)
  1693. return err;
  1694. sprintf(name, "%s Playback Switch", ctlname);
  1695. if ((err = add_control(spec, ALC_CTL_WIDGET_MUTE, name,
  1696. HDA_COMPOSE_AMP_VAL(0x0b, 3, idx, HDA_INPUT))) < 0)
  1697. return err;
  1698. return 0;
  1699. }
  1700. /* create playback/capture controls for input pins */
  1701. static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec, const struct auto_pin_cfg *cfg)
  1702. {
  1703. static char *labels[AUTO_PIN_LAST] = {
  1704. "Mic", "Front Mic", "Line", "Front Line", "CD", "Aux"
  1705. };
  1706. struct hda_input_mux *imux = &spec->private_imux;
  1707. int i, err;
  1708. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1709. if (alc880_is_input_pin(cfg->input_pins[i])) {
  1710. err = new_analog_input(spec, cfg->input_pins[i], labels[i]);
  1711. if (err < 0)
  1712. return err;
  1713. imux->items[imux->num_items].label = labels[i];
  1714. imux->items[imux->num_items].index = alc880_input_pin_idx(cfg->input_pins[i]);
  1715. imux->num_items++;
  1716. }
  1717. }
  1718. return 0;
  1719. }
  1720. static void alc880_auto_set_output_and_unmute(struct hda_codec *codec, hda_nid_t nid, int pin_type,
  1721. int dac_idx)
  1722. {
  1723. /* set as output */
  1724. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  1725. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  1726. /* need the manual connection? */
  1727. if (alc880_is_multi_pin(nid)) {
  1728. struct alc_spec *spec = codec->spec;
  1729. int idx = alc880_multi_pin_idx(nid);
  1730. snd_hda_codec_write(codec, alc880_idx_to_selector(idx), 0,
  1731. AC_VERB_SET_CONNECT_SEL,
  1732. alc880_dac_to_idx(spec->multiout.dac_nids[dac_idx]));
  1733. }
  1734. }
  1735. static void alc880_auto_init_multi_out(struct hda_codec *codec)
  1736. {
  1737. struct alc_spec *spec = codec->spec;
  1738. int i;
  1739. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1740. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1741. alc880_auto_set_output_and_unmute(codec, nid, PIN_OUT, i);
  1742. }
  1743. }
  1744. static void alc880_auto_init_hp_out(struct hda_codec *codec)
  1745. {
  1746. struct alc_spec *spec = codec->spec;
  1747. hda_nid_t pin;
  1748. pin = spec->autocfg.hp_pin;
  1749. if (pin) /* connect to front */
  1750. alc880_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
  1751. }
  1752. static void alc880_auto_init_analog_input(struct hda_codec *codec)
  1753. {
  1754. struct alc_spec *spec = codec->spec;
  1755. int i;
  1756. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1757. hda_nid_t nid = spec->autocfg.input_pins[i];
  1758. if (alc880_is_input_pin(nid)) {
  1759. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1760. i <= AUTO_PIN_FRONT_MIC ? PIN_VREF80 : PIN_IN);
  1761. if (nid != ALC880_PIN_CD_NID)
  1762. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1763. AMP_OUT_MUTE);
  1764. }
  1765. }
  1766. }
  1767. /* parse the BIOS configuration and set up the alc_spec */
  1768. /* return 1 if successful, 0 if the proper config is not found, or a negative error code */
  1769. static int alc880_parse_auto_config(struct hda_codec *codec)
  1770. {
  1771. struct alc_spec *spec = codec->spec;
  1772. int err;
  1773. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg)) < 0)
  1774. return err;
  1775. if ((err = alc880_auto_fill_dac_nids(spec, &spec->autocfg)) < 0)
  1776. return err;
  1777. if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
  1778. return 0; /* can't find valid BIOS pin config */
  1779. if ((err = alc880_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  1780. (err = alc880_auto_create_hp_ctls(spec, spec->autocfg.hp_pin)) < 0 ||
  1781. (err = alc880_auto_create_analog_input_ctls(spec, &spec->autocfg)) < 0)
  1782. return err;
  1783. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1784. if (spec->autocfg.dig_out_pin)
  1785. spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
  1786. if (spec->autocfg.dig_in_pin)
  1787. spec->dig_in_nid = ALC880_DIGIN_NID;
  1788. if (spec->kctl_alloc)
  1789. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1790. spec->init_verbs[spec->num_init_verbs++] = alc880_volume_init_verbs;
  1791. spec->input_mux = &spec->private_imux;
  1792. return 1;
  1793. }
  1794. /* init callback for auto-configuration model -- overriding the default init */
  1795. static int alc880_auto_init(struct hda_codec *codec)
  1796. {
  1797. alc_init(codec);
  1798. alc880_auto_init_multi_out(codec);
  1799. alc880_auto_init_hp_out(codec);
  1800. alc880_auto_init_analog_input(codec);
  1801. return 0;
  1802. }
  1803. /*
  1804. * OK, here we have finally the patch for ALC880
  1805. */
  1806. static int patch_alc880(struct hda_codec *codec)
  1807. {
  1808. struct alc_spec *spec;
  1809. int board_config;
  1810. int i, err;
  1811. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1812. if (spec == NULL)
  1813. return -ENOMEM;
  1814. codec->spec = spec;
  1815. board_config = snd_hda_check_board_config(codec, alc880_cfg_tbl);
  1816. if (board_config < 0 || board_config >= ALC880_MODEL_LAST) {
  1817. printk(KERN_INFO "hda_codec: Unknown model for ALC880, trying auto-probe from BIOS...\n");
  1818. board_config = ALC880_AUTO;
  1819. }
  1820. if (board_config == ALC880_AUTO) {
  1821. /* automatic parse from the BIOS config */
  1822. err = alc880_parse_auto_config(codec);
  1823. if (err < 0) {
  1824. alc_free(codec);
  1825. return err;
  1826. } else if (! err) {
  1827. printk(KERN_INFO "hda_codec: Cannot set up configuration from BIOS. Using 3-stack mode...\n");
  1828. board_config = ALC880_3ST;
  1829. }
  1830. }
  1831. if (board_config != ALC880_AUTO) {
  1832. /* set up from the preset table */
  1833. const struct alc_config_preset *preset;
  1834. preset = &alc880_presets[board_config];
  1835. for (i = 0; preset->mixers[i]; i++) {
  1836. snd_assert(spec->num_mixers < ARRAY_SIZE(spec->mixers), break);
  1837. spec->mixers[spec->num_mixers++] = preset->mixers[i];
  1838. }
  1839. for (i = 0; preset->init_verbs[i]; i++) {
  1840. snd_assert(spec->num_init_verbs < ARRAY_SIZE(spec->init_verbs), break);
  1841. spec->init_verbs[spec->num_init_verbs++] = preset->init_verbs[i];
  1842. }
  1843. spec->channel_mode = preset->channel_mode;
  1844. spec->num_channel_mode = preset->num_channel_mode;
  1845. spec->multiout.max_channels = spec->channel_mode[0].channels;
  1846. spec->multiout.num_dacs = preset->num_dacs;
  1847. spec->multiout.dac_nids = preset->dac_nids;
  1848. spec->multiout.dig_out_nid = preset->dig_out_nid;
  1849. spec->multiout.hp_nid = preset->hp_nid;
  1850. spec->input_mux = preset->input_mux;
  1851. spec->num_adc_nids = preset->num_adc_nids;
  1852. spec->adc_nids = preset->adc_nids;
  1853. }
  1854. spec->stream_name_analog = "ALC880 Analog";
  1855. spec->stream_analog_playback = &alc880_pcm_analog_playback;
  1856. spec->stream_analog_capture = &alc880_pcm_analog_capture;
  1857. spec->stream_name_digital = "ALC880 Digital";
  1858. spec->stream_digital_playback = &alc880_pcm_digital_playback;
  1859. spec->stream_digital_capture = &alc880_pcm_digital_capture;
  1860. if (! spec->adc_nids && spec->input_mux) {
  1861. /* check whether NID 0x07 is valid */
  1862. unsigned int wcap = snd_hda_param_read(codec, alc880_adc_nids[0],
  1863. AC_PAR_AUDIO_WIDGET_CAP);
  1864. wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
  1865. if (wcap != AC_WID_AUD_IN) {
  1866. spec->adc_nids = alc880_adc_nids_alt;
  1867. spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids_alt);
  1868. spec->mixers[spec->num_mixers] = alc880_capture_alt_mixer;
  1869. spec->num_mixers++;
  1870. } else {
  1871. spec->adc_nids = alc880_adc_nids;
  1872. spec->num_adc_nids = ARRAY_SIZE(alc880_adc_nids);
  1873. spec->mixers[spec->num_mixers] = alc880_capture_mixer;
  1874. spec->num_mixers++;
  1875. }
  1876. }
  1877. codec->patch_ops = alc_patch_ops;
  1878. if (board_config == ALC880_AUTO)
  1879. codec->patch_ops.init = alc880_auto_init;
  1880. return 0;
  1881. }
  1882. /*
  1883. * ALC260 support
  1884. */
  1885. static hda_nid_t alc260_dac_nids[1] = {
  1886. /* front */
  1887. 0x02,
  1888. };
  1889. static hda_nid_t alc260_adc_nids[1] = {
  1890. /* ADC0 */
  1891. 0x04,
  1892. };
  1893. static hda_nid_t alc260_hp_adc_nids[1] = {
  1894. /* ADC1 */
  1895. 0x05,
  1896. };
  1897. #define ALC260_DIGOUT_NID 0x03
  1898. #define ALC260_DIGIN_NID 0x06
  1899. static struct hda_input_mux alc260_capture_source = {
  1900. .num_items = 4,
  1901. .items = {
  1902. { "Mic", 0x0 },
  1903. { "Front Mic", 0x1 },
  1904. { "Line", 0x2 },
  1905. { "CD", 0x4 },
  1906. },
  1907. };
  1908. /* On Fujitsu S702x laptops capture only makes sense from Mic/LineIn jack
  1909. * and the internal CD lines.
  1910. */
  1911. static struct hda_input_mux alc260_fujitsu_capture_source = {
  1912. .num_items = 2,
  1913. .items = {
  1914. { "Mic/Line", 0x0 },
  1915. { "CD", 0x4 },
  1916. },
  1917. };
  1918. /*
  1919. * This is just place-holder, so there's something for alc_build_pcms to look
  1920. * at when it calculates the maximum number of channels. ALC260 has no mixer
  1921. * element which allows changing the channel mode, so the verb list is
  1922. * never used.
  1923. */
  1924. static struct hda_channel_mode alc260_modes[1] = {
  1925. { 2, NULL },
  1926. };
  1927. static snd_kcontrol_new_t alc260_base_mixer[] = {
  1928. HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  1929. HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
  1930. HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
  1931. HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
  1932. HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
  1933. HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
  1934. HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
  1935. HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
  1936. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
  1937. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
  1938. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x07, 0x05, HDA_INPUT),
  1939. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x07, 0x05, HDA_INPUT),
  1940. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  1941. HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
  1942. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  1943. HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
  1944. HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
  1945. HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
  1946. {
  1947. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1948. .name = "Capture Source",
  1949. .info = alc_mux_enum_info,
  1950. .get = alc_mux_enum_get,
  1951. .put = alc_mux_enum_put,
  1952. },
  1953. { } /* end */
  1954. };
  1955. static snd_kcontrol_new_t alc260_hp_mixer[] = {
  1956. HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  1957. HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
  1958. HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
  1959. HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
  1960. HDA_CODEC_VOLUME("Line Playback Volume", 0x07, 0x02, HDA_INPUT),
  1961. HDA_CODEC_MUTE("Line Playback Switch", 0x07, 0x02, HDA_INPUT),
  1962. HDA_CODEC_VOLUME("Mic Playback Volume", 0x07, 0x0, HDA_INPUT),
  1963. HDA_CODEC_MUTE("Mic Playback Switch", 0x07, 0x0, HDA_INPUT),
  1964. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x07, 0x01, HDA_INPUT),
  1965. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x07, 0x01, HDA_INPUT),
  1966. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  1967. HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
  1968. HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
  1969. HDA_BIND_MUTE_MONO("Mono Playback Switch", 0x0a, 1, 2, HDA_INPUT),
  1970. HDA_CODEC_VOLUME("Capture Volume", 0x05, 0x0, HDA_INPUT),
  1971. HDA_CODEC_MUTE("Capture Switch", 0x05, 0x0, HDA_INPUT),
  1972. {
  1973. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1974. .name = "Capture Source",
  1975. .info = alc_mux_enum_info,
  1976. .get = alc_mux_enum_get,
  1977. .put = alc_mux_enum_put,
  1978. },
  1979. { } /* end */
  1980. };
  1981. static snd_kcontrol_new_t alc260_fujitsu_mixer[] = {
  1982. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
  1983. HDA_BIND_MUTE("Headphone Playback Switch", 0x08, 2, HDA_INPUT),
  1984. ALC_PINCTL_SWITCH("Headphone Amp Switch", 0x14, PIN_HP_AMP),
  1985. HDA_CODEC_VOLUME("CD Playback Volume", 0x07, 0x04, HDA_INPUT),
  1986. HDA_CODEC_MUTE("CD Playback Switch", 0x07, 0x04, HDA_INPUT),
  1987. HDA_CODEC_VOLUME("Mic/Line Playback Volume", 0x07, 0x0, HDA_INPUT),
  1988. HDA_CODEC_MUTE("Mic/Line Playback Switch", 0x07, 0x0, HDA_INPUT),
  1989. HDA_CODEC_VOLUME("Beep Playback Volume", 0x07, 0x05, HDA_INPUT),
  1990. HDA_CODEC_MUTE("Beep Playback Switch", 0x07, 0x05, HDA_INPUT),
  1991. HDA_CODEC_VOLUME("Internal Speaker Playback Volume", 0x09, 0x0, HDA_OUTPUT),
  1992. HDA_BIND_MUTE("Internal Speaker Playback Switch", 0x09, 2, HDA_INPUT),
  1993. HDA_CODEC_VOLUME("Capture Volume", 0x04, 0x0, HDA_INPUT),
  1994. HDA_CODEC_MUTE("Capture Switch", 0x04, 0x0, HDA_INPUT),
  1995. {
  1996. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1997. .name = "Capture Source",
  1998. .info = alc_mux_enum_info,
  1999. .get = alc_mux_enum_get,
  2000. .put = alc_mux_enum_put,
  2001. },
  2002. { } /* end */
  2003. };
  2004. static struct hda_verb alc260_init_verbs[] = {
  2005. /* Line In pin widget for input */
  2006. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2007. /* CD pin widget for input */
  2008. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2009. /* Mic1 (rear panel) pin widget for input and vref at 80% */
  2010. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2011. /* Mic2 (front panel) pin widget for input and vref at 80% */
  2012. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2013. /* LINE-2 is used for line-out in rear */
  2014. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2015. /* select line-out */
  2016. {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
  2017. /* LINE-OUT pin */
  2018. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2019. /* enable HP */
  2020. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2021. /* enable Mono */
  2022. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2023. /* mute capture amp left and right */
  2024. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2025. /* set connection select to line in (default select for this ADC) */
  2026. {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
  2027. /* mute capture amp left and right */
  2028. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2029. /* set connection select to line in (default select for this ADC) */
  2030. {0x05, AC_VERB_SET_CONNECT_SEL, 0x02},
  2031. /* set vol=0 Line-Out mixer amp left and right */
  2032. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2033. /* unmute pin widget amp left and right (no gain on this amp) */
  2034. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2035. /* set vol=0 HP mixer amp left and right */
  2036. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2037. /* unmute pin widget amp left and right (no gain on this amp) */
  2038. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2039. /* set vol=0 Mono mixer amp left and right */
  2040. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2041. /* unmute pin widget amp left and right (no gain on this amp) */
  2042. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2043. /* unmute LINE-2 out pin */
  2044. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2045. /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 & Line In 2 = 0x03 */
  2046. /* mute CD */
  2047. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
  2048. /* mute Line In */
  2049. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
  2050. /* mute Mic */
  2051. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2052. /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
  2053. /* mute Front out path */
  2054. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2055. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2056. /* mute Headphone out path */
  2057. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2058. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2059. /* mute Mono out path */
  2060. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2061. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2062. { }
  2063. };
  2064. /* Initialisation sequence for ALC260 as configured in Fujitsu S702x
  2065. * laptops.
  2066. */
  2067. static struct hda_verb alc260_fujitsu_init_verbs[] = {
  2068. /* Disable all GPIOs */
  2069. {0x01, AC_VERB_SET_GPIO_MASK, 0},
  2070. /* Internal speaker is connected to headphone pin */
  2071. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2072. /* Headphone/Line-out jack connects to Line1 pin; make it an output */
  2073. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2074. /* Mic/Line-in jack is connected to mic1 pin, so make it an input */
  2075. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2076. /* Ensure all other unused pins are disabled and muted.
  2077. * Note: trying to set widget 0x15 to anything blocks all audio
  2078. * output for some reason, so just leave that at the default.
  2079. */
  2080. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2081. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2082. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2083. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2084. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2085. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2086. /* Disable digital (SPDIF) pins */
  2087. {0x03, AC_VERB_SET_DIGI_CONVERT_1, 0},
  2088. {0x06, AC_VERB_SET_DIGI_CONVERT_1, 0},
  2089. /* Start with mixer outputs muted */
  2090. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2091. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2092. {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2093. /* Unmute HP pin widget amp left and right (no equiv mixer ctrl) */
  2094. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2095. /* Unmute Line1 pin widget amp left and right (no equiv mixer ctrl) */
  2096. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2097. /* Unmute pin widget used for Line-in (no equiv mixer ctrl) */
  2098. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2099. /* Mute capture amp left and right */
  2100. {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2101. /* Set ADC connection select to line in (on mic1 pin) */
  2102. {0x04, AC_VERB_SET_CONNECT_SEL, 0x00},
  2103. /* Mute all inputs to mixer widget (even unconnected ones) */
  2104. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  2105. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  2106. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  2107. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  2108. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  2109. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  2110. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  2111. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  2112. };
  2113. static struct hda_pcm_stream alc260_pcm_analog_playback = {
  2114. .substreams = 1,
  2115. .channels_min = 2,
  2116. .channels_max = 2,
  2117. };
  2118. static struct hda_pcm_stream alc260_pcm_analog_capture = {
  2119. .substreams = 1,
  2120. .channels_min = 2,
  2121. .channels_max = 2,
  2122. };
  2123. static struct hda_board_config alc260_cfg_tbl[] = {
  2124. { .modelname = "hp", .config = ALC260_HP },
  2125. { .pci_subvendor = 0x103c, .config = ALC260_HP },
  2126. { .modelname = "fujitsu", .config = ALC260_FUJITSU_S702x },
  2127. { .pci_subvendor = 0x10cf, .pci_subdevice = 0x1326, .config = ALC260_FUJITSU_S702x },
  2128. {}
  2129. };
  2130. static int patch_alc260(struct hda_codec *codec)
  2131. {
  2132. struct alc_spec *spec;
  2133. int board_config;
  2134. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2135. if (spec == NULL)
  2136. return -ENOMEM;
  2137. codec->spec = spec;
  2138. board_config = snd_hda_check_board_config(codec, alc260_cfg_tbl);
  2139. if (board_config < 0 || board_config >= ALC260_MODEL_LAST) {
  2140. snd_printd(KERN_INFO "hda_codec: Unknown model for ALC260\n");
  2141. board_config = ALC260_BASIC;
  2142. }
  2143. switch (board_config) {
  2144. case ALC260_HP:
  2145. spec->mixers[spec->num_mixers] = alc260_hp_mixer;
  2146. spec->num_mixers++;
  2147. break;
  2148. case ALC260_FUJITSU_S702x:
  2149. spec->mixers[spec->num_mixers] = alc260_fujitsu_mixer;
  2150. spec->num_mixers++;
  2151. break;
  2152. default:
  2153. spec->mixers[spec->num_mixers] = alc260_base_mixer;
  2154. spec->num_mixers++;
  2155. break;
  2156. }
  2157. if (board_config != ALC260_FUJITSU_S702x) {
  2158. spec->init_verbs[0] = alc260_init_verbs;
  2159. spec->num_init_verbs = 1;
  2160. } else {
  2161. spec->init_verbs[0] = alc260_fujitsu_init_verbs;
  2162. spec->num_init_verbs = 1;
  2163. }
  2164. spec->channel_mode = alc260_modes;
  2165. spec->num_channel_mode = ARRAY_SIZE(alc260_modes);
  2166. spec->stream_name_analog = "ALC260 Analog";
  2167. spec->stream_analog_playback = &alc260_pcm_analog_playback;
  2168. spec->stream_analog_capture = &alc260_pcm_analog_capture;
  2169. spec->multiout.max_channels = spec->channel_mode[0].channels;
  2170. spec->multiout.num_dacs = ARRAY_SIZE(alc260_dac_nids);
  2171. spec->multiout.dac_nids = alc260_dac_nids;
  2172. if (board_config != ALC260_FUJITSU_S702x) {
  2173. spec->input_mux = &alc260_capture_source;
  2174. } else {
  2175. spec->input_mux = &alc260_fujitsu_capture_source;
  2176. }
  2177. switch (board_config) {
  2178. case ALC260_HP:
  2179. spec->num_adc_nids = ARRAY_SIZE(alc260_hp_adc_nids);
  2180. spec->adc_nids = alc260_hp_adc_nids;
  2181. break;
  2182. default:
  2183. spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids);
  2184. spec->adc_nids = alc260_adc_nids;
  2185. break;
  2186. }
  2187. codec->patch_ops = alc_patch_ops;
  2188. return 0;
  2189. }
  2190. /*
  2191. * ALC882 support
  2192. *
  2193. * ALC882 is almost identical with ALC880 but has cleaner and more flexible
  2194. * configuration. Each pin widget can choose any input DACs and a mixer.
  2195. * Each ADC is connected from a mixer of all inputs. This makes possible
  2196. * 6-channel independent captures.
  2197. *
  2198. * In addition, an independent DAC for the multi-playback (not used in this
  2199. * driver yet).
  2200. */
  2201. static struct hda_channel_mode alc882_ch_modes[1] = {
  2202. { 8, NULL }
  2203. };
  2204. static hda_nid_t alc882_dac_nids[4] = {
  2205. /* front, rear, clfe, rear_surr */
  2206. 0x02, 0x03, 0x04, 0x05
  2207. };
  2208. static hda_nid_t alc882_adc_nids[3] = {
  2209. /* ADC0-2 */
  2210. 0x07, 0x08, 0x09,
  2211. };
  2212. /* input MUX */
  2213. /* FIXME: should be a matrix-type input source selection */
  2214. static struct hda_input_mux alc882_capture_source = {
  2215. .num_items = 4,
  2216. .items = {
  2217. { "Mic", 0x0 },
  2218. { "Front Mic", 0x1 },
  2219. { "Line", 0x2 },
  2220. { "CD", 0x4 },
  2221. },
  2222. };
  2223. #define alc882_mux_enum_info alc_mux_enum_info
  2224. #define alc882_mux_enum_get alc_mux_enum_get
  2225. static int alc882_mux_enum_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
  2226. {
  2227. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2228. struct alc_spec *spec = codec->spec;
  2229. const struct hda_input_mux *imux = spec->input_mux;
  2230. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  2231. static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 };
  2232. hda_nid_t nid = capture_mixers[adc_idx];
  2233. unsigned int *cur_val = &spec->cur_mux[adc_idx];
  2234. unsigned int i, idx;
  2235. idx = ucontrol->value.enumerated.item[0];
  2236. if (idx >= imux->num_items)
  2237. idx = imux->num_items - 1;
  2238. if (*cur_val == idx && ! codec->in_resume)
  2239. return 0;
  2240. for (i = 0; i < imux->num_items; i++) {
  2241. unsigned int v = (i == idx) ? 0x7000 : 0x7080;
  2242. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2243. v | (imux->items[i].index << 8));
  2244. }
  2245. *cur_val = idx;
  2246. return 1;
  2247. }
  2248. /* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
  2249. * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
  2250. */
  2251. static snd_kcontrol_new_t alc882_base_mixer[] = {
  2252. HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
  2253. HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
  2254. HDA_CODEC_VOLUME("Surround Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
  2255. HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
  2256. HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0e, 1, 0x0, HDA_OUTPUT),
  2257. HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0e, 2, 0x0, HDA_OUTPUT),
  2258. HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
  2259. HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
  2260. HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
  2261. HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
  2262. HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
  2263. HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
  2264. HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
  2265. HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
  2266. HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
  2267. HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
  2268. HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
  2269. HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
  2270. HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
  2271. HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
  2272. HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
  2273. HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
  2274. HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
  2275. HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x08, 0x0, HDA_INPUT),
  2276. HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x08, 0x0, HDA_INPUT),
  2277. HDA_CODEC_VOLUME_IDX("Capture Volume", 2, 0x09, 0x0, HDA_INPUT),
  2278. HDA_CODEC_MUTE_IDX("Capture Switch", 2, 0x09, 0x0, HDA_INPUT),
  2279. {
  2280. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2281. /* .name = "Capture Source", */
  2282. .name = "Input Source",
  2283. .count = 3,
  2284. .info = alc882_mux_enum_info,
  2285. .get = alc882_mux_enum_get,
  2286. .put = alc882_mux_enum_put,
  2287. },
  2288. { } /* end */
  2289. };
  2290. static struct hda_verb alc882_init_verbs[] = {
  2291. /* Front mixer: unmute input/output amp left and right (volume = 0) */
  2292. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2293. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2294. {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2295. /* Rear mixer */
  2296. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2297. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2298. {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2299. /* CLFE mixer */
  2300. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2301. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2302. {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2303. /* Side mixer */
  2304. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
  2305. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2306. {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2307. /* Front Pin: output 0 (0x0c) */
  2308. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2309. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2310. {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
  2311. /* Rear Pin: output 1 (0x0d) */
  2312. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2313. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2314. {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
  2315. /* CLFE Pin: output 2 (0x0e) */
  2316. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2317. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2318. {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
  2319. /* Side Pin: output 3 (0x0f) */
  2320. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2321. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2322. {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
  2323. /* Mic (rear) pin: input vref at 80% */
  2324. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2325. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2326. /* Front Mic pin: input vref at 80% */
  2327. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2328. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2329. /* Line In pin: input */
  2330. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2331. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2332. /* Line-2 In: Headphone output (output 0 - 0x0c) */
  2333. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2334. {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2335. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  2336. /* CD pin widget for input */
  2337. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2338. /* FIXME: use matrix-type input source selection */
  2339. /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
  2340. /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
  2341. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2342. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2343. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2344. {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2345. /* Input mixer2 */
  2346. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2347. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2348. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2349. {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2350. /* Input mixer3 */
  2351. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
  2352. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2353. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2354. {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2355. /* ADC1: mute amp left and right */
  2356. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2357. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  2358. /* ADC2: mute amp left and right */
  2359. {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2360. {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
  2361. /* ADC3: mute amp left and right */
  2362. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2363. {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
  2364. { }
  2365. };
  2366. static int patch_alc882(struct hda_codec *codec)
  2367. {
  2368. struct alc_spec *spec;
  2369. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2370. if (spec == NULL)
  2371. return -ENOMEM;
  2372. codec->spec = spec;
  2373. spec->mixers[spec->num_mixers] = alc882_base_mixer;
  2374. spec->num_mixers++;
  2375. spec->multiout.dig_out_nid = ALC880_DIGOUT_NID;
  2376. spec->dig_in_nid = ALC880_DIGIN_NID;
  2377. spec->init_verbs[0] = alc882_init_verbs;
  2378. spec->num_init_verbs = 1;
  2379. spec->channel_mode = alc882_ch_modes;
  2380. spec->num_channel_mode = ARRAY_SIZE(alc882_ch_modes);
  2381. spec->stream_name_analog = "ALC882 Analog";
  2382. spec->stream_analog_playback = &alc880_pcm_analog_playback;
  2383. spec->stream_analog_capture = &alc880_pcm_analog_capture;
  2384. spec->stream_name_digital = "ALC882 Digital";
  2385. spec->stream_digital_playback = &alc880_pcm_digital_playback;
  2386. spec->stream_digital_capture = &alc880_pcm_digital_capture;
  2387. spec->multiout.max_channels = spec->channel_mode[0].channels;
  2388. spec->multiout.num_dacs = ARRAY_SIZE(alc882_dac_nids);
  2389. spec->multiout.dac_nids = alc882_dac_nids;
  2390. spec->input_mux = &alc882_capture_source;
  2391. spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
  2392. spec->adc_nids = alc882_adc_nids;
  2393. codec->patch_ops = alc_patch_ops;
  2394. return 0;
  2395. }
  2396. /*
  2397. * patch entries
  2398. */
  2399. struct hda_codec_preset snd_hda_preset_realtek[] = {
  2400. { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
  2401. { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
  2402. { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
  2403. {} /* terminator */
  2404. };