patch_conexant.c 97 KB

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