patch_conexant.c 89 KB

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