patch_conexant.c 72 KB

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