patch_conexant.c 99 KB

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