patch_realtek.c 92 KB

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