patch_realtek.c 88 KB

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