patch_realtek.c 94 KB

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