patch_realtek.c 89 KB

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