patch_realtek.c 92 KB

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