patch_conexant.c 85 KB

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