patch_conexant.c 107 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598
  1. /*
  2. * HD audio interface patch for Conexant HDA audio codec
  3. *
  4. * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
  5. * Takashi Iwai <tiwai@suse.de>
  6. * Tobin Davis <tdavis@dsl-only.net>
  7. *
  8. * This driver is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This driver is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <linux/module.h>
  27. #include <sound/core.h>
  28. #include <sound/jack.h>
  29. #include "hda_codec.h"
  30. #include "hda_local.h"
  31. #include "hda_auto_parser.h"
  32. #include "hda_beep.h"
  33. #include "hda_jack.h"
  34. #include "hda_generic.h"
  35. #undef ENABLE_CXT_STATIC_QUIRKS
  36. #define CXT_PIN_DIR_IN 0x00
  37. #define CXT_PIN_DIR_OUT 0x01
  38. #define CXT_PIN_DIR_INOUT 0x02
  39. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  40. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  41. #define CONEXANT_HP_EVENT 0x37
  42. #define CONEXANT_MIC_EVENT 0x38
  43. #define CONEXANT_LINE_EVENT 0x39
  44. /* Conexant 5051 specific */
  45. #define CXT5051_SPDIF_OUT 0x12
  46. #define CXT5051_PORTB_EVENT 0x38
  47. #define CXT5051_PORTC_EVENT 0x39
  48. #define AUTO_MIC_PORTB (1 << 1)
  49. #define AUTO_MIC_PORTC (1 << 2)
  50. struct conexant_spec {
  51. struct hda_gen_spec gen;
  52. unsigned int beep_amp;
  53. /* extra EAPD pins */
  54. unsigned int num_eapds;
  55. hda_nid_t eapds[4];
  56. bool dynamic_eapd;
  57. unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
  58. /* OPLC XO specific */
  59. bool recording;
  60. bool dc_enable;
  61. unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
  62. struct nid_path *dc_mode_path;
  63. #ifdef ENABLE_CXT_STATIC_QUIRKS
  64. const struct snd_kcontrol_new *mixers[5];
  65. int num_mixers;
  66. hda_nid_t vmaster_nid;
  67. const struct hda_verb *init_verbs[5]; /* initialization verbs
  68. * don't forget NULL
  69. * termination!
  70. */
  71. unsigned int num_init_verbs;
  72. /* playback */
  73. struct hda_multi_out multiout; /* playback set-up
  74. * max_channels, dacs must be set
  75. * dig_out_nid and hp_nid are optional
  76. */
  77. unsigned int cur_eapd;
  78. unsigned int hp_present;
  79. unsigned int line_present;
  80. unsigned int auto_mic;
  81. /* capture */
  82. unsigned int num_adc_nids;
  83. const hda_nid_t *adc_nids;
  84. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  85. unsigned int cur_adc_idx;
  86. hda_nid_t cur_adc;
  87. unsigned int cur_adc_stream_tag;
  88. unsigned int cur_adc_format;
  89. const struct hda_pcm_stream *capture_stream;
  90. /* capture source */
  91. const struct hda_input_mux *input_mux;
  92. const hda_nid_t *capsrc_nids;
  93. unsigned int cur_mux[3];
  94. /* channel model */
  95. const struct hda_channel_mode *channel_mode;
  96. int num_channel_mode;
  97. /* PCM information */
  98. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  99. unsigned int spdif_route;
  100. unsigned int port_d_mode;
  101. unsigned int dell_automute:1;
  102. unsigned int dell_vostro:1;
  103. unsigned int ideapad:1;
  104. unsigned int thinkpad:1;
  105. unsigned int hp_laptop:1;
  106. unsigned int asus:1;
  107. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  108. #endif /* ENABLE_CXT_STATIC_QUIRKS */
  109. };
  110. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  111. static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
  112. int idx, int dir)
  113. {
  114. spec->gen.beep_nid = nid;
  115. spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
  116. }
  117. /* additional beep mixers; the actual parameters are overwritten at build */
  118. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  119. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  120. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  121. { } /* end */
  122. };
  123. /* create beep controls if needed */
  124. static int add_beep_ctls(struct hda_codec *codec)
  125. {
  126. struct conexant_spec *spec = codec->spec;
  127. int err;
  128. if (spec->beep_amp) {
  129. const struct snd_kcontrol_new *knew;
  130. for (knew = cxt_beep_mixer; knew->name; knew++) {
  131. struct snd_kcontrol *kctl;
  132. kctl = snd_ctl_new1(knew, codec);
  133. if (!kctl)
  134. return -ENOMEM;
  135. kctl->private_value = spec->beep_amp;
  136. err = snd_hda_ctl_add(codec, 0, kctl);
  137. if (err < 0)
  138. return err;
  139. }
  140. }
  141. return 0;
  142. }
  143. #else
  144. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  145. #define add_beep_ctls(codec) 0
  146. #endif
  147. #ifdef ENABLE_CXT_STATIC_QUIRKS
  148. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  149. struct hda_codec *codec,
  150. struct snd_pcm_substream *substream)
  151. {
  152. struct conexant_spec *spec = codec->spec;
  153. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  154. hinfo);
  155. }
  156. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  157. struct hda_codec *codec,
  158. unsigned int stream_tag,
  159. unsigned int format,
  160. struct snd_pcm_substream *substream)
  161. {
  162. struct conexant_spec *spec = codec->spec;
  163. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  164. stream_tag,
  165. format, substream);
  166. }
  167. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  168. struct hda_codec *codec,
  169. struct snd_pcm_substream *substream)
  170. {
  171. struct conexant_spec *spec = codec->spec;
  172. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  173. }
  174. /*
  175. * Digital out
  176. */
  177. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  178. struct hda_codec *codec,
  179. struct snd_pcm_substream *substream)
  180. {
  181. struct conexant_spec *spec = codec->spec;
  182. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  183. }
  184. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  185. struct hda_codec *codec,
  186. struct snd_pcm_substream *substream)
  187. {
  188. struct conexant_spec *spec = codec->spec;
  189. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  190. }
  191. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  192. struct hda_codec *codec,
  193. unsigned int stream_tag,
  194. unsigned int format,
  195. struct snd_pcm_substream *substream)
  196. {
  197. struct conexant_spec *spec = codec->spec;
  198. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  199. stream_tag,
  200. format, substream);
  201. }
  202. /*
  203. * Analog capture
  204. */
  205. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  206. struct hda_codec *codec,
  207. unsigned int stream_tag,
  208. unsigned int format,
  209. struct snd_pcm_substream *substream)
  210. {
  211. struct conexant_spec *spec = codec->spec;
  212. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  213. stream_tag, 0, format);
  214. return 0;
  215. }
  216. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  217. struct hda_codec *codec,
  218. struct snd_pcm_substream *substream)
  219. {
  220. struct conexant_spec *spec = codec->spec;
  221. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  222. return 0;
  223. }
  224. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  225. .substreams = 1,
  226. .channels_min = 2,
  227. .channels_max = 2,
  228. .nid = 0, /* fill later */
  229. .ops = {
  230. .open = conexant_playback_pcm_open,
  231. .prepare = conexant_playback_pcm_prepare,
  232. .cleanup = conexant_playback_pcm_cleanup
  233. },
  234. };
  235. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  236. .substreams = 1,
  237. .channels_min = 2,
  238. .channels_max = 2,
  239. .nid = 0, /* fill later */
  240. .ops = {
  241. .prepare = conexant_capture_pcm_prepare,
  242. .cleanup = conexant_capture_pcm_cleanup
  243. },
  244. };
  245. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  246. .substreams = 1,
  247. .channels_min = 2,
  248. .channels_max = 2,
  249. .nid = 0, /* fill later */
  250. .ops = {
  251. .open = conexant_dig_playback_pcm_open,
  252. .close = conexant_dig_playback_pcm_close,
  253. .prepare = conexant_dig_playback_pcm_prepare
  254. },
  255. };
  256. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  257. .substreams = 1,
  258. .channels_min = 2,
  259. .channels_max = 2,
  260. /* NID is set in alc_build_pcms */
  261. };
  262. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  263. struct hda_codec *codec,
  264. unsigned int stream_tag,
  265. unsigned int format,
  266. struct snd_pcm_substream *substream)
  267. {
  268. struct conexant_spec *spec = codec->spec;
  269. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  270. spec->cur_adc_stream_tag = stream_tag;
  271. spec->cur_adc_format = format;
  272. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  273. return 0;
  274. }
  275. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  276. struct hda_codec *codec,
  277. struct snd_pcm_substream *substream)
  278. {
  279. struct conexant_spec *spec = codec->spec;
  280. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  281. spec->cur_adc = 0;
  282. return 0;
  283. }
  284. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  285. .substreams = 1,
  286. .channels_min = 2,
  287. .channels_max = 2,
  288. .nid = 0, /* fill later */
  289. .ops = {
  290. .prepare = cx5051_capture_pcm_prepare,
  291. .cleanup = cx5051_capture_pcm_cleanup
  292. },
  293. };
  294. static int conexant_build_pcms(struct hda_codec *codec)
  295. {
  296. struct conexant_spec *spec = codec->spec;
  297. struct hda_pcm *info = spec->pcm_rec;
  298. codec->num_pcms = 1;
  299. codec->pcm_info = info;
  300. info->name = "CONEXANT Analog";
  301. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  302. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  303. spec->multiout.max_channels;
  304. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  305. spec->multiout.dac_nids[0];
  306. if (spec->capture_stream)
  307. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  308. else {
  309. if (codec->vendor_id == 0x14f15051)
  310. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  311. cx5051_pcm_analog_capture;
  312. else {
  313. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  314. conexant_pcm_analog_capture;
  315. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  316. spec->num_adc_nids;
  317. }
  318. }
  319. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  320. if (spec->multiout.dig_out_nid) {
  321. info++;
  322. codec->num_pcms++;
  323. info->name = "Conexant Digital";
  324. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  325. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  326. conexant_pcm_digital_playback;
  327. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  328. spec->multiout.dig_out_nid;
  329. if (spec->dig_in_nid) {
  330. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  331. conexant_pcm_digital_capture;
  332. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  333. spec->dig_in_nid;
  334. }
  335. }
  336. return 0;
  337. }
  338. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  339. struct snd_ctl_elem_info *uinfo)
  340. {
  341. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  342. struct conexant_spec *spec = codec->spec;
  343. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  344. }
  345. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  346. struct snd_ctl_elem_value *ucontrol)
  347. {
  348. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  349. struct conexant_spec *spec = codec->spec;
  350. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  351. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  352. return 0;
  353. }
  354. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  355. struct snd_ctl_elem_value *ucontrol)
  356. {
  357. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  358. struct conexant_spec *spec = codec->spec;
  359. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  360. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  361. spec->capsrc_nids[adc_idx],
  362. &spec->cur_mux[adc_idx]);
  363. }
  364. static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
  365. unsigned int power_state)
  366. {
  367. if (power_state == AC_PWRST_D3)
  368. msleep(100);
  369. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
  370. power_state);
  371. /* partial workaround for "azx_get_response timeout" */
  372. if (power_state == AC_PWRST_D0)
  373. msleep(10);
  374. snd_hda_codec_set_power_to_all(codec, fg, power_state);
  375. }
  376. static int conexant_init(struct hda_codec *codec)
  377. {
  378. struct conexant_spec *spec = codec->spec;
  379. int i;
  380. for (i = 0; i < spec->num_init_verbs; i++)
  381. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  382. return 0;
  383. }
  384. static void conexant_free(struct hda_codec *codec)
  385. {
  386. struct conexant_spec *spec = codec->spec;
  387. snd_hda_detach_beep_device(codec);
  388. kfree(spec);
  389. }
  390. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  391. {
  392. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  393. .name = "Capture Source",
  394. .info = conexant_mux_enum_info,
  395. .get = conexant_mux_enum_get,
  396. .put = conexant_mux_enum_put
  397. },
  398. {}
  399. };
  400. static const char * const slave_pfxs[] = {
  401. "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
  402. NULL
  403. };
  404. static int conexant_build_controls(struct hda_codec *codec)
  405. {
  406. struct conexant_spec *spec = codec->spec;
  407. unsigned int i;
  408. int err;
  409. for (i = 0; i < spec->num_mixers; i++) {
  410. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  411. if (err < 0)
  412. return err;
  413. }
  414. if (spec->multiout.dig_out_nid) {
  415. err = snd_hda_create_spdif_out_ctls(codec,
  416. spec->multiout.dig_out_nid,
  417. spec->multiout.dig_out_nid);
  418. if (err < 0)
  419. return err;
  420. err = snd_hda_create_spdif_share_sw(codec,
  421. &spec->multiout);
  422. if (err < 0)
  423. return err;
  424. spec->multiout.share_spdif = 1;
  425. }
  426. if (spec->dig_in_nid) {
  427. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  428. if (err < 0)
  429. return err;
  430. }
  431. /* if we have no master control, let's create it */
  432. if (spec->vmaster_nid &&
  433. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  434. unsigned int vmaster_tlv[4];
  435. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  436. HDA_OUTPUT, vmaster_tlv);
  437. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  438. vmaster_tlv, slave_pfxs,
  439. "Playback Volume");
  440. if (err < 0)
  441. return err;
  442. }
  443. if (spec->vmaster_nid &&
  444. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  445. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  446. NULL, slave_pfxs,
  447. "Playback Switch");
  448. if (err < 0)
  449. return err;
  450. }
  451. if (spec->input_mux) {
  452. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  453. if (err < 0)
  454. return err;
  455. }
  456. err = add_beep_ctls(codec);
  457. if (err < 0)
  458. return err;
  459. return 0;
  460. }
  461. static const struct hda_codec_ops conexant_patch_ops = {
  462. .build_controls = conexant_build_controls,
  463. .build_pcms = conexant_build_pcms,
  464. .init = conexant_init,
  465. .free = conexant_free,
  466. .set_power_state = conexant_set_power,
  467. };
  468. static int patch_conexant_auto(struct hda_codec *codec);
  469. /*
  470. * EAPD control
  471. * the private value = nid | (invert << 8)
  472. */
  473. #define cxt_eapd_info snd_ctl_boolean_mono_info
  474. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  475. struct snd_ctl_elem_value *ucontrol)
  476. {
  477. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  478. struct conexant_spec *spec = codec->spec;
  479. int invert = (kcontrol->private_value >> 8) & 1;
  480. if (invert)
  481. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  482. else
  483. ucontrol->value.integer.value[0] = spec->cur_eapd;
  484. return 0;
  485. }
  486. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  487. struct snd_ctl_elem_value *ucontrol)
  488. {
  489. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  490. struct conexant_spec *spec = codec->spec;
  491. int invert = (kcontrol->private_value >> 8) & 1;
  492. hda_nid_t nid = kcontrol->private_value & 0xff;
  493. unsigned int eapd;
  494. eapd = !!ucontrol->value.integer.value[0];
  495. if (invert)
  496. eapd = !eapd;
  497. if (eapd == spec->cur_eapd)
  498. return 0;
  499. spec->cur_eapd = eapd;
  500. snd_hda_codec_write_cache(codec, nid,
  501. 0, AC_VERB_SET_EAPD_BTLENABLE,
  502. eapd ? 0x02 : 0x00);
  503. return 1;
  504. }
  505. /* controls for test mode */
  506. #ifdef CONFIG_SND_DEBUG
  507. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  508. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  509. .info = cxt_eapd_info, \
  510. .get = cxt_eapd_get, \
  511. .put = cxt_eapd_put, \
  512. .private_value = nid | (mask<<16) }
  513. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  514. struct snd_ctl_elem_info *uinfo)
  515. {
  516. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  517. struct conexant_spec *spec = codec->spec;
  518. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  519. spec->num_channel_mode);
  520. }
  521. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  522. struct snd_ctl_elem_value *ucontrol)
  523. {
  524. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  525. struct conexant_spec *spec = codec->spec;
  526. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  527. spec->num_channel_mode,
  528. spec->multiout.max_channels);
  529. }
  530. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  531. struct snd_ctl_elem_value *ucontrol)
  532. {
  533. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  534. struct conexant_spec *spec = codec->spec;
  535. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  536. spec->num_channel_mode,
  537. &spec->multiout.max_channels);
  538. return err;
  539. }
  540. #define CXT_PIN_MODE(xname, nid, dir) \
  541. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  542. .info = conexant_ch_mode_info, \
  543. .get = conexant_ch_mode_get, \
  544. .put = conexant_ch_mode_put, \
  545. .private_value = nid | (dir<<16) }
  546. #endif /* CONFIG_SND_DEBUG */
  547. /* Conexant 5045 specific */
  548. static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  549. static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  550. static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  551. #define CXT5045_SPDIF_OUT 0x18
  552. static const struct hda_channel_mode cxt5045_modes[1] = {
  553. { 2, NULL },
  554. };
  555. static const struct hda_input_mux cxt5045_capture_source = {
  556. .num_items = 2,
  557. .items = {
  558. { "Internal Mic", 0x1 },
  559. { "Mic", 0x2 },
  560. }
  561. };
  562. static const struct hda_input_mux cxt5045_capture_source_benq = {
  563. .num_items = 4,
  564. .items = {
  565. { "Internal Mic", 0x1 },
  566. { "Mic", 0x2 },
  567. { "Line", 0x3 },
  568. { "Mixer", 0x0 },
  569. }
  570. };
  571. /* turn on/off EAPD (+ mute HP) as a master switch */
  572. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  573. struct snd_ctl_elem_value *ucontrol)
  574. {
  575. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  576. struct conexant_spec *spec = codec->spec;
  577. unsigned int bits;
  578. if (!cxt_eapd_put(kcontrol, ucontrol))
  579. return 0;
  580. /* toggle internal speakers mute depending of presence of
  581. * the headphone jack
  582. */
  583. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  584. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  585. HDA_AMP_MUTE, bits);
  586. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  587. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  588. HDA_AMP_MUTE, bits);
  589. return 1;
  590. }
  591. /* bind volumes of both NID 0x10 and 0x11 */
  592. static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  593. .ops = &snd_hda_bind_vol,
  594. .values = {
  595. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  596. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  597. 0
  598. },
  599. };
  600. /* toggle input of built-in and mic jack appropriately */
  601. static void cxt5045_hp_automic(struct hda_codec *codec)
  602. {
  603. static const struct hda_verb mic_jack_on[] = {
  604. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  605. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  606. {}
  607. };
  608. static const struct hda_verb mic_jack_off[] = {
  609. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  610. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  611. {}
  612. };
  613. unsigned int present;
  614. present = snd_hda_jack_detect(codec, 0x12);
  615. if (present)
  616. snd_hda_sequence_write(codec, mic_jack_on);
  617. else
  618. snd_hda_sequence_write(codec, mic_jack_off);
  619. }
  620. /* mute internal speaker if HP is plugged */
  621. static void cxt5045_hp_automute(struct hda_codec *codec)
  622. {
  623. struct conexant_spec *spec = codec->spec;
  624. unsigned int bits;
  625. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  626. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  627. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  628. HDA_AMP_MUTE, bits);
  629. }
  630. /* unsolicited event for HP jack sensing */
  631. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  632. unsigned int res)
  633. {
  634. res >>= 26;
  635. switch (res) {
  636. case CONEXANT_HP_EVENT:
  637. cxt5045_hp_automute(codec);
  638. break;
  639. case CONEXANT_MIC_EVENT:
  640. cxt5045_hp_automic(codec);
  641. break;
  642. }
  643. }
  644. static const struct snd_kcontrol_new cxt5045_mixers[] = {
  645. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
  646. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  647. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  648. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  649. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  650. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  651. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  652. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  653. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  654. {
  655. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  656. .name = "Master Playback Switch",
  657. .info = cxt_eapd_info,
  658. .get = cxt_eapd_get,
  659. .put = cxt5045_hp_master_sw_put,
  660. .private_value = 0x10,
  661. },
  662. {}
  663. };
  664. static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  665. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
  666. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
  667. {}
  668. };
  669. static const struct hda_verb cxt5045_init_verbs[] = {
  670. /* Line in, Mic */
  671. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  672. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  673. /* HP, Amp */
  674. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  675. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  676. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  677. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  678. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  679. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  680. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  681. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  682. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  683. /* Record selector: Internal mic */
  684. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  685. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  686. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  687. /* SPDIF route: PCM */
  688. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  689. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  690. /* EAPD */
  691. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  692. { } /* end */
  693. };
  694. static const struct hda_verb cxt5045_benq_init_verbs[] = {
  695. /* Internal Mic, Mic */
  696. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  697. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  698. /* Line In,HP, Amp */
  699. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  700. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  701. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  702. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  703. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  704. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  705. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  706. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  707. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  708. /* Record selector: Internal mic */
  709. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  710. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  711. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  712. /* SPDIF route: PCM */
  713. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  714. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  715. /* EAPD */
  716. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  717. { } /* end */
  718. };
  719. static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  720. /* pin sensing on HP jack */
  721. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  722. { } /* end */
  723. };
  724. static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  725. /* pin sensing on HP jack */
  726. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  727. { } /* end */
  728. };
  729. #ifdef CONFIG_SND_DEBUG
  730. /* Test configuration for debugging, modelled after the ALC260 test
  731. * configuration.
  732. */
  733. static const struct hda_input_mux cxt5045_test_capture_source = {
  734. .num_items = 5,
  735. .items = {
  736. { "MIXER", 0x0 },
  737. { "MIC1 pin", 0x1 },
  738. { "LINE1 pin", 0x2 },
  739. { "HP-OUT pin", 0x3 },
  740. { "CD pin", 0x4 },
  741. },
  742. };
  743. static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
  744. /* Output controls */
  745. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  746. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  747. HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  748. HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  749. HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  750. HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  751. /* Modes for retasking pin widgets */
  752. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  753. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  754. /* EAPD Switch Control */
  755. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  756. /* Loopback mixer controls */
  757. HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
  758. HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
  759. HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
  760. HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
  761. HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
  762. HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
  763. HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
  764. HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
  765. HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
  766. HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
  767. {
  768. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  769. .name = "Input Source",
  770. .info = conexant_mux_enum_info,
  771. .get = conexant_mux_enum_get,
  772. .put = conexant_mux_enum_put,
  773. },
  774. /* Audio input controls */
  775. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
  776. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  777. { } /* end */
  778. };
  779. static const struct hda_verb cxt5045_test_init_verbs[] = {
  780. /* Set connections */
  781. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  782. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  783. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  784. /* Enable retasking pins as output, initially without power amp */
  785. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  786. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  787. /* Disable digital (SPDIF) pins initially, but users can enable
  788. * them via a mixer switch. In the case of SPDIF-out, this initverb
  789. * payload also sets the generation to 0, output to be in "consumer"
  790. * PCM format, copyright asserted, no pre-emphasis and no validity
  791. * control.
  792. */
  793. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  794. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  795. /* Unmute retasking pin widget output buffers since the default
  796. * state appears to be output. As the pin mode is changed by the
  797. * user the pin mode control will take care of enabling the pin's
  798. * input/output buffers as needed.
  799. */
  800. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  801. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  802. /* Mute capture amp left and right */
  803. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  804. /* Set ADC connection select to match default mixer setting (mic1
  805. * pin)
  806. */
  807. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
  808. {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
  809. /* Mute all inputs to mixer widget (even unconnected ones) */
  810. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
  811. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  812. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  813. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  814. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  815. { }
  816. };
  817. #endif
  818. /* initialize jack-sensing, too */
  819. static int cxt5045_init(struct hda_codec *codec)
  820. {
  821. conexant_init(codec);
  822. cxt5045_hp_automute(codec);
  823. return 0;
  824. }
  825. enum {
  826. CXT5045_LAPTOP_HPSENSE,
  827. CXT5045_LAPTOP_MICSENSE,
  828. CXT5045_LAPTOP_HPMICSENSE,
  829. CXT5045_BENQ,
  830. #ifdef CONFIG_SND_DEBUG
  831. CXT5045_TEST,
  832. #endif
  833. CXT5045_AUTO,
  834. CXT5045_MODELS
  835. };
  836. static const char * const cxt5045_models[CXT5045_MODELS] = {
  837. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  838. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  839. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  840. [CXT5045_BENQ] = "benq",
  841. #ifdef CONFIG_SND_DEBUG
  842. [CXT5045_TEST] = "test",
  843. #endif
  844. [CXT5045_AUTO] = "auto",
  845. };
  846. static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  847. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  848. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  849. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  850. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  851. CXT5045_LAPTOP_HPMICSENSE),
  852. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  853. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  854. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  855. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  856. CXT5045_LAPTOP_HPMICSENSE),
  857. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  858. {}
  859. };
  860. static int patch_cxt5045(struct hda_codec *codec)
  861. {
  862. struct conexant_spec *spec;
  863. int board_config;
  864. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  865. cxt5045_models,
  866. cxt5045_cfg_tbl);
  867. if (board_config < 0)
  868. board_config = CXT5045_AUTO; /* model=auto as default */
  869. if (board_config == CXT5045_AUTO)
  870. return patch_conexant_auto(codec);
  871. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  872. if (!spec)
  873. return -ENOMEM;
  874. codec->spec = spec;
  875. codec->single_adc_amp = 1;
  876. spec->multiout.max_channels = 2;
  877. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  878. spec->multiout.dac_nids = cxt5045_dac_nids;
  879. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  880. spec->num_adc_nids = 1;
  881. spec->adc_nids = cxt5045_adc_nids;
  882. spec->capsrc_nids = cxt5045_capsrc_nids;
  883. spec->input_mux = &cxt5045_capture_source;
  884. spec->num_mixers = 1;
  885. spec->mixers[0] = cxt5045_mixers;
  886. spec->num_init_verbs = 1;
  887. spec->init_verbs[0] = cxt5045_init_verbs;
  888. spec->spdif_route = 0;
  889. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
  890. spec->channel_mode = cxt5045_modes;
  891. set_beep_amp(spec, 0x16, 0, 1);
  892. codec->patch_ops = conexant_patch_ops;
  893. switch (board_config) {
  894. case CXT5045_LAPTOP_HPSENSE:
  895. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  896. spec->input_mux = &cxt5045_capture_source;
  897. spec->num_init_verbs = 2;
  898. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  899. spec->mixers[0] = cxt5045_mixers;
  900. codec->patch_ops.init = cxt5045_init;
  901. break;
  902. case CXT5045_LAPTOP_MICSENSE:
  903. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  904. spec->input_mux = &cxt5045_capture_source;
  905. spec->num_init_verbs = 2;
  906. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  907. spec->mixers[0] = cxt5045_mixers;
  908. codec->patch_ops.init = cxt5045_init;
  909. break;
  910. default:
  911. case CXT5045_LAPTOP_HPMICSENSE:
  912. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  913. spec->input_mux = &cxt5045_capture_source;
  914. spec->num_init_verbs = 3;
  915. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  916. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  917. spec->mixers[0] = cxt5045_mixers;
  918. codec->patch_ops.init = cxt5045_init;
  919. break;
  920. case CXT5045_BENQ:
  921. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  922. spec->input_mux = &cxt5045_capture_source_benq;
  923. spec->num_init_verbs = 1;
  924. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  925. spec->mixers[0] = cxt5045_mixers;
  926. spec->mixers[1] = cxt5045_benq_mixers;
  927. spec->num_mixers = 2;
  928. codec->patch_ops.init = cxt5045_init;
  929. break;
  930. #ifdef CONFIG_SND_DEBUG
  931. case CXT5045_TEST:
  932. spec->input_mux = &cxt5045_test_capture_source;
  933. spec->mixers[0] = cxt5045_test_mixer;
  934. spec->init_verbs[0] = cxt5045_test_init_verbs;
  935. break;
  936. #endif
  937. }
  938. switch (codec->subsystem_id >> 16) {
  939. case 0x103c:
  940. case 0x1631:
  941. case 0x1734:
  942. case 0x17aa:
  943. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  944. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  945. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  946. */
  947. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  948. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  949. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  950. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  951. (1 << AC_AMPCAP_MUTE_SHIFT));
  952. break;
  953. }
  954. if (spec->beep_amp)
  955. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  956. return 0;
  957. }
  958. /* Conexant 5047 specific */
  959. #define CXT5047_SPDIF_OUT 0x11
  960. static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  961. static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  962. static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  963. static const struct hda_channel_mode cxt5047_modes[1] = {
  964. { 2, NULL },
  965. };
  966. static const struct hda_input_mux cxt5047_toshiba_capture_source = {
  967. .num_items = 2,
  968. .items = {
  969. { "ExtMic", 0x2 },
  970. { "Line-In", 0x1 },
  971. }
  972. };
  973. /* turn on/off EAPD (+ mute HP) as a master switch */
  974. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  975. struct snd_ctl_elem_value *ucontrol)
  976. {
  977. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  978. struct conexant_spec *spec = codec->spec;
  979. unsigned int bits;
  980. if (!cxt_eapd_put(kcontrol, ucontrol))
  981. return 0;
  982. /* toggle internal speakers mute depending of presence of
  983. * the headphone jack
  984. */
  985. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  986. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  987. * pin widgets unlike other codecs. In this case, we need to
  988. * set index 0x01 for the volume from the mixer amp 0x19.
  989. */
  990. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  991. HDA_AMP_MUTE, bits);
  992. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  993. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  994. HDA_AMP_MUTE, bits);
  995. return 1;
  996. }
  997. /* mute internal speaker if HP is plugged */
  998. static void cxt5047_hp_automute(struct hda_codec *codec)
  999. {
  1000. struct conexant_spec *spec = codec->spec;
  1001. unsigned int bits;
  1002. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1003. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1004. /* See the note in cxt5047_hp_master_sw_put */
  1005. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1006. HDA_AMP_MUTE, bits);
  1007. }
  1008. /* toggle input of built-in and mic jack appropriately */
  1009. static void cxt5047_hp_automic(struct hda_codec *codec)
  1010. {
  1011. static const struct hda_verb mic_jack_on[] = {
  1012. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1013. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1014. {}
  1015. };
  1016. static const struct hda_verb mic_jack_off[] = {
  1017. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1018. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1019. {}
  1020. };
  1021. unsigned int present;
  1022. present = snd_hda_jack_detect(codec, 0x15);
  1023. if (present)
  1024. snd_hda_sequence_write(codec, mic_jack_on);
  1025. else
  1026. snd_hda_sequence_write(codec, mic_jack_off);
  1027. }
  1028. /* unsolicited event for HP jack sensing */
  1029. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1030. unsigned int res)
  1031. {
  1032. switch (res >> 26) {
  1033. case CONEXANT_HP_EVENT:
  1034. cxt5047_hp_automute(codec);
  1035. break;
  1036. case CONEXANT_MIC_EVENT:
  1037. cxt5047_hp_automic(codec);
  1038. break;
  1039. }
  1040. }
  1041. static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1042. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1043. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1044. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1045. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1046. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1047. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1048. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1049. {
  1050. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1051. .name = "Master Playback Switch",
  1052. .info = cxt_eapd_info,
  1053. .get = cxt_eapd_get,
  1054. .put = cxt5047_hp_master_sw_put,
  1055. .private_value = 0x13,
  1056. },
  1057. {}
  1058. };
  1059. static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1060. /* See the note in cxt5047_hp_master_sw_put */
  1061. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1062. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1063. {}
  1064. };
  1065. static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1066. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1067. { } /* end */
  1068. };
  1069. static const struct hda_verb cxt5047_init_verbs[] = {
  1070. /* Line in, Mic, Built-in Mic */
  1071. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1072. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1073. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1074. /* HP, Speaker */
  1075. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1076. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1077. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1078. /* Record selector: Mic */
  1079. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1080. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1081. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1082. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1083. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1084. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1085. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1086. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1087. /* SPDIF route: PCM */
  1088. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1089. /* Enable unsolicited events */
  1090. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1091. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1092. { } /* end */
  1093. };
  1094. /* configuration for Toshiba Laptops */
  1095. static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1096. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1097. {}
  1098. };
  1099. /* Test configuration for debugging, modelled after the ALC260 test
  1100. * configuration.
  1101. */
  1102. #ifdef CONFIG_SND_DEBUG
  1103. static const struct hda_input_mux cxt5047_test_capture_source = {
  1104. .num_items = 4,
  1105. .items = {
  1106. { "LINE1 pin", 0x0 },
  1107. { "MIC1 pin", 0x1 },
  1108. { "MIC2 pin", 0x2 },
  1109. { "CD pin", 0x3 },
  1110. },
  1111. };
  1112. static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1113. /* Output only controls */
  1114. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1115. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1116. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1117. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1118. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1119. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1120. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1121. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1122. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1123. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1124. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1125. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1126. /* Modes for retasking pin widgets */
  1127. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1128. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1129. /* EAPD Switch Control */
  1130. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1131. /* Loopback mixer controls */
  1132. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1133. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1134. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1135. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1136. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1137. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1138. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1139. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1140. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1141. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1142. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1143. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1144. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1145. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1146. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1147. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1148. {
  1149. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1150. .name = "Input Source",
  1151. .info = conexant_mux_enum_info,
  1152. .get = conexant_mux_enum_get,
  1153. .put = conexant_mux_enum_put,
  1154. },
  1155. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1156. { } /* end */
  1157. };
  1158. static const struct hda_verb cxt5047_test_init_verbs[] = {
  1159. /* Enable retasking pins as output, initially without power amp */
  1160. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1161. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1162. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1163. /* Disable digital (SPDIF) pins initially, but users can enable
  1164. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1165. * payload also sets the generation to 0, output to be in "consumer"
  1166. * PCM format, copyright asserted, no pre-emphasis and no validity
  1167. * control.
  1168. */
  1169. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1170. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1171. * OUT1 sum bus when acting as an output.
  1172. */
  1173. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1174. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1175. /* Start with output sum widgets muted and their output gains at min */
  1176. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1177. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1178. /* Unmute retasking pin widget output buffers since the default
  1179. * state appears to be output. As the pin mode is changed by the
  1180. * user the pin mode control will take care of enabling the pin's
  1181. * input/output buffers as needed.
  1182. */
  1183. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1184. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1185. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1186. /* Mute capture amp left and right */
  1187. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1188. /* Set ADC connection select to match default mixer setting (mic1
  1189. * pin)
  1190. */
  1191. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1192. /* Mute all inputs to mixer widget (even unconnected ones) */
  1193. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1194. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1195. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1196. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1197. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1198. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1199. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1200. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1201. { }
  1202. };
  1203. #endif
  1204. /* initialize jack-sensing, too */
  1205. static int cxt5047_hp_init(struct hda_codec *codec)
  1206. {
  1207. conexant_init(codec);
  1208. cxt5047_hp_automute(codec);
  1209. return 0;
  1210. }
  1211. enum {
  1212. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1213. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1214. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1215. #ifdef CONFIG_SND_DEBUG
  1216. CXT5047_TEST,
  1217. #endif
  1218. CXT5047_AUTO,
  1219. CXT5047_MODELS
  1220. };
  1221. static const char * const cxt5047_models[CXT5047_MODELS] = {
  1222. [CXT5047_LAPTOP] = "laptop",
  1223. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1224. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1225. #ifdef CONFIG_SND_DEBUG
  1226. [CXT5047_TEST] = "test",
  1227. #endif
  1228. [CXT5047_AUTO] = "auto",
  1229. };
  1230. static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1231. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1232. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1233. CXT5047_LAPTOP),
  1234. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1235. {}
  1236. };
  1237. static int patch_cxt5047(struct hda_codec *codec)
  1238. {
  1239. struct conexant_spec *spec;
  1240. int board_config;
  1241. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1242. cxt5047_models,
  1243. cxt5047_cfg_tbl);
  1244. if (board_config < 0)
  1245. board_config = CXT5047_AUTO; /* model=auto as default */
  1246. if (board_config == CXT5047_AUTO)
  1247. return patch_conexant_auto(codec);
  1248. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1249. if (!spec)
  1250. return -ENOMEM;
  1251. codec->spec = spec;
  1252. codec->pin_amp_workaround = 1;
  1253. spec->multiout.max_channels = 2;
  1254. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1255. spec->multiout.dac_nids = cxt5047_dac_nids;
  1256. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1257. spec->num_adc_nids = 1;
  1258. spec->adc_nids = cxt5047_adc_nids;
  1259. spec->capsrc_nids = cxt5047_capsrc_nids;
  1260. spec->num_mixers = 1;
  1261. spec->mixers[0] = cxt5047_base_mixers;
  1262. spec->num_init_verbs = 1;
  1263. spec->init_verbs[0] = cxt5047_init_verbs;
  1264. spec->spdif_route = 0;
  1265. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1266. spec->channel_mode = cxt5047_modes,
  1267. codec->patch_ops = conexant_patch_ops;
  1268. switch (board_config) {
  1269. case CXT5047_LAPTOP:
  1270. spec->num_mixers = 2;
  1271. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1272. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1273. break;
  1274. case CXT5047_LAPTOP_HP:
  1275. spec->num_mixers = 2;
  1276. spec->mixers[1] = cxt5047_hp_only_mixers;
  1277. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1278. codec->patch_ops.init = cxt5047_hp_init;
  1279. break;
  1280. case CXT5047_LAPTOP_EAPD:
  1281. spec->input_mux = &cxt5047_toshiba_capture_source;
  1282. spec->num_mixers = 2;
  1283. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1284. spec->num_init_verbs = 2;
  1285. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1286. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1287. break;
  1288. #ifdef CONFIG_SND_DEBUG
  1289. case CXT5047_TEST:
  1290. spec->input_mux = &cxt5047_test_capture_source;
  1291. spec->mixers[0] = cxt5047_test_mixer;
  1292. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1293. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1294. #endif
  1295. }
  1296. spec->vmaster_nid = 0x13;
  1297. switch (codec->subsystem_id >> 16) {
  1298. case 0x103c:
  1299. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1300. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1301. * with 0 dB offset 0x17)
  1302. */
  1303. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1304. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1305. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1306. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1307. (1 << AC_AMPCAP_MUTE_SHIFT));
  1308. break;
  1309. }
  1310. return 0;
  1311. }
  1312. /* Conexant 5051 specific */
  1313. static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1314. static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1315. static const struct hda_channel_mode cxt5051_modes[1] = {
  1316. { 2, NULL },
  1317. };
  1318. static void cxt5051_update_speaker(struct hda_codec *codec)
  1319. {
  1320. struct conexant_spec *spec = codec->spec;
  1321. unsigned int pinctl;
  1322. /* headphone pin */
  1323. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1324. snd_hda_set_pin_ctl(codec, 0x16, pinctl);
  1325. /* speaker pin */
  1326. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1327. snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
  1328. /* on ideapad there is an additional speaker (subwoofer) to mute */
  1329. if (spec->ideapad)
  1330. snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
  1331. }
  1332. /* turn on/off EAPD (+ mute HP) as a master switch */
  1333. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1334. struct snd_ctl_elem_value *ucontrol)
  1335. {
  1336. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1337. if (!cxt_eapd_put(kcontrol, ucontrol))
  1338. return 0;
  1339. cxt5051_update_speaker(codec);
  1340. return 1;
  1341. }
  1342. /* toggle input of built-in and mic jack appropriately */
  1343. static void cxt5051_portb_automic(struct hda_codec *codec)
  1344. {
  1345. struct conexant_spec *spec = codec->spec;
  1346. unsigned int present;
  1347. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1348. return;
  1349. present = snd_hda_jack_detect(codec, 0x17);
  1350. snd_hda_codec_write(codec, 0x14, 0,
  1351. AC_VERB_SET_CONNECT_SEL,
  1352. present ? 0x01 : 0x00);
  1353. }
  1354. /* switch the current ADC according to the jack state */
  1355. static void cxt5051_portc_automic(struct hda_codec *codec)
  1356. {
  1357. struct conexant_spec *spec = codec->spec;
  1358. unsigned int present;
  1359. hda_nid_t new_adc;
  1360. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1361. return;
  1362. present = snd_hda_jack_detect(codec, 0x18);
  1363. if (present)
  1364. spec->cur_adc_idx = 1;
  1365. else
  1366. spec->cur_adc_idx = 0;
  1367. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1368. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1369. /* stream is running, let's swap the current ADC */
  1370. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1371. spec->cur_adc = new_adc;
  1372. snd_hda_codec_setup_stream(codec, new_adc,
  1373. spec->cur_adc_stream_tag, 0,
  1374. spec->cur_adc_format);
  1375. }
  1376. }
  1377. /* mute internal speaker if HP is plugged */
  1378. static void cxt5051_hp_automute(struct hda_codec *codec)
  1379. {
  1380. struct conexant_spec *spec = codec->spec;
  1381. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1382. cxt5051_update_speaker(codec);
  1383. }
  1384. /* unsolicited event for HP jack sensing */
  1385. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1386. unsigned int res)
  1387. {
  1388. switch (res >> 26) {
  1389. case CONEXANT_HP_EVENT:
  1390. cxt5051_hp_automute(codec);
  1391. break;
  1392. case CXT5051_PORTB_EVENT:
  1393. cxt5051_portb_automic(codec);
  1394. break;
  1395. case CXT5051_PORTC_EVENT:
  1396. cxt5051_portc_automic(codec);
  1397. break;
  1398. }
  1399. }
  1400. static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1401. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1402. {
  1403. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1404. .name = "Master Playback Switch",
  1405. .info = cxt_eapd_info,
  1406. .get = cxt_eapd_get,
  1407. .put = cxt5051_hp_master_sw_put,
  1408. .private_value = 0x1a,
  1409. },
  1410. {}
  1411. };
  1412. static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1413. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1414. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1415. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1416. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1417. HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
  1418. HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
  1419. {}
  1420. };
  1421. static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1422. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1423. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1424. HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
  1425. HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
  1426. {}
  1427. };
  1428. static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1429. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1430. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1431. {}
  1432. };
  1433. static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1434. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1435. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1436. {}
  1437. };
  1438. static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1439. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1440. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1441. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1442. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1443. {}
  1444. };
  1445. static const struct hda_verb cxt5051_init_verbs[] = {
  1446. /* Line in, Mic */
  1447. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1448. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1449. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1450. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1451. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1452. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1453. /* SPK */
  1454. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1455. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1456. /* HP, Amp */
  1457. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1458. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1459. /* DAC1 */
  1460. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1461. /* Record selector: Internal mic */
  1462. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1463. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1464. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1465. /* SPDIF route: PCM */
  1466. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1467. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1468. /* EAPD */
  1469. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1470. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1471. { } /* end */
  1472. };
  1473. static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1474. /* Line in, Mic */
  1475. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1476. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1477. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1478. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1479. /* SPK */
  1480. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1481. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1482. /* HP, Amp */
  1483. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1484. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1485. /* DAC1 */
  1486. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1487. /* Record selector: Internal mic */
  1488. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1489. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1490. /* SPDIF route: PCM */
  1491. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1492. /* EAPD */
  1493. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1494. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1495. { } /* end */
  1496. };
  1497. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1498. /* Line in, Mic */
  1499. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1500. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1501. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1502. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1503. /* SPK */
  1504. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1505. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1506. /* HP, Amp */
  1507. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1508. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1509. /* DAC1 */
  1510. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1511. /* Record selector: Internal mic */
  1512. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1513. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1514. /* SPDIF route: PCM */
  1515. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1516. /* EAPD */
  1517. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1518. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1519. { } /* end */
  1520. };
  1521. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1522. unsigned int event)
  1523. {
  1524. snd_hda_codec_write(codec, nid, 0,
  1525. AC_VERB_SET_UNSOLICITED_ENABLE,
  1526. AC_USRSP_EN | event);
  1527. }
  1528. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1529. /* Subwoofer */
  1530. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1531. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1532. { } /* end */
  1533. };
  1534. /* initialize jack-sensing, too */
  1535. static int cxt5051_init(struct hda_codec *codec)
  1536. {
  1537. struct conexant_spec *spec = codec->spec;
  1538. conexant_init(codec);
  1539. if (spec->auto_mic & AUTO_MIC_PORTB)
  1540. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1541. if (spec->auto_mic & AUTO_MIC_PORTC)
  1542. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1543. if (codec->patch_ops.unsol_event) {
  1544. cxt5051_hp_automute(codec);
  1545. cxt5051_portb_automic(codec);
  1546. cxt5051_portc_automic(codec);
  1547. }
  1548. return 0;
  1549. }
  1550. enum {
  1551. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1552. CXT5051_HP, /* no docking */
  1553. CXT5051_HP_DV6736, /* HP without mic switch */
  1554. CXT5051_F700, /* HP Compaq Presario F700 */
  1555. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1556. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1557. CXT5051_AUTO, /* auto-parser */
  1558. CXT5051_MODELS
  1559. };
  1560. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1561. [CXT5051_LAPTOP] = "laptop",
  1562. [CXT5051_HP] = "hp",
  1563. [CXT5051_HP_DV6736] = "hp-dv6736",
  1564. [CXT5051_F700] = "hp-700",
  1565. [CXT5051_TOSHIBA] = "toshiba",
  1566. [CXT5051_IDEAPAD] = "ideapad",
  1567. [CXT5051_AUTO] = "auto",
  1568. };
  1569. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1570. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1571. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1572. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1573. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1574. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1575. CXT5051_LAPTOP),
  1576. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1577. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1578. {}
  1579. };
  1580. static int patch_cxt5051(struct hda_codec *codec)
  1581. {
  1582. struct conexant_spec *spec;
  1583. int board_config;
  1584. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1585. cxt5051_models,
  1586. cxt5051_cfg_tbl);
  1587. if (board_config < 0)
  1588. board_config = CXT5051_AUTO; /* model=auto as default */
  1589. if (board_config == CXT5051_AUTO)
  1590. return patch_conexant_auto(codec);
  1591. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1592. if (!spec)
  1593. return -ENOMEM;
  1594. codec->spec = spec;
  1595. codec->pin_amp_workaround = 1;
  1596. codec->patch_ops = conexant_patch_ops;
  1597. codec->patch_ops.init = cxt5051_init;
  1598. spec->multiout.max_channels = 2;
  1599. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1600. spec->multiout.dac_nids = cxt5051_dac_nids;
  1601. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1602. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1603. spec->adc_nids = cxt5051_adc_nids;
  1604. spec->num_mixers = 2;
  1605. spec->mixers[0] = cxt5051_capture_mixers;
  1606. spec->mixers[1] = cxt5051_playback_mixers;
  1607. spec->num_init_verbs = 1;
  1608. spec->init_verbs[0] = cxt5051_init_verbs;
  1609. spec->spdif_route = 0;
  1610. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1611. spec->channel_mode = cxt5051_modes;
  1612. spec->cur_adc = 0;
  1613. spec->cur_adc_idx = 0;
  1614. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1615. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1616. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1617. switch (board_config) {
  1618. case CXT5051_HP:
  1619. spec->mixers[0] = cxt5051_hp_mixers;
  1620. break;
  1621. case CXT5051_HP_DV6736:
  1622. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1623. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1624. spec->auto_mic = 0;
  1625. break;
  1626. case CXT5051_F700:
  1627. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1628. spec->mixers[0] = cxt5051_f700_mixers;
  1629. spec->auto_mic = 0;
  1630. break;
  1631. case CXT5051_TOSHIBA:
  1632. spec->mixers[0] = cxt5051_toshiba_mixers;
  1633. spec->auto_mic = AUTO_MIC_PORTB;
  1634. break;
  1635. case CXT5051_IDEAPAD:
  1636. spec->init_verbs[spec->num_init_verbs++] =
  1637. cxt5051_ideapad_init_verbs;
  1638. spec->ideapad = 1;
  1639. break;
  1640. }
  1641. if (spec->beep_amp)
  1642. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  1643. return 0;
  1644. }
  1645. /* Conexant 5066 specific */
  1646. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1647. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1648. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1649. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1650. static const struct hda_channel_mode cxt5066_modes[1] = {
  1651. { 2, NULL },
  1652. };
  1653. #define HP_PRESENT_PORT_A (1 << 0)
  1654. #define HP_PRESENT_PORT_D (1 << 1)
  1655. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1656. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1657. static void cxt5066_update_speaker(struct hda_codec *codec)
  1658. {
  1659. struct conexant_spec *spec = codec->spec;
  1660. unsigned int pinctl;
  1661. snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1662. spec->hp_present, spec->cur_eapd);
  1663. /* Port A (HP) */
  1664. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1665. snd_hda_set_pin_ctl(codec, 0x19, pinctl);
  1666. /* Port D (HP/LO) */
  1667. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1668. if (spec->dell_automute || spec->thinkpad) {
  1669. /* Mute if Port A is connected */
  1670. if (hp_port_a_present(spec))
  1671. pinctl = 0;
  1672. } else {
  1673. /* Thinkpad/Dell doesn't give pin-D status */
  1674. if (!hp_port_d_present(spec))
  1675. pinctl = 0;
  1676. }
  1677. snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
  1678. /* CLASS_D AMP */
  1679. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1680. snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
  1681. }
  1682. /* turn on/off EAPD (+ mute HP) as a master switch */
  1683. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1684. struct snd_ctl_elem_value *ucontrol)
  1685. {
  1686. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1687. if (!cxt_eapd_put(kcontrol, ucontrol))
  1688. return 0;
  1689. cxt5066_update_speaker(codec);
  1690. return 1;
  1691. }
  1692. /* toggle input of built-in digital mic and mic jack appropriately */
  1693. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1694. {
  1695. unsigned int present;
  1696. struct hda_verb ext_mic_present[] = {
  1697. /* enable external mic, port B */
  1698. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1699. /* switch to external mic input */
  1700. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1701. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1702. /* disable internal digital mic */
  1703. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1704. {}
  1705. };
  1706. static const struct hda_verb ext_mic_absent[] = {
  1707. /* enable internal mic, port C */
  1708. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1709. /* switch to internal mic input */
  1710. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1711. /* disable external mic, port B */
  1712. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1713. {}
  1714. };
  1715. present = snd_hda_jack_detect(codec, 0x1a);
  1716. if (present) {
  1717. snd_printdd("CXT5066: external microphone detected\n");
  1718. snd_hda_sequence_write(codec, ext_mic_present);
  1719. } else {
  1720. snd_printdd("CXT5066: external microphone absent\n");
  1721. snd_hda_sequence_write(codec, ext_mic_absent);
  1722. }
  1723. }
  1724. /* toggle input of built-in digital mic and mic jack appropriately */
  1725. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1726. {
  1727. unsigned int present;
  1728. struct hda_verb ext_mic_present[] = {
  1729. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1730. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1731. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1732. {}
  1733. };
  1734. static const struct hda_verb ext_mic_absent[] = {
  1735. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1736. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1737. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1738. {}
  1739. };
  1740. present = snd_hda_jack_detect(codec, 0x1b);
  1741. if (present) {
  1742. snd_printdd("CXT5066: external microphone detected\n");
  1743. snd_hda_sequence_write(codec, ext_mic_present);
  1744. } else {
  1745. snd_printdd("CXT5066: external microphone absent\n");
  1746. snd_hda_sequence_write(codec, ext_mic_absent);
  1747. }
  1748. }
  1749. /* toggle input of built-in digital mic and mic jack appropriately */
  1750. static void cxt5066_asus_automic(struct hda_codec *codec)
  1751. {
  1752. unsigned int present;
  1753. present = snd_hda_jack_detect(codec, 0x1b);
  1754. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1755. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1756. present ? 1 : 0);
  1757. }
  1758. /* toggle input of built-in digital mic and mic jack appropriately */
  1759. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  1760. {
  1761. unsigned int present;
  1762. present = snd_hda_jack_detect(codec, 0x1b);
  1763. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1764. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1765. present ? 1 : 3);
  1766. }
  1767. /* toggle input of built-in digital mic and mic jack appropriately
  1768. order is: external mic -> dock mic -> interal mic */
  1769. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1770. {
  1771. unsigned int ext_present, dock_present;
  1772. static const struct hda_verb ext_mic_present[] = {
  1773. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1774. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1775. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1776. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1777. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1778. {}
  1779. };
  1780. static const struct hda_verb dock_mic_present[] = {
  1781. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1782. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1783. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1784. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1785. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1786. {}
  1787. };
  1788. static const struct hda_verb ext_mic_absent[] = {
  1789. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1790. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1791. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1792. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1793. {}
  1794. };
  1795. ext_present = snd_hda_jack_detect(codec, 0x1b);
  1796. dock_present = snd_hda_jack_detect(codec, 0x1a);
  1797. if (ext_present) {
  1798. snd_printdd("CXT5066: external microphone detected\n");
  1799. snd_hda_sequence_write(codec, ext_mic_present);
  1800. } else if (dock_present) {
  1801. snd_printdd("CXT5066: dock microphone detected\n");
  1802. snd_hda_sequence_write(codec, dock_mic_present);
  1803. } else {
  1804. snd_printdd("CXT5066: external microphone absent\n");
  1805. snd_hda_sequence_write(codec, ext_mic_absent);
  1806. }
  1807. }
  1808. /* mute internal speaker if HP is plugged */
  1809. static void cxt5066_hp_automute(struct hda_codec *codec)
  1810. {
  1811. struct conexant_spec *spec = codec->spec;
  1812. unsigned int portA, portD;
  1813. /* Port A */
  1814. portA = snd_hda_jack_detect(codec, 0x19);
  1815. /* Port D */
  1816. portD = snd_hda_jack_detect(codec, 0x1c);
  1817. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  1818. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  1819. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1820. portA, portD, spec->hp_present);
  1821. cxt5066_update_speaker(codec);
  1822. }
  1823. /* Dispatch the right mic autoswitch function */
  1824. static void cxt5066_automic(struct hda_codec *codec)
  1825. {
  1826. struct conexant_spec *spec = codec->spec;
  1827. if (spec->dell_vostro)
  1828. cxt5066_vostro_automic(codec);
  1829. else if (spec->ideapad)
  1830. cxt5066_ideapad_automic(codec);
  1831. else if (spec->thinkpad)
  1832. cxt5066_thinkpad_automic(codec);
  1833. else if (spec->hp_laptop)
  1834. cxt5066_hp_laptop_automic(codec);
  1835. else if (spec->asus)
  1836. cxt5066_asus_automic(codec);
  1837. }
  1838. /* unsolicited event for jack sensing */
  1839. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  1840. {
  1841. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1842. switch (res >> 26) {
  1843. case CONEXANT_HP_EVENT:
  1844. cxt5066_hp_automute(codec);
  1845. break;
  1846. case CONEXANT_MIC_EVENT:
  1847. cxt5066_automic(codec);
  1848. break;
  1849. }
  1850. }
  1851. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  1852. .num_items = 5,
  1853. .items = {
  1854. { "0dB", 0 },
  1855. { "10dB", 1 },
  1856. { "20dB", 2 },
  1857. { "30dB", 3 },
  1858. { "40dB", 4 },
  1859. },
  1860. };
  1861. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  1862. {
  1863. struct conexant_spec *spec = codec->spec;
  1864. snd_hda_codec_write_cache(codec, 0x17, 0,
  1865. AC_VERB_SET_AMP_GAIN_MUTE,
  1866. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  1867. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  1868. if (spec->ideapad || spec->thinkpad) {
  1869. /* adjust the internal mic as well...it is not through 0x17 */
  1870. snd_hda_codec_write_cache(codec, 0x23, 0,
  1871. AC_VERB_SET_AMP_GAIN_MUTE,
  1872. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  1873. cxt5066_analog_mic_boost.
  1874. items[spec->mic_boost].index);
  1875. }
  1876. }
  1877. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  1878. struct snd_ctl_elem_info *uinfo)
  1879. {
  1880. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  1881. }
  1882. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  1883. struct snd_ctl_elem_value *ucontrol)
  1884. {
  1885. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1886. struct conexant_spec *spec = codec->spec;
  1887. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  1888. return 0;
  1889. }
  1890. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  1891. struct snd_ctl_elem_value *ucontrol)
  1892. {
  1893. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1894. struct conexant_spec *spec = codec->spec;
  1895. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  1896. unsigned int idx;
  1897. idx = ucontrol->value.enumerated.item[0];
  1898. if (idx >= imux->num_items)
  1899. idx = imux->num_items - 1;
  1900. spec->mic_boost = idx;
  1901. cxt5066_set_mic_boost(codec);
  1902. return 1;
  1903. }
  1904. static void conexant_check_dig_outs(struct hda_codec *codec,
  1905. const hda_nid_t *dig_pins,
  1906. int num_pins)
  1907. {
  1908. struct conexant_spec *spec = codec->spec;
  1909. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  1910. int i;
  1911. for (i = 0; i < num_pins; i++, dig_pins++) {
  1912. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  1913. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  1914. continue;
  1915. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  1916. continue;
  1917. }
  1918. }
  1919. static const struct hda_input_mux cxt5066_capture_source = {
  1920. .num_items = 4,
  1921. .items = {
  1922. { "Mic B", 0 },
  1923. { "Mic C", 1 },
  1924. { "Mic E", 2 },
  1925. { "Mic F", 3 },
  1926. },
  1927. };
  1928. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  1929. .ops = &snd_hda_bind_vol,
  1930. .values = {
  1931. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1932. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1933. 0
  1934. },
  1935. };
  1936. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  1937. .ops = &snd_hda_bind_sw,
  1938. .values = {
  1939. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1940. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1941. 0
  1942. },
  1943. };
  1944. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  1945. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1946. {}
  1947. };
  1948. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  1949. {
  1950. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1951. .name = "Master Playback Switch",
  1952. .info = cxt_eapd_info,
  1953. .get = cxt_eapd_get,
  1954. .put = cxt5066_hp_master_sw_put,
  1955. .private_value = 0x1d,
  1956. },
  1957. {
  1958. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1959. .name = "Analog Mic Boost Capture Enum",
  1960. .info = cxt5066_mic_boost_mux_enum_info,
  1961. .get = cxt5066_mic_boost_mux_enum_get,
  1962. .put = cxt5066_mic_boost_mux_enum_put,
  1963. },
  1964. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  1965. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  1966. {}
  1967. };
  1968. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  1969. {
  1970. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1971. .name = "Internal Mic Boost Capture Enum",
  1972. .info = cxt5066_mic_boost_mux_enum_info,
  1973. .get = cxt5066_mic_boost_mux_enum_get,
  1974. .put = cxt5066_mic_boost_mux_enum_put,
  1975. .private_value = 0x23 | 0x100,
  1976. },
  1977. {}
  1978. };
  1979. static const struct hda_verb cxt5066_init_verbs[] = {
  1980. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  1981. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  1982. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  1983. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  1984. /* Speakers */
  1985. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1986. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1987. /* HP, Amp */
  1988. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1989. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1990. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1991. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1992. /* DAC1 */
  1993. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1994. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  1995. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  1996. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1997. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  1998. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1999. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2000. /* no digital microphone support yet */
  2001. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2002. /* Audio input selector */
  2003. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2004. /* SPDIF route: PCM */
  2005. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2006. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2007. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2008. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2009. /* EAPD */
  2010. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2011. /* not handling these yet */
  2012. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2013. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2014. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2015. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2016. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2017. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2018. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2019. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2020. { } /* end */
  2021. };
  2022. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2023. /* Port A: headphones */
  2024. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2025. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2026. /* Port B: external microphone */
  2027. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2028. /* Port C: unused */
  2029. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2030. /* Port D: unused */
  2031. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2032. /* Port E: unused, but has primary EAPD */
  2033. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2034. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2035. /* Port F: unused */
  2036. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2037. /* Port G: internal speakers */
  2038. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2039. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2040. /* DAC1 */
  2041. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2042. /* DAC2: unused */
  2043. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2044. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2045. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2046. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2047. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2048. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2049. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2050. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2051. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2052. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2053. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2054. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2055. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2056. /* Digital microphone port */
  2057. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2058. /* Audio input selectors */
  2059. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2060. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2061. /* Disable SPDIF */
  2062. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2063. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2064. /* enable unsolicited events for Port A and B */
  2065. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2066. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2067. { } /* end */
  2068. };
  2069. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2070. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2071. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2072. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2073. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2074. /* Speakers */
  2075. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2076. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2077. /* HP, Amp */
  2078. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2079. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2080. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2081. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2082. /* DAC1 */
  2083. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2084. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2085. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2086. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2087. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2088. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2089. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2090. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2091. /* Audio input selector */
  2092. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2093. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2094. /* SPDIF route: PCM */
  2095. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2096. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2097. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2098. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2099. /* internal microphone */
  2100. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2101. /* EAPD */
  2102. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2103. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2104. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2105. { } /* end */
  2106. };
  2107. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2108. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2109. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2110. /* Port G: internal speakers */
  2111. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2112. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2113. /* Port A: HP, Amp */
  2114. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2115. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2116. /* Port B: Mic Dock */
  2117. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2118. /* Port C: Mic */
  2119. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2120. /* Port D: HP Dock, Amp */
  2121. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2122. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2123. /* DAC1 */
  2124. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2125. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2126. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2127. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2128. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2129. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2130. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2131. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2132. /* Audio input selector */
  2133. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2134. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2135. /* SPDIF route: PCM */
  2136. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2137. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2138. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2139. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2140. /* internal microphone */
  2141. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2142. /* EAPD */
  2143. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2144. /* enable unsolicited events for Port A, B, C and D */
  2145. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2146. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2147. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2148. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2149. { } /* end */
  2150. };
  2151. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2152. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2153. { } /* end */
  2154. };
  2155. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2156. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2157. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2158. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2159. { } /* end */
  2160. };
  2161. /* initialize jack-sensing, too */
  2162. static int cxt5066_init(struct hda_codec *codec)
  2163. {
  2164. snd_printdd("CXT5066: init\n");
  2165. conexant_init(codec);
  2166. if (codec->patch_ops.unsol_event) {
  2167. cxt5066_hp_automute(codec);
  2168. cxt5066_automic(codec);
  2169. }
  2170. cxt5066_set_mic_boost(codec);
  2171. return 0;
  2172. }
  2173. enum {
  2174. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2175. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2176. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2177. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2178. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2179. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2180. CXT5066_HP_LAPTOP, /* HP Laptop */
  2181. CXT5066_AUTO, /* BIOS auto-parser */
  2182. CXT5066_MODELS
  2183. };
  2184. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2185. [CXT5066_LAPTOP] = "laptop",
  2186. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2187. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2188. [CXT5066_IDEAPAD] = "ideapad",
  2189. [CXT5066_THINKPAD] = "thinkpad",
  2190. [CXT5066_ASUS] = "asus",
  2191. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2192. [CXT5066_AUTO] = "auto",
  2193. };
  2194. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2195. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2196. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2197. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2198. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2199. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2200. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2201. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2202. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2203. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2204. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2205. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2206. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2207. CXT5066_LAPTOP),
  2208. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2209. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2210. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2211. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
  2212. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2213. {}
  2214. };
  2215. static int patch_cxt5066(struct hda_codec *codec)
  2216. {
  2217. struct conexant_spec *spec;
  2218. int board_config;
  2219. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2220. cxt5066_models, cxt5066_cfg_tbl);
  2221. if (board_config < 0)
  2222. board_config = CXT5066_AUTO; /* model=auto as default */
  2223. if (board_config == CXT5066_AUTO)
  2224. return patch_conexant_auto(codec);
  2225. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2226. if (!spec)
  2227. return -ENOMEM;
  2228. codec->spec = spec;
  2229. codec->patch_ops = conexant_patch_ops;
  2230. codec->patch_ops.init = conexant_init;
  2231. spec->dell_automute = 0;
  2232. spec->multiout.max_channels = 2;
  2233. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2234. spec->multiout.dac_nids = cxt5066_dac_nids;
  2235. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2236. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2237. spec->num_adc_nids = 1;
  2238. spec->adc_nids = cxt5066_adc_nids;
  2239. spec->capsrc_nids = cxt5066_capsrc_nids;
  2240. spec->input_mux = &cxt5066_capture_source;
  2241. spec->port_d_mode = PIN_HP;
  2242. spec->num_init_verbs = 1;
  2243. spec->init_verbs[0] = cxt5066_init_verbs;
  2244. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2245. spec->channel_mode = cxt5066_modes;
  2246. spec->cur_adc = 0;
  2247. spec->cur_adc_idx = 0;
  2248. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2249. switch (board_config) {
  2250. default:
  2251. case CXT5066_LAPTOP:
  2252. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2253. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2254. break;
  2255. case CXT5066_DELL_LAPTOP:
  2256. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2257. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2258. spec->port_d_mode = PIN_OUT;
  2259. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2260. spec->num_init_verbs++;
  2261. spec->dell_automute = 1;
  2262. break;
  2263. case CXT5066_ASUS:
  2264. case CXT5066_HP_LAPTOP:
  2265. codec->patch_ops.init = cxt5066_init;
  2266. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2267. spec->init_verbs[spec->num_init_verbs] =
  2268. cxt5066_init_verbs_hp_laptop;
  2269. spec->num_init_verbs++;
  2270. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2271. spec->asus = board_config == CXT5066_ASUS;
  2272. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2273. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2274. /* no S/PDIF out */
  2275. if (board_config == CXT5066_HP_LAPTOP)
  2276. spec->multiout.dig_out_nid = 0;
  2277. /* input source automatically selected */
  2278. spec->input_mux = NULL;
  2279. spec->port_d_mode = 0;
  2280. spec->mic_boost = 3; /* default 30dB gain */
  2281. break;
  2282. case CXT5066_DELL_VOSTRO:
  2283. codec->patch_ops.init = cxt5066_init;
  2284. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2285. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2286. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2287. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2288. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2289. spec->port_d_mode = 0;
  2290. spec->dell_vostro = 1;
  2291. spec->mic_boost = 3; /* default 30dB gain */
  2292. /* no S/PDIF out */
  2293. spec->multiout.dig_out_nid = 0;
  2294. /* input source automatically selected */
  2295. spec->input_mux = NULL;
  2296. break;
  2297. case CXT5066_IDEAPAD:
  2298. codec->patch_ops.init = cxt5066_init;
  2299. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2300. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2301. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2302. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2303. spec->port_d_mode = 0;
  2304. spec->ideapad = 1;
  2305. spec->mic_boost = 2; /* default 20dB gain */
  2306. /* no S/PDIF out */
  2307. spec->multiout.dig_out_nid = 0;
  2308. /* input source automatically selected */
  2309. spec->input_mux = NULL;
  2310. break;
  2311. case CXT5066_THINKPAD:
  2312. codec->patch_ops.init = cxt5066_init;
  2313. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2314. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2315. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2316. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2317. spec->thinkpad = 1;
  2318. spec->port_d_mode = PIN_OUT;
  2319. spec->mic_boost = 2; /* default 20dB gain */
  2320. /* no S/PDIF out */
  2321. spec->multiout.dig_out_nid = 0;
  2322. /* input source automatically selected */
  2323. spec->input_mux = NULL;
  2324. break;
  2325. }
  2326. if (spec->beep_amp)
  2327. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  2328. return 0;
  2329. }
  2330. #endif /* ENABLE_CXT_STATIC_QUIRKS */
  2331. /*
  2332. * Automatic parser for CX20641 & co
  2333. */
  2334. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2335. static void cx_auto_parse_beep(struct hda_codec *codec)
  2336. {
  2337. struct conexant_spec *spec = codec->spec;
  2338. hda_nid_t nid, end_nid;
  2339. end_nid = codec->start_nid + codec->num_nodes;
  2340. for (nid = codec->start_nid; nid < end_nid; nid++)
  2341. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  2342. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  2343. break;
  2344. }
  2345. }
  2346. #else
  2347. #define cx_auto_parse_beep(codec)
  2348. #endif
  2349. /* parse EAPDs */
  2350. static void cx_auto_parse_eapd(struct hda_codec *codec)
  2351. {
  2352. struct conexant_spec *spec = codec->spec;
  2353. hda_nid_t nid, end_nid;
  2354. end_nid = codec->start_nid + codec->num_nodes;
  2355. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2356. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  2357. continue;
  2358. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
  2359. continue;
  2360. spec->eapds[spec->num_eapds++] = nid;
  2361. if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
  2362. break;
  2363. }
  2364. /* NOTE: below is a wild guess; if we have more than two EAPDs,
  2365. * it's a new chip, where EAPDs are supposed to be associated to
  2366. * pins, and we can control EAPD per pin.
  2367. * OTOH, if only one or two EAPDs are found, it's an old chip,
  2368. * thus it might control over all pins.
  2369. */
  2370. if (spec->num_eapds > 2)
  2371. spec->dynamic_eapd = 1;
  2372. }
  2373. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  2374. hda_nid_t *pins, bool on)
  2375. {
  2376. int i;
  2377. for (i = 0; i < num_pins; i++) {
  2378. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  2379. snd_hda_codec_write(codec, pins[i], 0,
  2380. AC_VERB_SET_EAPD_BTLENABLE,
  2381. on ? 0x02 : 0);
  2382. }
  2383. }
  2384. /* turn on/off EAPD according to Master switch */
  2385. static void cx_auto_vmaster_hook(void *private_data, int enabled)
  2386. {
  2387. struct hda_codec *codec = private_data;
  2388. struct conexant_spec *spec = codec->spec;
  2389. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
  2390. }
  2391. static int cx_auto_build_controls(struct hda_codec *codec)
  2392. {
  2393. int err;
  2394. err = snd_hda_gen_build_controls(codec);
  2395. if (err < 0)
  2396. return err;
  2397. err = add_beep_ctls(codec);
  2398. if (err < 0)
  2399. return err;
  2400. return 0;
  2401. }
  2402. static int cx_auto_init(struct hda_codec *codec)
  2403. {
  2404. struct conexant_spec *spec = codec->spec;
  2405. snd_hda_gen_init(codec);
  2406. if (!spec->dynamic_eapd)
  2407. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
  2408. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
  2409. return 0;
  2410. }
  2411. #define cx_auto_free snd_hda_gen_free
  2412. static const struct hda_codec_ops cx_auto_patch_ops = {
  2413. .build_controls = cx_auto_build_controls,
  2414. .build_pcms = snd_hda_gen_build_pcms,
  2415. .init = cx_auto_init,
  2416. .free = cx_auto_free,
  2417. .unsol_event = snd_hda_jack_unsol_event,
  2418. #ifdef CONFIG_PM
  2419. .check_power_status = snd_hda_gen_check_power_status,
  2420. #endif
  2421. };
  2422. /*
  2423. * pin fix-up
  2424. */
  2425. enum {
  2426. CXT_PINCFG_LENOVO_X200,
  2427. CXT_PINCFG_LENOVO_TP410,
  2428. CXT_PINCFG_LEMOTE_A1004,
  2429. CXT_PINCFG_LEMOTE_A1205,
  2430. CXT_FIXUP_STEREO_DMIC,
  2431. CXT_FIXUP_INC_MIC_BOOST,
  2432. CXT_FIXUP_HEADPHONE_MIC_PIN,
  2433. CXT_FIXUP_HEADPHONE_MIC,
  2434. CXT_FIXUP_GPIO1,
  2435. CXT_FIXUP_THINKPAD_ACPI,
  2436. CXT_FIXUP_OLPC_XO,
  2437. CXT_FIXUP_CAP_MIX_AMP,
  2438. CXT_FIXUP_TOSHIBA_P105,
  2439. CXT_FIXUP_HP_530,
  2440. CXT_FIXUP_CAP_MIX_AMP_5047,
  2441. };
  2442. /* for hda_fixup_thinkpad_acpi() */
  2443. #include "thinkpad_helper.c"
  2444. static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
  2445. const struct hda_fixup *fix, int action)
  2446. {
  2447. struct conexant_spec *spec = codec->spec;
  2448. spec->gen.inv_dmic_split = 1;
  2449. }
  2450. static void cxt5066_increase_mic_boost(struct hda_codec *codec,
  2451. const struct hda_fixup *fix, int action)
  2452. {
  2453. if (action != HDA_FIXUP_ACT_PRE_PROBE)
  2454. return;
  2455. snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
  2456. (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
  2457. (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2458. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2459. (0 << AC_AMPCAP_MUTE_SHIFT));
  2460. }
  2461. static void cxt_update_headset_mode(struct hda_codec *codec)
  2462. {
  2463. /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
  2464. int i;
  2465. bool mic_mode = false;
  2466. struct conexant_spec *spec = codec->spec;
  2467. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  2468. hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
  2469. for (i = 0; i < cfg->num_inputs; i++)
  2470. if (cfg->inputs[i].pin == mux_pin) {
  2471. mic_mode = !!cfg->inputs[i].is_headphone_mic;
  2472. break;
  2473. }
  2474. if (mic_mode) {
  2475. snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
  2476. spec->gen.hp_jack_present = false;
  2477. } else {
  2478. snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
  2479. spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
  2480. }
  2481. snd_hda_gen_update_outputs(codec);
  2482. }
  2483. static void cxt_update_headset_mode_hook(struct hda_codec *codec,
  2484. struct snd_ctl_elem_value *ucontrol)
  2485. {
  2486. cxt_update_headset_mode(codec);
  2487. }
  2488. static void cxt_fixup_headphone_mic(struct hda_codec *codec,
  2489. const struct hda_fixup *fix, int action)
  2490. {
  2491. struct conexant_spec *spec = codec->spec;
  2492. switch (action) {
  2493. case HDA_FIXUP_ACT_PRE_PROBE:
  2494. spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
  2495. break;
  2496. case HDA_FIXUP_ACT_PROBE:
  2497. spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
  2498. spec->gen.automute_hook = cxt_update_headset_mode;
  2499. break;
  2500. case HDA_FIXUP_ACT_INIT:
  2501. cxt_update_headset_mode(codec);
  2502. break;
  2503. }
  2504. }
  2505. /* OPLC XO 1.5 fixup */
  2506. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  2507. * through the microphone jack.
  2508. * When the user enables this through a mixer switch, both internal and
  2509. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  2510. * we also allow the bias to be configured through a separate mixer
  2511. * control. */
  2512. #define update_mic_pin(codec, nid, val) \
  2513. snd_hda_codec_update_cache(codec, nid, 0, \
  2514. AC_VERB_SET_PIN_WIDGET_CONTROL, val)
  2515. static const struct hda_input_mux olpc_xo_dc_bias = {
  2516. .num_items = 3,
  2517. .items = {
  2518. { "Off", PIN_IN },
  2519. { "50%", PIN_VREF50 },
  2520. { "80%", PIN_VREF80 },
  2521. },
  2522. };
  2523. static void olpc_xo_update_mic_boost(struct hda_codec *codec)
  2524. {
  2525. struct conexant_spec *spec = codec->spec;
  2526. int ch, val;
  2527. for (ch = 0; ch < 2; ch++) {
  2528. val = AC_AMP_SET_OUTPUT |
  2529. (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
  2530. if (!spec->dc_enable)
  2531. val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
  2532. snd_hda_codec_write(codec, 0x17, 0,
  2533. AC_VERB_SET_AMP_GAIN_MUTE, val);
  2534. }
  2535. }
  2536. static void olpc_xo_update_mic_pins(struct hda_codec *codec)
  2537. {
  2538. struct conexant_spec *spec = codec->spec;
  2539. int cur_input, val;
  2540. struct nid_path *path;
  2541. cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
  2542. /* Set up mic pins for port-B, C and F dynamically as the recording
  2543. * LED is turned on/off by these pin controls
  2544. */
  2545. if (!spec->dc_enable) {
  2546. /* disable DC bias path and pin for port F */
  2547. update_mic_pin(codec, 0x1e, 0);
  2548. snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
  2549. /* update port B (ext mic) and C (int mic) */
  2550. /* OLPC defers mic widget control until when capture is
  2551. * started because the microphone LED comes on as soon as
  2552. * these settings are put in place. if we did this before
  2553. * recording, it would give the false indication that
  2554. * recording is happening when it is not.
  2555. */
  2556. update_mic_pin(codec, 0x1a, spec->recording ?
  2557. snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
  2558. update_mic_pin(codec, 0x1b, spec->recording ?
  2559. snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
  2560. /* enable normal mic path */
  2561. path = snd_hda_get_path_from_idx(codec, cur_input);
  2562. if (path)
  2563. snd_hda_activate_path(codec, path, true, false);
  2564. } else {
  2565. /* disable normal mic path */
  2566. path = snd_hda_get_path_from_idx(codec, cur_input);
  2567. if (path)
  2568. snd_hda_activate_path(codec, path, false, false);
  2569. /* Even though port F is the DC input, the bias is controlled
  2570. * on port B. We also leave that port as an active input (but
  2571. * unselected) in DC mode just in case that is necessary to
  2572. * make the bias setting take effect.
  2573. */
  2574. if (spec->recording)
  2575. val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
  2576. else
  2577. val = 0;
  2578. update_mic_pin(codec, 0x1a, val);
  2579. update_mic_pin(codec, 0x1b, 0);
  2580. /* enable DC bias path and pin */
  2581. update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
  2582. snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
  2583. }
  2584. }
  2585. /* mic_autoswitch hook */
  2586. static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
  2587. {
  2588. struct conexant_spec *spec = codec->spec;
  2589. int saved_cached_write = codec->cached_write;
  2590. codec->cached_write = 1;
  2591. /* in DC mode, we don't handle automic */
  2592. if (!spec->dc_enable)
  2593. snd_hda_gen_mic_autoswitch(codec, jack);
  2594. olpc_xo_update_mic_pins(codec);
  2595. snd_hda_codec_flush_cache(codec);
  2596. codec->cached_write = saved_cached_write;
  2597. if (spec->dc_enable)
  2598. olpc_xo_update_mic_boost(codec);
  2599. }
  2600. /* pcm_capture hook */
  2601. static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
  2602. struct hda_codec *codec,
  2603. struct snd_pcm_substream *substream,
  2604. int action)
  2605. {
  2606. struct conexant_spec *spec = codec->spec;
  2607. /* toggle spec->recording flag and update mic pins accordingly
  2608. * for turning on/off LED
  2609. */
  2610. switch (action) {
  2611. case HDA_GEN_PCM_ACT_PREPARE:
  2612. spec->recording = 1;
  2613. olpc_xo_update_mic_pins(codec);
  2614. break;
  2615. case HDA_GEN_PCM_ACT_CLEANUP:
  2616. spec->recording = 0;
  2617. olpc_xo_update_mic_pins(codec);
  2618. break;
  2619. }
  2620. }
  2621. static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
  2622. struct snd_ctl_elem_value *ucontrol)
  2623. {
  2624. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2625. struct conexant_spec *spec = codec->spec;
  2626. ucontrol->value.integer.value[0] = spec->dc_enable;
  2627. return 0;
  2628. }
  2629. static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
  2630. struct snd_ctl_elem_value *ucontrol)
  2631. {
  2632. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2633. struct conexant_spec *spec = codec->spec;
  2634. int dc_enable = !!ucontrol->value.integer.value[0];
  2635. if (dc_enable == spec->dc_enable)
  2636. return 0;
  2637. spec->dc_enable = dc_enable;
  2638. olpc_xo_update_mic_pins(codec);
  2639. olpc_xo_update_mic_boost(codec);
  2640. return 1;
  2641. }
  2642. static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2643. struct snd_ctl_elem_value *ucontrol)
  2644. {
  2645. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2646. struct conexant_spec *spec = codec->spec;
  2647. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2648. return 0;
  2649. }
  2650. static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2651. struct snd_ctl_elem_info *uinfo)
  2652. {
  2653. return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
  2654. }
  2655. static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2656. struct snd_ctl_elem_value *ucontrol)
  2657. {
  2658. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2659. struct conexant_spec *spec = codec->spec;
  2660. const struct hda_input_mux *imux = &olpc_xo_dc_bias;
  2661. unsigned int idx;
  2662. idx = ucontrol->value.enumerated.item[0];
  2663. if (idx >= imux->num_items)
  2664. idx = imux->num_items - 1;
  2665. if (spec->dc_input_bias == idx)
  2666. return 0;
  2667. spec->dc_input_bias = idx;
  2668. if (spec->dc_enable)
  2669. olpc_xo_update_mic_pins(codec);
  2670. return 1;
  2671. }
  2672. static const struct snd_kcontrol_new olpc_xo_mixers[] = {
  2673. {
  2674. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2675. .name = "DC Mode Enable Switch",
  2676. .info = snd_ctl_boolean_mono_info,
  2677. .get = olpc_xo_dc_mode_get,
  2678. .put = olpc_xo_dc_mode_put,
  2679. },
  2680. {
  2681. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2682. .name = "DC Input Bias Enum",
  2683. .info = olpc_xo_dc_bias_enum_info,
  2684. .get = olpc_xo_dc_bias_enum_get,
  2685. .put = olpc_xo_dc_bias_enum_put,
  2686. },
  2687. {}
  2688. };
  2689. /* overriding mic boost put callback; update mic boost volume only when
  2690. * DC mode is disabled
  2691. */
  2692. static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
  2693. struct snd_ctl_elem_value *ucontrol)
  2694. {
  2695. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2696. struct conexant_spec *spec = codec->spec;
  2697. int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
  2698. if (ret > 0 && spec->dc_enable)
  2699. olpc_xo_update_mic_boost(codec);
  2700. return ret;
  2701. }
  2702. static void cxt_fixup_olpc_xo(struct hda_codec *codec,
  2703. const struct hda_fixup *fix, int action)
  2704. {
  2705. struct conexant_spec *spec = codec->spec;
  2706. int i;
  2707. if (action != HDA_FIXUP_ACT_PROBE)
  2708. return;
  2709. spec->gen.mic_autoswitch_hook = olpc_xo_automic;
  2710. spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
  2711. spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
  2712. snd_hda_add_new_ctls(codec, olpc_xo_mixers);
  2713. /* OLPC's microphone port is DC coupled for use with external sensors,
  2714. * therefore we use a 50% mic bias in order to center the input signal
  2715. * with the DC input range of the codec.
  2716. */
  2717. snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
  2718. /* override mic boost control */
  2719. for (i = 0; i < spec->gen.kctls.used; i++) {
  2720. struct snd_kcontrol_new *kctl =
  2721. snd_array_elem(&spec->gen.kctls, i);
  2722. if (!strcmp(kctl->name, "Mic Boost Volume")) {
  2723. kctl->put = olpc_xo_mic_boost_put;
  2724. break;
  2725. }
  2726. }
  2727. }
  2728. /*
  2729. * Fix max input level on mixer widget to 0dB
  2730. * (originally it has 0x2b steps with 0dB offset 0x14)
  2731. */
  2732. static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
  2733. const struct hda_fixup *fix, int action)
  2734. {
  2735. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  2736. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  2737. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2738. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2739. (1 << AC_AMPCAP_MUTE_SHIFT));
  2740. }
  2741. /*
  2742. * Fix max input level on mixer widget to 0dB
  2743. * (originally it has 0x1e steps with 0 dB offset 0x17)
  2744. */
  2745. static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
  2746. const struct hda_fixup *fix, int action)
  2747. {
  2748. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  2749. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2750. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2751. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2752. (1 << AC_AMPCAP_MUTE_SHIFT));
  2753. }
  2754. /* ThinkPad X200 & co with cxt5051 */
  2755. static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
  2756. { 0x16, 0x042140ff }, /* HP (seq# overridden) */
  2757. { 0x17, 0x21a11000 }, /* dock-mic */
  2758. { 0x19, 0x2121103f }, /* dock-HP */
  2759. { 0x1c, 0x21440100 }, /* dock SPDIF out */
  2760. {}
  2761. };
  2762. /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
  2763. static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
  2764. { 0x19, 0x042110ff }, /* HP (seq# overridden) */
  2765. { 0x1a, 0x21a190f0 }, /* dock-mic */
  2766. { 0x1c, 0x212140ff }, /* dock-HP */
  2767. {}
  2768. };
  2769. /* Lemote A1004/A1205 with cxt5066 */
  2770. static const struct hda_pintbl cxt_pincfg_lemote[] = {
  2771. { 0x1a, 0x90a10020 }, /* Internal mic */
  2772. { 0x1b, 0x03a11020 }, /* External mic */
  2773. { 0x1d, 0x400101f0 }, /* Not used */
  2774. { 0x1e, 0x40a701f0 }, /* Not used */
  2775. { 0x20, 0x404501f0 }, /* Not used */
  2776. { 0x22, 0x404401f0 }, /* Not used */
  2777. { 0x23, 0x40a701f0 }, /* Not used */
  2778. {}
  2779. };
  2780. static const struct hda_fixup cxt_fixups[] = {
  2781. [CXT_PINCFG_LENOVO_X200] = {
  2782. .type = HDA_FIXUP_PINS,
  2783. .v.pins = cxt_pincfg_lenovo_x200,
  2784. },
  2785. [CXT_PINCFG_LENOVO_TP410] = {
  2786. .type = HDA_FIXUP_PINS,
  2787. .v.pins = cxt_pincfg_lenovo_tp410,
  2788. .chained = true,
  2789. .chain_id = CXT_FIXUP_THINKPAD_ACPI,
  2790. },
  2791. [CXT_PINCFG_LEMOTE_A1004] = {
  2792. .type = HDA_FIXUP_PINS,
  2793. .chained = true,
  2794. .chain_id = CXT_FIXUP_INC_MIC_BOOST,
  2795. .v.pins = cxt_pincfg_lemote,
  2796. },
  2797. [CXT_PINCFG_LEMOTE_A1205] = {
  2798. .type = HDA_FIXUP_PINS,
  2799. .v.pins = cxt_pincfg_lemote,
  2800. },
  2801. [CXT_FIXUP_STEREO_DMIC] = {
  2802. .type = HDA_FIXUP_FUNC,
  2803. .v.func = cxt_fixup_stereo_dmic,
  2804. },
  2805. [CXT_FIXUP_INC_MIC_BOOST] = {
  2806. .type = HDA_FIXUP_FUNC,
  2807. .v.func = cxt5066_increase_mic_boost,
  2808. },
  2809. [CXT_FIXUP_HEADPHONE_MIC_PIN] = {
  2810. .type = HDA_FIXUP_PINS,
  2811. .chained = true,
  2812. .chain_id = CXT_FIXUP_HEADPHONE_MIC,
  2813. .v.pins = (const struct hda_pintbl[]) {
  2814. { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
  2815. { }
  2816. }
  2817. },
  2818. [CXT_FIXUP_HEADPHONE_MIC] = {
  2819. .type = HDA_FIXUP_FUNC,
  2820. .v.func = cxt_fixup_headphone_mic,
  2821. },
  2822. [CXT_FIXUP_GPIO1] = {
  2823. .type = HDA_FIXUP_VERBS,
  2824. .v.verbs = (const struct hda_verb[]) {
  2825. { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
  2826. { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
  2827. { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
  2828. { }
  2829. },
  2830. },
  2831. [CXT_FIXUP_THINKPAD_ACPI] = {
  2832. .type = HDA_FIXUP_FUNC,
  2833. .v.func = hda_fixup_thinkpad_acpi,
  2834. },
  2835. [CXT_FIXUP_OLPC_XO] = {
  2836. .type = HDA_FIXUP_FUNC,
  2837. .v.func = cxt_fixup_olpc_xo,
  2838. },
  2839. [CXT_FIXUP_CAP_MIX_AMP] = {
  2840. .type = HDA_FIXUP_FUNC,
  2841. .v.func = cxt_fixup_cap_mix_amp,
  2842. },
  2843. [CXT_FIXUP_TOSHIBA_P105] = {
  2844. .type = HDA_FIXUP_PINS,
  2845. .v.pins = (const struct hda_pintbl[]) {
  2846. { 0x10, 0x961701f0 }, /* speaker/hp */
  2847. { 0x12, 0x02a1901e }, /* ext mic */
  2848. { 0x14, 0x95a70110 }, /* int mic */
  2849. {}
  2850. },
  2851. },
  2852. [CXT_FIXUP_HP_530] = {
  2853. .type = HDA_FIXUP_PINS,
  2854. .v.pins = (const struct hda_pintbl[]) {
  2855. { 0x12, 0x90a60160 }, /* int mic */
  2856. {}
  2857. },
  2858. .chained = true,
  2859. .chain_id = CXT_FIXUP_CAP_MIX_AMP,
  2860. },
  2861. [CXT_FIXUP_CAP_MIX_AMP_5047] = {
  2862. .type = HDA_FIXUP_FUNC,
  2863. .v.func = cxt_fixup_cap_mix_amp_5047,
  2864. },
  2865. };
  2866. static const struct snd_pci_quirk cxt5045_fixups[] = {
  2867. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
  2868. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
  2869. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  2870. * really bad sound over 0dB on NID 0x17.
  2871. */
  2872. SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
  2873. SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
  2874. SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
  2875. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
  2876. {}
  2877. };
  2878. static const struct hda_model_fixup cxt5045_fixup_models[] = {
  2879. { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
  2880. { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
  2881. { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
  2882. {}
  2883. };
  2884. static const struct snd_pci_quirk cxt5047_fixups[] = {
  2885. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  2886. */
  2887. SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
  2888. {}
  2889. };
  2890. static const struct hda_model_fixup cxt5047_fixup_models[] = {
  2891. { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
  2892. {}
  2893. };
  2894. static const struct snd_pci_quirk cxt5051_fixups[] = {
  2895. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
  2896. {}
  2897. };
  2898. static const struct hda_model_fixup cxt5051_fixup_models[] = {
  2899. { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
  2900. {}
  2901. };
  2902. static const struct snd_pci_quirk cxt5066_fixups[] = {
  2903. SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
  2904. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
  2905. SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
  2906. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
  2907. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
  2908. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
  2909. SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
  2910. SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
  2911. SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
  2912. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
  2913. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
  2914. SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
  2915. SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
  2916. SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
  2917. SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
  2918. SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
  2919. SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
  2920. {}
  2921. };
  2922. static const struct hda_model_fixup cxt5066_fixup_models[] = {
  2923. { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
  2924. { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
  2925. { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
  2926. { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
  2927. { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
  2928. { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
  2929. { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
  2930. {}
  2931. };
  2932. /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
  2933. * can be created (bko#42825)
  2934. */
  2935. static void add_cx5051_fake_mutes(struct hda_codec *codec)
  2936. {
  2937. static hda_nid_t out_nids[] = {
  2938. 0x10, 0x11, 0
  2939. };
  2940. hda_nid_t *p;
  2941. for (p = out_nids; *p; p++)
  2942. snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
  2943. AC_AMPCAP_MIN_MUTE |
  2944. query_amp_caps(codec, *p, HDA_OUTPUT));
  2945. }
  2946. static int patch_conexant_auto(struct hda_codec *codec)
  2947. {
  2948. struct conexant_spec *spec;
  2949. int err;
  2950. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  2951. codec->chip_name);
  2952. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2953. if (!spec)
  2954. return -ENOMEM;
  2955. snd_hda_gen_spec_init(&spec->gen);
  2956. codec->spec = spec;
  2957. cx_auto_parse_beep(codec);
  2958. cx_auto_parse_eapd(codec);
  2959. spec->gen.own_eapd_ctl = 1;
  2960. if (spec->dynamic_eapd)
  2961. spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
  2962. switch (codec->vendor_id) {
  2963. case 0x14f15045:
  2964. codec->single_adc_amp = 1;
  2965. spec->gen.mixer_nid = 0x17;
  2966. spec->gen.add_stereo_mix_input = 1;
  2967. snd_hda_pick_fixup(codec, cxt5045_fixup_models,
  2968. cxt5045_fixups, cxt_fixups);
  2969. break;
  2970. case 0x14f15047:
  2971. codec->pin_amp_workaround = 1;
  2972. spec->gen.mixer_nid = 0x19;
  2973. spec->gen.add_stereo_mix_input = 1;
  2974. snd_hda_pick_fixup(codec, cxt5047_fixup_models,
  2975. cxt5047_fixups, cxt_fixups);
  2976. break;
  2977. case 0x14f15051:
  2978. add_cx5051_fake_mutes(codec);
  2979. codec->pin_amp_workaround = 1;
  2980. snd_hda_pick_fixup(codec, cxt5051_fixup_models,
  2981. cxt5051_fixups, cxt_fixups);
  2982. break;
  2983. default:
  2984. codec->pin_amp_workaround = 1;
  2985. snd_hda_pick_fixup(codec, cxt5066_fixup_models,
  2986. cxt5066_fixups, cxt_fixups);
  2987. break;
  2988. }
  2989. /* Show mute-led control only on HP laptops
  2990. * This is a sort of white-list: on HP laptops, EAPD corresponds
  2991. * only to the mute-LED without actualy amp function. Meanwhile,
  2992. * others may use EAPD really as an amp switch, so it might be
  2993. * not good to expose it blindly.
  2994. */
  2995. switch (codec->subsystem_id >> 16) {
  2996. case 0x103c:
  2997. spec->gen.vmaster_mute_enum = 1;
  2998. break;
  2999. }
  3000. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  3001. err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
  3002. spec->parse_flags);
  3003. if (err < 0)
  3004. goto error;
  3005. err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
  3006. if (err < 0)
  3007. goto error;
  3008. codec->patch_ops = cx_auto_patch_ops;
  3009. /* Some laptops with Conexant chips show stalls in S3 resume,
  3010. * which falls into the single-cmd mode.
  3011. * Better to make reset, then.
  3012. */
  3013. if (!codec->bus->sync_write) {
  3014. snd_printd("hda_codec: "
  3015. "Enable sync_write for stable communication\n");
  3016. codec->bus->sync_write = 1;
  3017. codec->bus->allow_bus_reset = 1;
  3018. }
  3019. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  3020. return 0;
  3021. error:
  3022. cx_auto_free(codec);
  3023. return err;
  3024. }
  3025. #ifndef ENABLE_CXT_STATIC_QUIRKS
  3026. #define patch_cxt5045 patch_conexant_auto
  3027. #define patch_cxt5047 patch_conexant_auto
  3028. #define patch_cxt5051 patch_conexant_auto
  3029. #define patch_cxt5066 patch_conexant_auto
  3030. #endif
  3031. /*
  3032. */
  3033. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3034. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3035. .patch = patch_cxt5045 },
  3036. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  3037. .patch = patch_cxt5047 },
  3038. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  3039. .patch = patch_cxt5051 },
  3040. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  3041. .patch = patch_cxt5066 },
  3042. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  3043. .patch = patch_cxt5066 },
  3044. { .id = 0x14f15068, .name = "CX20584",
  3045. .patch = patch_cxt5066 },
  3046. { .id = 0x14f15069, .name = "CX20585",
  3047. .patch = patch_cxt5066 },
  3048. { .id = 0x14f1506c, .name = "CX20588",
  3049. .patch = patch_cxt5066 },
  3050. { .id = 0x14f1506e, .name = "CX20590",
  3051. .patch = patch_cxt5066 },
  3052. { .id = 0x14f15097, .name = "CX20631",
  3053. .patch = patch_conexant_auto },
  3054. { .id = 0x14f15098, .name = "CX20632",
  3055. .patch = patch_conexant_auto },
  3056. { .id = 0x14f150a1, .name = "CX20641",
  3057. .patch = patch_conexant_auto },
  3058. { .id = 0x14f150a2, .name = "CX20642",
  3059. .patch = patch_conexant_auto },
  3060. { .id = 0x14f150ab, .name = "CX20651",
  3061. .patch = patch_conexant_auto },
  3062. { .id = 0x14f150ac, .name = "CX20652",
  3063. .patch = patch_conexant_auto },
  3064. { .id = 0x14f150b8, .name = "CX20664",
  3065. .patch = patch_conexant_auto },
  3066. { .id = 0x14f150b9, .name = "CX20665",
  3067. .patch = patch_conexant_auto },
  3068. { .id = 0x14f1510f, .name = "CX20751/2",
  3069. .patch = patch_conexant_auto },
  3070. { .id = 0x14f15110, .name = "CX20751/2",
  3071. .patch = patch_conexant_auto },
  3072. { .id = 0x14f15111, .name = "CX20753/4",
  3073. .patch = patch_conexant_auto },
  3074. { .id = 0x14f15113, .name = "CX20755",
  3075. .patch = patch_conexant_auto },
  3076. { .id = 0x14f15114, .name = "CX20756",
  3077. .patch = patch_conexant_auto },
  3078. { .id = 0x14f15115, .name = "CX20757",
  3079. .patch = patch_conexant_auto },
  3080. { .id = 0x14f151d7, .name = "CX20952",
  3081. .patch = patch_conexant_auto },
  3082. {} /* terminator */
  3083. };
  3084. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  3085. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  3086. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  3087. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  3088. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  3089. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  3090. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  3091. MODULE_ALIAS("snd-hda-codec-id:14f1506c");
  3092. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  3093. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  3094. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  3095. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  3096. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  3097. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  3098. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  3099. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  3100. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  3101. MODULE_ALIAS("snd-hda-codec-id:14f1510f");
  3102. MODULE_ALIAS("snd-hda-codec-id:14f15110");
  3103. MODULE_ALIAS("snd-hda-codec-id:14f15111");
  3104. MODULE_ALIAS("snd-hda-codec-id:14f15113");
  3105. MODULE_ALIAS("snd-hda-codec-id:14f15114");
  3106. MODULE_ALIAS("snd-hda-codec-id:14f15115");
  3107. MODULE_ALIAS("snd-hda-codec-id:14f151d7");
  3108. MODULE_LICENSE("GPL");
  3109. MODULE_DESCRIPTION("Conexant HD-audio codec");
  3110. static struct hda_codec_preset_list conexant_list = {
  3111. .preset = snd_hda_preset_conexant,
  3112. .owner = THIS_MODULE,
  3113. };
  3114. static int __init patch_conexant_init(void)
  3115. {
  3116. return snd_hda_add_codec_preset(&conexant_list);
  3117. }
  3118. static void __exit patch_conexant_exit(void)
  3119. {
  3120. snd_hda_delete_codec_preset(&conexant_list);
  3121. }
  3122. module_init(patch_conexant_init)
  3123. module_exit(patch_conexant_exit)