patch_conexant.c 75 KB

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