patch_conexant.c 84 KB

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