patch_conexant.c 75 KB

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