patch_conexant.c 105 KB

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