patch_conexant.c 97 KB

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