patch_realtek.c 88 KB

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