patch_conexant.c 105 KB

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