patch_conexant.c 107 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596
  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/module.h>
  26. #include <sound/core.h>
  27. #include <sound/jack.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #include "hda_auto_parser.h"
  31. #include "hda_beep.h"
  32. #include "hda_jack.h"
  33. #include "hda_generic.h"
  34. #undef ENABLE_CXT_STATIC_QUIRKS
  35. #define CXT_PIN_DIR_IN 0x00
  36. #define CXT_PIN_DIR_OUT 0x01
  37. #define CXT_PIN_DIR_INOUT 0x02
  38. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  39. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  40. #define CONEXANT_HP_EVENT 0x37
  41. #define CONEXANT_MIC_EVENT 0x38
  42. #define CONEXANT_LINE_EVENT 0x39
  43. /* Conexant 5051 specific */
  44. #define CXT5051_SPDIF_OUT 0x12
  45. #define CXT5051_PORTB_EVENT 0x38
  46. #define CXT5051_PORTC_EVENT 0x39
  47. #define AUTO_MIC_PORTB (1 << 1)
  48. #define AUTO_MIC_PORTC (1 << 2)
  49. struct conexant_spec {
  50. struct hda_gen_spec gen;
  51. unsigned int beep_amp;
  52. /* extra EAPD pins */
  53. unsigned int num_eapds;
  54. hda_nid_t eapds[4];
  55. bool dynamic_eapd;
  56. unsigned int parse_flags; /* flag for snd_hda_parse_pin_defcfg() */
  57. /* OPLC XO specific */
  58. bool recording;
  59. bool dc_enable;
  60. unsigned int dc_input_bias; /* offset into olpc_xo_dc_bias */
  61. struct nid_path *dc_mode_path;
  62. #ifdef ENABLE_CXT_STATIC_QUIRKS
  63. const struct snd_kcontrol_new *mixers[5];
  64. int num_mixers;
  65. hda_nid_t vmaster_nid;
  66. const struct hda_verb *init_verbs[5]; /* initialization verbs
  67. * don't forget NULL
  68. * termination!
  69. */
  70. unsigned int num_init_verbs;
  71. /* playback */
  72. struct hda_multi_out multiout; /* playback set-up
  73. * max_channels, dacs must be set
  74. * dig_out_nid and hp_nid are optional
  75. */
  76. unsigned int cur_eapd;
  77. unsigned int hp_present;
  78. unsigned int line_present;
  79. unsigned int auto_mic;
  80. /* capture */
  81. unsigned int num_adc_nids;
  82. const hda_nid_t *adc_nids;
  83. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  84. unsigned int cur_adc_idx;
  85. hda_nid_t cur_adc;
  86. unsigned int cur_adc_stream_tag;
  87. unsigned int cur_adc_format;
  88. const struct hda_pcm_stream *capture_stream;
  89. /* capture source */
  90. const struct hda_input_mux *input_mux;
  91. const hda_nid_t *capsrc_nids;
  92. unsigned int cur_mux[3];
  93. /* channel model */
  94. const struct hda_channel_mode *channel_mode;
  95. int num_channel_mode;
  96. /* PCM information */
  97. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  98. unsigned int spdif_route;
  99. unsigned int port_d_mode;
  100. unsigned int dell_automute:1;
  101. unsigned int dell_vostro:1;
  102. unsigned int ideapad:1;
  103. unsigned int thinkpad:1;
  104. unsigned int hp_laptop:1;
  105. unsigned int asus:1;
  106. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  107. #endif /* ENABLE_CXT_STATIC_QUIRKS */
  108. };
  109. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  110. static inline void set_beep_amp(struct conexant_spec *spec, hda_nid_t nid,
  111. int idx, int dir)
  112. {
  113. spec->gen.beep_nid = nid;
  114. spec->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir);
  115. }
  116. /* additional beep mixers; the actual parameters are overwritten at build */
  117. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  118. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  119. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  120. { } /* end */
  121. };
  122. /* create beep controls if needed */
  123. static int add_beep_ctls(struct hda_codec *codec)
  124. {
  125. struct conexant_spec *spec = codec->spec;
  126. int err;
  127. if (spec->beep_amp) {
  128. const struct snd_kcontrol_new *knew;
  129. for (knew = cxt_beep_mixer; knew->name; knew++) {
  130. struct snd_kcontrol *kctl;
  131. kctl = snd_ctl_new1(knew, codec);
  132. if (!kctl)
  133. return -ENOMEM;
  134. kctl->private_value = spec->beep_amp;
  135. err = snd_hda_ctl_add(codec, 0, kctl);
  136. if (err < 0)
  137. return err;
  138. }
  139. }
  140. return 0;
  141. }
  142. #else
  143. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  144. #define add_beep_ctls(codec) 0
  145. #endif
  146. #ifdef ENABLE_CXT_STATIC_QUIRKS
  147. static int conexant_playback_pcm_open(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_analog_open(codec, &spec->multiout, substream,
  153. hinfo);
  154. }
  155. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  156. struct hda_codec *codec,
  157. unsigned int stream_tag,
  158. unsigned int format,
  159. struct snd_pcm_substream *substream)
  160. {
  161. struct conexant_spec *spec = codec->spec;
  162. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  163. stream_tag,
  164. format, substream);
  165. }
  166. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  167. struct hda_codec *codec,
  168. struct snd_pcm_substream *substream)
  169. {
  170. struct conexant_spec *spec = codec->spec;
  171. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  172. }
  173. /*
  174. * Digital out
  175. */
  176. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  177. struct hda_codec *codec,
  178. struct snd_pcm_substream *substream)
  179. {
  180. struct conexant_spec *spec = codec->spec;
  181. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  182. }
  183. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  184. struct hda_codec *codec,
  185. struct snd_pcm_substream *substream)
  186. {
  187. struct conexant_spec *spec = codec->spec;
  188. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  189. }
  190. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  191. struct hda_codec *codec,
  192. unsigned int stream_tag,
  193. unsigned int format,
  194. struct snd_pcm_substream *substream)
  195. {
  196. struct conexant_spec *spec = codec->spec;
  197. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  198. stream_tag,
  199. format, substream);
  200. }
  201. /*
  202. * Analog capture
  203. */
  204. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  205. struct hda_codec *codec,
  206. unsigned int stream_tag,
  207. unsigned int format,
  208. struct snd_pcm_substream *substream)
  209. {
  210. struct conexant_spec *spec = codec->spec;
  211. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  212. stream_tag, 0, format);
  213. return 0;
  214. }
  215. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  216. struct hda_codec *codec,
  217. struct snd_pcm_substream *substream)
  218. {
  219. struct conexant_spec *spec = codec->spec;
  220. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  221. return 0;
  222. }
  223. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  224. .substreams = 1,
  225. .channels_min = 2,
  226. .channels_max = 2,
  227. .nid = 0, /* fill later */
  228. .ops = {
  229. .open = conexant_playback_pcm_open,
  230. .prepare = conexant_playback_pcm_prepare,
  231. .cleanup = conexant_playback_pcm_cleanup
  232. },
  233. };
  234. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  235. .substreams = 1,
  236. .channels_min = 2,
  237. .channels_max = 2,
  238. .nid = 0, /* fill later */
  239. .ops = {
  240. .prepare = conexant_capture_pcm_prepare,
  241. .cleanup = conexant_capture_pcm_cleanup
  242. },
  243. };
  244. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  245. .substreams = 1,
  246. .channels_min = 2,
  247. .channels_max = 2,
  248. .nid = 0, /* fill later */
  249. .ops = {
  250. .open = conexant_dig_playback_pcm_open,
  251. .close = conexant_dig_playback_pcm_close,
  252. .prepare = conexant_dig_playback_pcm_prepare
  253. },
  254. };
  255. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  256. .substreams = 1,
  257. .channels_min = 2,
  258. .channels_max = 2,
  259. /* NID is set in alc_build_pcms */
  260. };
  261. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  262. struct hda_codec *codec,
  263. unsigned int stream_tag,
  264. unsigned int format,
  265. struct snd_pcm_substream *substream)
  266. {
  267. struct conexant_spec *spec = codec->spec;
  268. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  269. spec->cur_adc_stream_tag = stream_tag;
  270. spec->cur_adc_format = format;
  271. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  272. return 0;
  273. }
  274. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  275. struct hda_codec *codec,
  276. struct snd_pcm_substream *substream)
  277. {
  278. struct conexant_spec *spec = codec->spec;
  279. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  280. spec->cur_adc = 0;
  281. return 0;
  282. }
  283. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  284. .substreams = 1,
  285. .channels_min = 2,
  286. .channels_max = 2,
  287. .nid = 0, /* fill later */
  288. .ops = {
  289. .prepare = cx5051_capture_pcm_prepare,
  290. .cleanup = cx5051_capture_pcm_cleanup
  291. },
  292. };
  293. static int conexant_build_pcms(struct hda_codec *codec)
  294. {
  295. struct conexant_spec *spec = codec->spec;
  296. struct hda_pcm *info = spec->pcm_rec;
  297. codec->num_pcms = 1;
  298. codec->pcm_info = info;
  299. info->name = "CONEXANT Analog";
  300. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  301. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  302. spec->multiout.max_channels;
  303. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  304. spec->multiout.dac_nids[0];
  305. if (spec->capture_stream)
  306. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  307. else {
  308. if (codec->vendor_id == 0x14f15051)
  309. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  310. cx5051_pcm_analog_capture;
  311. else {
  312. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  313. conexant_pcm_analog_capture;
  314. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  315. spec->num_adc_nids;
  316. }
  317. }
  318. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  319. if (spec->multiout.dig_out_nid) {
  320. info++;
  321. codec->num_pcms++;
  322. info->name = "Conexant Digital";
  323. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  324. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  325. conexant_pcm_digital_playback;
  326. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  327. spec->multiout.dig_out_nid;
  328. if (spec->dig_in_nid) {
  329. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  330. conexant_pcm_digital_capture;
  331. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  332. spec->dig_in_nid;
  333. }
  334. }
  335. return 0;
  336. }
  337. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  338. struct snd_ctl_elem_info *uinfo)
  339. {
  340. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  341. struct conexant_spec *spec = codec->spec;
  342. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  343. }
  344. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  345. struct snd_ctl_elem_value *ucontrol)
  346. {
  347. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  348. struct conexant_spec *spec = codec->spec;
  349. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  350. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  351. return 0;
  352. }
  353. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  354. struct snd_ctl_elem_value *ucontrol)
  355. {
  356. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  357. struct conexant_spec *spec = codec->spec;
  358. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  359. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  360. spec->capsrc_nids[adc_idx],
  361. &spec->cur_mux[adc_idx]);
  362. }
  363. static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
  364. unsigned int power_state)
  365. {
  366. if (power_state == AC_PWRST_D3)
  367. msleep(100);
  368. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
  369. power_state);
  370. /* partial workaround for "azx_get_response timeout" */
  371. if (power_state == AC_PWRST_D0)
  372. msleep(10);
  373. snd_hda_codec_set_power_to_all(codec, fg, power_state);
  374. }
  375. static int conexant_init(struct hda_codec *codec)
  376. {
  377. struct conexant_spec *spec = codec->spec;
  378. int i;
  379. for (i = 0; i < spec->num_init_verbs; i++)
  380. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  381. return 0;
  382. }
  383. static void conexant_free(struct hda_codec *codec)
  384. {
  385. kfree(codec->spec);
  386. }
  387. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  388. {
  389. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  390. .name = "Capture Source",
  391. .info = conexant_mux_enum_info,
  392. .get = conexant_mux_enum_get,
  393. .put = conexant_mux_enum_put
  394. },
  395. {}
  396. };
  397. static const char * const slave_pfxs[] = {
  398. "Headphone", "Speaker", "Bass Speaker", "Front", "Surround", "CLFE",
  399. NULL
  400. };
  401. static int conexant_build_controls(struct hda_codec *codec)
  402. {
  403. struct conexant_spec *spec = codec->spec;
  404. unsigned int i;
  405. int err;
  406. for (i = 0; i < spec->num_mixers; i++) {
  407. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  408. if (err < 0)
  409. return err;
  410. }
  411. if (spec->multiout.dig_out_nid) {
  412. err = snd_hda_create_spdif_out_ctls(codec,
  413. spec->multiout.dig_out_nid,
  414. spec->multiout.dig_out_nid);
  415. if (err < 0)
  416. return err;
  417. err = snd_hda_create_spdif_share_sw(codec,
  418. &spec->multiout);
  419. if (err < 0)
  420. return err;
  421. spec->multiout.share_spdif = 1;
  422. }
  423. if (spec->dig_in_nid) {
  424. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  425. if (err < 0)
  426. return err;
  427. }
  428. /* if we have no master control, let's create it */
  429. if (spec->vmaster_nid &&
  430. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  431. unsigned int vmaster_tlv[4];
  432. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  433. HDA_OUTPUT, vmaster_tlv);
  434. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  435. vmaster_tlv, slave_pfxs,
  436. "Playback Volume");
  437. if (err < 0)
  438. return err;
  439. }
  440. if (spec->vmaster_nid &&
  441. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  442. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  443. NULL, slave_pfxs,
  444. "Playback Switch");
  445. if (err < 0)
  446. return err;
  447. }
  448. if (spec->input_mux) {
  449. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  450. if (err < 0)
  451. return err;
  452. }
  453. err = add_beep_ctls(codec);
  454. if (err < 0)
  455. return err;
  456. return 0;
  457. }
  458. static const struct hda_codec_ops conexant_patch_ops = {
  459. .build_controls = conexant_build_controls,
  460. .build_pcms = conexant_build_pcms,
  461. .init = conexant_init,
  462. .free = conexant_free,
  463. .set_power_state = conexant_set_power,
  464. };
  465. static int patch_conexant_auto(struct hda_codec *codec);
  466. /*
  467. * EAPD control
  468. * the private value = nid | (invert << 8)
  469. */
  470. #define cxt_eapd_info snd_ctl_boolean_mono_info
  471. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  472. struct snd_ctl_elem_value *ucontrol)
  473. {
  474. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  475. struct conexant_spec *spec = codec->spec;
  476. int invert = (kcontrol->private_value >> 8) & 1;
  477. if (invert)
  478. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  479. else
  480. ucontrol->value.integer.value[0] = spec->cur_eapd;
  481. return 0;
  482. }
  483. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  484. struct snd_ctl_elem_value *ucontrol)
  485. {
  486. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  487. struct conexant_spec *spec = codec->spec;
  488. int invert = (kcontrol->private_value >> 8) & 1;
  489. hda_nid_t nid = kcontrol->private_value & 0xff;
  490. unsigned int eapd;
  491. eapd = !!ucontrol->value.integer.value[0];
  492. if (invert)
  493. eapd = !eapd;
  494. if (eapd == spec->cur_eapd)
  495. return 0;
  496. spec->cur_eapd = eapd;
  497. snd_hda_codec_write_cache(codec, nid,
  498. 0, AC_VERB_SET_EAPD_BTLENABLE,
  499. eapd ? 0x02 : 0x00);
  500. return 1;
  501. }
  502. /* controls for test mode */
  503. #ifdef CONFIG_SND_DEBUG
  504. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  505. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  506. .info = cxt_eapd_info, \
  507. .get = cxt_eapd_get, \
  508. .put = cxt_eapd_put, \
  509. .private_value = nid | (mask<<16) }
  510. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  511. struct snd_ctl_elem_info *uinfo)
  512. {
  513. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  514. struct conexant_spec *spec = codec->spec;
  515. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  516. spec->num_channel_mode);
  517. }
  518. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  519. struct snd_ctl_elem_value *ucontrol)
  520. {
  521. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  522. struct conexant_spec *spec = codec->spec;
  523. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  524. spec->num_channel_mode,
  525. spec->multiout.max_channels);
  526. }
  527. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  528. struct snd_ctl_elem_value *ucontrol)
  529. {
  530. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  531. struct conexant_spec *spec = codec->spec;
  532. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  533. spec->num_channel_mode,
  534. &spec->multiout.max_channels);
  535. return err;
  536. }
  537. #define CXT_PIN_MODE(xname, nid, dir) \
  538. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  539. .info = conexant_ch_mode_info, \
  540. .get = conexant_ch_mode_get, \
  541. .put = conexant_ch_mode_put, \
  542. .private_value = nid | (dir<<16) }
  543. #endif /* CONFIG_SND_DEBUG */
  544. /* Conexant 5045 specific */
  545. static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  546. static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  547. static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  548. #define CXT5045_SPDIF_OUT 0x18
  549. static const struct hda_channel_mode cxt5045_modes[1] = {
  550. { 2, NULL },
  551. };
  552. static const struct hda_input_mux cxt5045_capture_source = {
  553. .num_items = 2,
  554. .items = {
  555. { "Internal Mic", 0x1 },
  556. { "Mic", 0x2 },
  557. }
  558. };
  559. static const struct hda_input_mux cxt5045_capture_source_benq = {
  560. .num_items = 4,
  561. .items = {
  562. { "Internal Mic", 0x1 },
  563. { "Mic", 0x2 },
  564. { "Line", 0x3 },
  565. { "Mixer", 0x0 },
  566. }
  567. };
  568. /* turn on/off EAPD (+ mute HP) as a master switch */
  569. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  570. struct snd_ctl_elem_value *ucontrol)
  571. {
  572. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  573. struct conexant_spec *spec = codec->spec;
  574. unsigned int bits;
  575. if (!cxt_eapd_put(kcontrol, ucontrol))
  576. return 0;
  577. /* toggle internal speakers mute depending of presence of
  578. * the headphone jack
  579. */
  580. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  581. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  582. HDA_AMP_MUTE, bits);
  583. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  584. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  585. HDA_AMP_MUTE, bits);
  586. return 1;
  587. }
  588. /* bind volumes of both NID 0x10 and 0x11 */
  589. static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  590. .ops = &snd_hda_bind_vol,
  591. .values = {
  592. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  593. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  594. 0
  595. },
  596. };
  597. /* toggle input of built-in and mic jack appropriately */
  598. static void cxt5045_hp_automic(struct hda_codec *codec)
  599. {
  600. static const struct hda_verb mic_jack_on[] = {
  601. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  602. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  603. {}
  604. };
  605. static const struct hda_verb mic_jack_off[] = {
  606. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  607. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  608. {}
  609. };
  610. unsigned int present;
  611. present = snd_hda_jack_detect(codec, 0x12);
  612. if (present)
  613. snd_hda_sequence_write(codec, mic_jack_on);
  614. else
  615. snd_hda_sequence_write(codec, mic_jack_off);
  616. }
  617. /* mute internal speaker if HP is plugged */
  618. static void cxt5045_hp_automute(struct hda_codec *codec)
  619. {
  620. struct conexant_spec *spec = codec->spec;
  621. unsigned int bits;
  622. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  623. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  624. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  625. HDA_AMP_MUTE, bits);
  626. }
  627. /* unsolicited event for HP jack sensing */
  628. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  629. unsigned int res)
  630. {
  631. res >>= 26;
  632. switch (res) {
  633. case CONEXANT_HP_EVENT:
  634. cxt5045_hp_automute(codec);
  635. break;
  636. case CONEXANT_MIC_EVENT:
  637. cxt5045_hp_automic(codec);
  638. break;
  639. }
  640. }
  641. static const struct snd_kcontrol_new cxt5045_mixers[] = {
  642. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x00, HDA_INPUT),
  643. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  644. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  645. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  646. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  647. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  648. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  649. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  650. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  651. {
  652. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  653. .name = "Master Playback Switch",
  654. .info = cxt_eapd_info,
  655. .get = cxt_eapd_get,
  656. .put = cxt5045_hp_master_sw_put,
  657. .private_value = 0x10,
  658. },
  659. {}
  660. };
  661. static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  662. HDA_CODEC_VOLUME("Line Playback Volume", 0x17, 0x3, HDA_INPUT),
  663. HDA_CODEC_MUTE("Line Playback Switch", 0x17, 0x3, HDA_INPUT),
  664. {}
  665. };
  666. static const struct hda_verb cxt5045_init_verbs[] = {
  667. /* Line in, Mic */
  668. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  669. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  670. /* HP, Amp */
  671. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  672. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  673. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  674. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  675. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  676. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  677. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  678. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  679. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  680. /* Record selector: Internal mic */
  681. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  682. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  683. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  684. /* SPDIF route: PCM */
  685. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  686. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  687. /* EAPD */
  688. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  689. { } /* end */
  690. };
  691. static const struct hda_verb cxt5045_benq_init_verbs[] = {
  692. /* Internal Mic, Mic */
  693. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  694. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  695. /* Line In,HP, Amp */
  696. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  697. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  698. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  699. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  700. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  701. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  702. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  703. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  704. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  705. /* Record selector: Internal mic */
  706. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  707. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  708. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  709. /* SPDIF route: PCM */
  710. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  711. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  712. /* EAPD */
  713. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  714. { } /* end */
  715. };
  716. static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  717. /* pin sensing on HP jack */
  718. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  719. { } /* end */
  720. };
  721. static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  722. /* pin sensing on HP jack */
  723. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  724. { } /* end */
  725. };
  726. #ifdef CONFIG_SND_DEBUG
  727. /* Test configuration for debugging, modelled after the ALC260 test
  728. * configuration.
  729. */
  730. static const struct hda_input_mux cxt5045_test_capture_source = {
  731. .num_items = 5,
  732. .items = {
  733. { "MIXER", 0x0 },
  734. { "MIC1 pin", 0x1 },
  735. { "LINE1 pin", 0x2 },
  736. { "HP-OUT pin", 0x3 },
  737. { "CD pin", 0x4 },
  738. },
  739. };
  740. static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
  741. /* Output controls */
  742. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  743. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  744. HDA_CODEC_VOLUME("HP-OUT Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  745. HDA_CODEC_MUTE("HP-OUT Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  746. HDA_CODEC_VOLUME("LINE1 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  747. HDA_CODEC_MUTE("LINE1 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  748. /* Modes for retasking pin widgets */
  749. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  750. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  751. /* EAPD Switch Control */
  752. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  753. /* Loopback mixer controls */
  754. HDA_CODEC_VOLUME("PCM Volume", 0x17, 0x0, HDA_INPUT),
  755. HDA_CODEC_MUTE("PCM Switch", 0x17, 0x0, HDA_INPUT),
  756. HDA_CODEC_VOLUME("MIC1 pin Volume", 0x17, 0x1, HDA_INPUT),
  757. HDA_CODEC_MUTE("MIC1 pin Switch", 0x17, 0x1, HDA_INPUT),
  758. HDA_CODEC_VOLUME("LINE1 pin Volume", 0x17, 0x2, HDA_INPUT),
  759. HDA_CODEC_MUTE("LINE1 pin Switch", 0x17, 0x2, HDA_INPUT),
  760. HDA_CODEC_VOLUME("HP-OUT pin Volume", 0x17, 0x3, HDA_INPUT),
  761. HDA_CODEC_MUTE("HP-OUT pin Switch", 0x17, 0x3, HDA_INPUT),
  762. HDA_CODEC_VOLUME("CD pin Volume", 0x17, 0x4, HDA_INPUT),
  763. HDA_CODEC_MUTE("CD pin Switch", 0x17, 0x4, HDA_INPUT),
  764. {
  765. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  766. .name = "Input Source",
  767. .info = conexant_mux_enum_info,
  768. .get = conexant_mux_enum_get,
  769. .put = conexant_mux_enum_put,
  770. },
  771. /* Audio input controls */
  772. HDA_CODEC_VOLUME("Capture Volume", 0x1a, 0x0, HDA_INPUT),
  773. HDA_CODEC_MUTE("Capture Switch", 0x1a, 0x0, HDA_INPUT),
  774. { } /* end */
  775. };
  776. static const struct hda_verb cxt5045_test_init_verbs[] = {
  777. /* Set connections */
  778. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  779. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  780. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  781. /* Enable retasking pins as output, initially without power amp */
  782. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  783. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  784. /* Disable digital (SPDIF) pins initially, but users can enable
  785. * them via a mixer switch. In the case of SPDIF-out, this initverb
  786. * payload also sets the generation to 0, output to be in "consumer"
  787. * PCM format, copyright asserted, no pre-emphasis and no validity
  788. * control.
  789. */
  790. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  791. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  792. /* Unmute retasking pin widget output buffers since the default
  793. * state appears to be output. As the pin mode is changed by the
  794. * user the pin mode control will take care of enabling the pin's
  795. * input/output buffers as needed.
  796. */
  797. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  798. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  799. /* Mute capture amp left and right */
  800. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  801. /* Set ADC connection select to match default mixer setting (mic1
  802. * pin)
  803. */
  804. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
  805. {0x17, AC_VERB_SET_CONNECT_SEL, 0x01},
  806. /* Mute all inputs to mixer widget (even unconnected ones) */
  807. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer */
  808. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  809. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  810. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  811. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  812. { }
  813. };
  814. #endif
  815. /* initialize jack-sensing, too */
  816. static int cxt5045_init(struct hda_codec *codec)
  817. {
  818. conexant_init(codec);
  819. cxt5045_hp_automute(codec);
  820. return 0;
  821. }
  822. enum {
  823. CXT5045_LAPTOP_HPSENSE,
  824. CXT5045_LAPTOP_MICSENSE,
  825. CXT5045_LAPTOP_HPMICSENSE,
  826. CXT5045_BENQ,
  827. #ifdef CONFIG_SND_DEBUG
  828. CXT5045_TEST,
  829. #endif
  830. CXT5045_AUTO,
  831. CXT5045_MODELS
  832. };
  833. static const char * const cxt5045_models[CXT5045_MODELS] = {
  834. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  835. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  836. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  837. [CXT5045_BENQ] = "benq",
  838. #ifdef CONFIG_SND_DEBUG
  839. [CXT5045_TEST] = "test",
  840. #endif
  841. [CXT5045_AUTO] = "auto",
  842. };
  843. static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  844. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  845. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  846. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  847. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  848. CXT5045_LAPTOP_HPMICSENSE),
  849. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  850. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  851. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  852. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  853. CXT5045_LAPTOP_HPMICSENSE),
  854. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  855. {}
  856. };
  857. static int patch_cxt5045(struct hda_codec *codec)
  858. {
  859. struct conexant_spec *spec;
  860. int board_config;
  861. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  862. cxt5045_models,
  863. cxt5045_cfg_tbl);
  864. if (board_config < 0)
  865. board_config = CXT5045_AUTO; /* model=auto as default */
  866. if (board_config == CXT5045_AUTO)
  867. return patch_conexant_auto(codec);
  868. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  869. if (!spec)
  870. return -ENOMEM;
  871. codec->spec = spec;
  872. codec->single_adc_amp = 1;
  873. spec->multiout.max_channels = 2;
  874. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  875. spec->multiout.dac_nids = cxt5045_dac_nids;
  876. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  877. spec->num_adc_nids = 1;
  878. spec->adc_nids = cxt5045_adc_nids;
  879. spec->capsrc_nids = cxt5045_capsrc_nids;
  880. spec->input_mux = &cxt5045_capture_source;
  881. spec->num_mixers = 1;
  882. spec->mixers[0] = cxt5045_mixers;
  883. spec->num_init_verbs = 1;
  884. spec->init_verbs[0] = cxt5045_init_verbs;
  885. spec->spdif_route = 0;
  886. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
  887. spec->channel_mode = cxt5045_modes;
  888. set_beep_amp(spec, 0x16, 0, 1);
  889. codec->patch_ops = conexant_patch_ops;
  890. switch (board_config) {
  891. case CXT5045_LAPTOP_HPSENSE:
  892. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  893. spec->input_mux = &cxt5045_capture_source;
  894. spec->num_init_verbs = 2;
  895. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  896. spec->mixers[0] = cxt5045_mixers;
  897. codec->patch_ops.init = cxt5045_init;
  898. break;
  899. case CXT5045_LAPTOP_MICSENSE:
  900. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  901. spec->input_mux = &cxt5045_capture_source;
  902. spec->num_init_verbs = 2;
  903. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  904. spec->mixers[0] = cxt5045_mixers;
  905. codec->patch_ops.init = cxt5045_init;
  906. break;
  907. default:
  908. case CXT5045_LAPTOP_HPMICSENSE:
  909. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  910. spec->input_mux = &cxt5045_capture_source;
  911. spec->num_init_verbs = 3;
  912. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  913. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  914. spec->mixers[0] = cxt5045_mixers;
  915. codec->patch_ops.init = cxt5045_init;
  916. break;
  917. case CXT5045_BENQ:
  918. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  919. spec->input_mux = &cxt5045_capture_source_benq;
  920. spec->num_init_verbs = 1;
  921. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  922. spec->mixers[0] = cxt5045_mixers;
  923. spec->mixers[1] = cxt5045_benq_mixers;
  924. spec->num_mixers = 2;
  925. codec->patch_ops.init = cxt5045_init;
  926. break;
  927. #ifdef CONFIG_SND_DEBUG
  928. case CXT5045_TEST:
  929. spec->input_mux = &cxt5045_test_capture_source;
  930. spec->mixers[0] = cxt5045_test_mixer;
  931. spec->init_verbs[0] = cxt5045_test_init_verbs;
  932. break;
  933. #endif
  934. }
  935. switch (codec->subsystem_id >> 16) {
  936. case 0x103c:
  937. case 0x1631:
  938. case 0x1734:
  939. case 0x17aa:
  940. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  941. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  942. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  943. */
  944. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  945. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  946. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  947. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  948. (1 << AC_AMPCAP_MUTE_SHIFT));
  949. break;
  950. }
  951. if (spec->beep_amp)
  952. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  953. return 0;
  954. }
  955. /* Conexant 5047 specific */
  956. #define CXT5047_SPDIF_OUT 0x11
  957. static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  958. static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  959. static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  960. static const struct hda_channel_mode cxt5047_modes[1] = {
  961. { 2, NULL },
  962. };
  963. static const struct hda_input_mux cxt5047_toshiba_capture_source = {
  964. .num_items = 2,
  965. .items = {
  966. { "ExtMic", 0x2 },
  967. { "Line-In", 0x1 },
  968. }
  969. };
  970. /* turn on/off EAPD (+ mute HP) as a master switch */
  971. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  972. struct snd_ctl_elem_value *ucontrol)
  973. {
  974. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  975. struct conexant_spec *spec = codec->spec;
  976. unsigned int bits;
  977. if (!cxt_eapd_put(kcontrol, ucontrol))
  978. return 0;
  979. /* toggle internal speakers mute depending of presence of
  980. * the headphone jack
  981. */
  982. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  983. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  984. * pin widgets unlike other codecs. In this case, we need to
  985. * set index 0x01 for the volume from the mixer amp 0x19.
  986. */
  987. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  988. HDA_AMP_MUTE, bits);
  989. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  990. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  991. HDA_AMP_MUTE, bits);
  992. return 1;
  993. }
  994. /* mute internal speaker if HP is plugged */
  995. static void cxt5047_hp_automute(struct hda_codec *codec)
  996. {
  997. struct conexant_spec *spec = codec->spec;
  998. unsigned int bits;
  999. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1000. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1001. /* See the note in cxt5047_hp_master_sw_put */
  1002. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1003. HDA_AMP_MUTE, bits);
  1004. }
  1005. /* toggle input of built-in and mic jack appropriately */
  1006. static void cxt5047_hp_automic(struct hda_codec *codec)
  1007. {
  1008. static const struct hda_verb mic_jack_on[] = {
  1009. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1010. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1011. {}
  1012. };
  1013. static const struct hda_verb mic_jack_off[] = {
  1014. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1015. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1016. {}
  1017. };
  1018. unsigned int present;
  1019. present = snd_hda_jack_detect(codec, 0x15);
  1020. if (present)
  1021. snd_hda_sequence_write(codec, mic_jack_on);
  1022. else
  1023. snd_hda_sequence_write(codec, mic_jack_off);
  1024. }
  1025. /* unsolicited event for HP jack sensing */
  1026. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1027. unsigned int res)
  1028. {
  1029. switch (res >> 26) {
  1030. case CONEXANT_HP_EVENT:
  1031. cxt5047_hp_automute(codec);
  1032. break;
  1033. case CONEXANT_MIC_EVENT:
  1034. cxt5047_hp_automic(codec);
  1035. break;
  1036. }
  1037. }
  1038. static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1039. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1040. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1041. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1042. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1043. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1044. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1045. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1046. {
  1047. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1048. .name = "Master Playback Switch",
  1049. .info = cxt_eapd_info,
  1050. .get = cxt_eapd_get,
  1051. .put = cxt5047_hp_master_sw_put,
  1052. .private_value = 0x13,
  1053. },
  1054. {}
  1055. };
  1056. static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1057. /* See the note in cxt5047_hp_master_sw_put */
  1058. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1059. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1060. {}
  1061. };
  1062. static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1063. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1064. { } /* end */
  1065. };
  1066. static const struct hda_verb cxt5047_init_verbs[] = {
  1067. /* Line in, Mic, Built-in Mic */
  1068. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1069. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1070. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1071. /* HP, Speaker */
  1072. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1073. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1074. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1075. /* Record selector: Mic */
  1076. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1077. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1078. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1079. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1080. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1081. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1082. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1083. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1084. /* SPDIF route: PCM */
  1085. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1086. /* Enable unsolicited events */
  1087. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1088. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1089. { } /* end */
  1090. };
  1091. /* configuration for Toshiba Laptops */
  1092. static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1093. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1094. {}
  1095. };
  1096. /* Test configuration for debugging, modelled after the ALC260 test
  1097. * configuration.
  1098. */
  1099. #ifdef CONFIG_SND_DEBUG
  1100. static const struct hda_input_mux cxt5047_test_capture_source = {
  1101. .num_items = 4,
  1102. .items = {
  1103. { "LINE1 pin", 0x0 },
  1104. { "MIC1 pin", 0x1 },
  1105. { "MIC2 pin", 0x2 },
  1106. { "CD pin", 0x3 },
  1107. },
  1108. };
  1109. static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1110. /* Output only controls */
  1111. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1112. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1113. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1114. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1115. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1116. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1117. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1118. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1119. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1120. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1121. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1122. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1123. /* Modes for retasking pin widgets */
  1124. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1125. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1126. /* EAPD Switch Control */
  1127. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1128. /* Loopback mixer controls */
  1129. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1130. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1131. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1132. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1133. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1134. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1135. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1136. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1137. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1138. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1139. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1140. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1141. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1142. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1143. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1144. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1145. {
  1146. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1147. .name = "Input Source",
  1148. .info = conexant_mux_enum_info,
  1149. .get = conexant_mux_enum_get,
  1150. .put = conexant_mux_enum_put,
  1151. },
  1152. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1153. { } /* end */
  1154. };
  1155. static const struct hda_verb cxt5047_test_init_verbs[] = {
  1156. /* Enable retasking pins as output, initially without power amp */
  1157. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1158. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1159. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1160. /* Disable digital (SPDIF) pins initially, but users can enable
  1161. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1162. * payload also sets the generation to 0, output to be in "consumer"
  1163. * PCM format, copyright asserted, no pre-emphasis and no validity
  1164. * control.
  1165. */
  1166. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1167. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1168. * OUT1 sum bus when acting as an output.
  1169. */
  1170. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1171. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1172. /* Start with output sum widgets muted and their output gains at min */
  1173. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1174. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1175. /* Unmute retasking pin widget output buffers since the default
  1176. * state appears to be output. As the pin mode is changed by the
  1177. * user the pin mode control will take care of enabling the pin's
  1178. * input/output buffers as needed.
  1179. */
  1180. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1181. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1182. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1183. /* Mute capture amp left and right */
  1184. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1185. /* Set ADC connection select to match default mixer setting (mic1
  1186. * pin)
  1187. */
  1188. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1189. /* Mute all inputs to mixer widget (even unconnected ones) */
  1190. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1191. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1192. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1193. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1194. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1195. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1196. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1197. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1198. { }
  1199. };
  1200. #endif
  1201. /* initialize jack-sensing, too */
  1202. static int cxt5047_hp_init(struct hda_codec *codec)
  1203. {
  1204. conexant_init(codec);
  1205. cxt5047_hp_automute(codec);
  1206. return 0;
  1207. }
  1208. enum {
  1209. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1210. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1211. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1212. #ifdef CONFIG_SND_DEBUG
  1213. CXT5047_TEST,
  1214. #endif
  1215. CXT5047_AUTO,
  1216. CXT5047_MODELS
  1217. };
  1218. static const char * const cxt5047_models[CXT5047_MODELS] = {
  1219. [CXT5047_LAPTOP] = "laptop",
  1220. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1221. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1222. #ifdef CONFIG_SND_DEBUG
  1223. [CXT5047_TEST] = "test",
  1224. #endif
  1225. [CXT5047_AUTO] = "auto",
  1226. };
  1227. static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1228. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1229. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1230. CXT5047_LAPTOP),
  1231. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1232. {}
  1233. };
  1234. static int patch_cxt5047(struct hda_codec *codec)
  1235. {
  1236. struct conexant_spec *spec;
  1237. int board_config;
  1238. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1239. cxt5047_models,
  1240. cxt5047_cfg_tbl);
  1241. if (board_config < 0)
  1242. board_config = CXT5047_AUTO; /* model=auto as default */
  1243. if (board_config == CXT5047_AUTO)
  1244. return patch_conexant_auto(codec);
  1245. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1246. if (!spec)
  1247. return -ENOMEM;
  1248. codec->spec = spec;
  1249. codec->pin_amp_workaround = 1;
  1250. spec->multiout.max_channels = 2;
  1251. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1252. spec->multiout.dac_nids = cxt5047_dac_nids;
  1253. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1254. spec->num_adc_nids = 1;
  1255. spec->adc_nids = cxt5047_adc_nids;
  1256. spec->capsrc_nids = cxt5047_capsrc_nids;
  1257. spec->num_mixers = 1;
  1258. spec->mixers[0] = cxt5047_base_mixers;
  1259. spec->num_init_verbs = 1;
  1260. spec->init_verbs[0] = cxt5047_init_verbs;
  1261. spec->spdif_route = 0;
  1262. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1263. spec->channel_mode = cxt5047_modes,
  1264. codec->patch_ops = conexant_patch_ops;
  1265. switch (board_config) {
  1266. case CXT5047_LAPTOP:
  1267. spec->num_mixers = 2;
  1268. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1269. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1270. break;
  1271. case CXT5047_LAPTOP_HP:
  1272. spec->num_mixers = 2;
  1273. spec->mixers[1] = cxt5047_hp_only_mixers;
  1274. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1275. codec->patch_ops.init = cxt5047_hp_init;
  1276. break;
  1277. case CXT5047_LAPTOP_EAPD:
  1278. spec->input_mux = &cxt5047_toshiba_capture_source;
  1279. spec->num_mixers = 2;
  1280. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1281. spec->num_init_verbs = 2;
  1282. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1283. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1284. break;
  1285. #ifdef CONFIG_SND_DEBUG
  1286. case CXT5047_TEST:
  1287. spec->input_mux = &cxt5047_test_capture_source;
  1288. spec->mixers[0] = cxt5047_test_mixer;
  1289. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1290. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1291. #endif
  1292. }
  1293. spec->vmaster_nid = 0x13;
  1294. switch (codec->subsystem_id >> 16) {
  1295. case 0x103c:
  1296. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1297. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1298. * with 0 dB offset 0x17)
  1299. */
  1300. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1301. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1302. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1303. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1304. (1 << AC_AMPCAP_MUTE_SHIFT));
  1305. break;
  1306. }
  1307. return 0;
  1308. }
  1309. /* Conexant 5051 specific */
  1310. static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1311. static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1312. static const struct hda_channel_mode cxt5051_modes[1] = {
  1313. { 2, NULL },
  1314. };
  1315. static void cxt5051_update_speaker(struct hda_codec *codec)
  1316. {
  1317. struct conexant_spec *spec = codec->spec;
  1318. unsigned int pinctl;
  1319. /* headphone pin */
  1320. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1321. snd_hda_set_pin_ctl(codec, 0x16, pinctl);
  1322. /* speaker pin */
  1323. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1324. snd_hda_set_pin_ctl(codec, 0x1a, pinctl);
  1325. /* on ideapad there is an additional speaker (subwoofer) to mute */
  1326. if (spec->ideapad)
  1327. snd_hda_set_pin_ctl(codec, 0x1b, pinctl);
  1328. }
  1329. /* turn on/off EAPD (+ mute HP) as a master switch */
  1330. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1331. struct snd_ctl_elem_value *ucontrol)
  1332. {
  1333. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1334. if (!cxt_eapd_put(kcontrol, ucontrol))
  1335. return 0;
  1336. cxt5051_update_speaker(codec);
  1337. return 1;
  1338. }
  1339. /* toggle input of built-in and mic jack appropriately */
  1340. static void cxt5051_portb_automic(struct hda_codec *codec)
  1341. {
  1342. struct conexant_spec *spec = codec->spec;
  1343. unsigned int present;
  1344. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1345. return;
  1346. present = snd_hda_jack_detect(codec, 0x17);
  1347. snd_hda_codec_write(codec, 0x14, 0,
  1348. AC_VERB_SET_CONNECT_SEL,
  1349. present ? 0x01 : 0x00);
  1350. }
  1351. /* switch the current ADC according to the jack state */
  1352. static void cxt5051_portc_automic(struct hda_codec *codec)
  1353. {
  1354. struct conexant_spec *spec = codec->spec;
  1355. unsigned int present;
  1356. hda_nid_t new_adc;
  1357. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1358. return;
  1359. present = snd_hda_jack_detect(codec, 0x18);
  1360. if (present)
  1361. spec->cur_adc_idx = 1;
  1362. else
  1363. spec->cur_adc_idx = 0;
  1364. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1365. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1366. /* stream is running, let's swap the current ADC */
  1367. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1368. spec->cur_adc = new_adc;
  1369. snd_hda_codec_setup_stream(codec, new_adc,
  1370. spec->cur_adc_stream_tag, 0,
  1371. spec->cur_adc_format);
  1372. }
  1373. }
  1374. /* mute internal speaker if HP is plugged */
  1375. static void cxt5051_hp_automute(struct hda_codec *codec)
  1376. {
  1377. struct conexant_spec *spec = codec->spec;
  1378. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1379. cxt5051_update_speaker(codec);
  1380. }
  1381. /* unsolicited event for HP jack sensing */
  1382. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1383. unsigned int res)
  1384. {
  1385. switch (res >> 26) {
  1386. case CONEXANT_HP_EVENT:
  1387. cxt5051_hp_automute(codec);
  1388. break;
  1389. case CXT5051_PORTB_EVENT:
  1390. cxt5051_portb_automic(codec);
  1391. break;
  1392. case CXT5051_PORTC_EVENT:
  1393. cxt5051_portc_automic(codec);
  1394. break;
  1395. }
  1396. }
  1397. static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1398. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1399. {
  1400. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1401. .name = "Master Playback Switch",
  1402. .info = cxt_eapd_info,
  1403. .get = cxt_eapd_get,
  1404. .put = cxt5051_hp_master_sw_put,
  1405. .private_value = 0x1a,
  1406. },
  1407. {}
  1408. };
  1409. static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1410. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1411. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1412. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1413. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1414. HDA_CODEC_VOLUME("Dock Mic Volume", 0x15, 0x00, HDA_INPUT),
  1415. HDA_CODEC_MUTE("Dock Mic Switch", 0x15, 0x00, HDA_INPUT),
  1416. {}
  1417. };
  1418. static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1419. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1420. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1421. HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
  1422. HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
  1423. {}
  1424. };
  1425. static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1426. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1427. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1428. {}
  1429. };
  1430. static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1431. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1432. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1433. {}
  1434. };
  1435. static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1436. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1437. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1438. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1439. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1440. {}
  1441. };
  1442. static const struct hda_verb cxt5051_init_verbs[] = {
  1443. /* Line in, Mic */
  1444. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1445. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1446. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1447. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1448. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1449. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1450. /* SPK */
  1451. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1452. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1453. /* HP, Amp */
  1454. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1455. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1456. /* DAC1 */
  1457. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1458. /* Record selector: Internal mic */
  1459. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1460. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1461. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1462. /* SPDIF route: PCM */
  1463. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1464. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1465. /* EAPD */
  1466. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1467. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1468. { } /* end */
  1469. };
  1470. static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1471. /* Line in, Mic */
  1472. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1473. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1474. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1475. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1476. /* SPK */
  1477. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1478. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1479. /* HP, Amp */
  1480. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1481. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1482. /* DAC1 */
  1483. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1484. /* Record selector: Internal mic */
  1485. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1486. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1487. /* SPDIF route: PCM */
  1488. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1489. /* EAPD */
  1490. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1491. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1492. { } /* end */
  1493. };
  1494. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1495. /* Line in, Mic */
  1496. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1497. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1498. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1499. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1500. /* SPK */
  1501. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1502. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1503. /* HP, Amp */
  1504. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1505. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1506. /* DAC1 */
  1507. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1508. /* Record selector: Internal mic */
  1509. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1510. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1511. /* SPDIF route: PCM */
  1512. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1513. /* EAPD */
  1514. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1515. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1516. { } /* end */
  1517. };
  1518. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1519. unsigned int event)
  1520. {
  1521. snd_hda_codec_write(codec, nid, 0,
  1522. AC_VERB_SET_UNSOLICITED_ENABLE,
  1523. AC_USRSP_EN | event);
  1524. }
  1525. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1526. /* Subwoofer */
  1527. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1528. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1529. { } /* end */
  1530. };
  1531. /* initialize jack-sensing, too */
  1532. static int cxt5051_init(struct hda_codec *codec)
  1533. {
  1534. struct conexant_spec *spec = codec->spec;
  1535. conexant_init(codec);
  1536. if (spec->auto_mic & AUTO_MIC_PORTB)
  1537. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1538. if (spec->auto_mic & AUTO_MIC_PORTC)
  1539. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1540. if (codec->patch_ops.unsol_event) {
  1541. cxt5051_hp_automute(codec);
  1542. cxt5051_portb_automic(codec);
  1543. cxt5051_portc_automic(codec);
  1544. }
  1545. return 0;
  1546. }
  1547. enum {
  1548. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1549. CXT5051_HP, /* no docking */
  1550. CXT5051_HP_DV6736, /* HP without mic switch */
  1551. CXT5051_F700, /* HP Compaq Presario F700 */
  1552. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1553. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1554. CXT5051_AUTO, /* auto-parser */
  1555. CXT5051_MODELS
  1556. };
  1557. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1558. [CXT5051_LAPTOP] = "laptop",
  1559. [CXT5051_HP] = "hp",
  1560. [CXT5051_HP_DV6736] = "hp-dv6736",
  1561. [CXT5051_F700] = "hp-700",
  1562. [CXT5051_TOSHIBA] = "toshiba",
  1563. [CXT5051_IDEAPAD] = "ideapad",
  1564. [CXT5051_AUTO] = "auto",
  1565. };
  1566. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1567. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1568. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1569. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1570. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1571. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1572. CXT5051_LAPTOP),
  1573. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1574. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1575. {}
  1576. };
  1577. static int patch_cxt5051(struct hda_codec *codec)
  1578. {
  1579. struct conexant_spec *spec;
  1580. int board_config;
  1581. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1582. cxt5051_models,
  1583. cxt5051_cfg_tbl);
  1584. if (board_config < 0)
  1585. board_config = CXT5051_AUTO; /* model=auto as default */
  1586. if (board_config == CXT5051_AUTO)
  1587. return patch_conexant_auto(codec);
  1588. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1589. if (!spec)
  1590. return -ENOMEM;
  1591. codec->spec = spec;
  1592. codec->pin_amp_workaround = 1;
  1593. codec->patch_ops = conexant_patch_ops;
  1594. codec->patch_ops.init = cxt5051_init;
  1595. spec->multiout.max_channels = 2;
  1596. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1597. spec->multiout.dac_nids = cxt5051_dac_nids;
  1598. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1599. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1600. spec->adc_nids = cxt5051_adc_nids;
  1601. spec->num_mixers = 2;
  1602. spec->mixers[0] = cxt5051_capture_mixers;
  1603. spec->mixers[1] = cxt5051_playback_mixers;
  1604. spec->num_init_verbs = 1;
  1605. spec->init_verbs[0] = cxt5051_init_verbs;
  1606. spec->spdif_route = 0;
  1607. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1608. spec->channel_mode = cxt5051_modes;
  1609. spec->cur_adc = 0;
  1610. spec->cur_adc_idx = 0;
  1611. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1612. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1613. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1614. switch (board_config) {
  1615. case CXT5051_HP:
  1616. spec->mixers[0] = cxt5051_hp_mixers;
  1617. break;
  1618. case CXT5051_HP_DV6736:
  1619. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1620. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1621. spec->auto_mic = 0;
  1622. break;
  1623. case CXT5051_F700:
  1624. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1625. spec->mixers[0] = cxt5051_f700_mixers;
  1626. spec->auto_mic = 0;
  1627. break;
  1628. case CXT5051_TOSHIBA:
  1629. spec->mixers[0] = cxt5051_toshiba_mixers;
  1630. spec->auto_mic = AUTO_MIC_PORTB;
  1631. break;
  1632. case CXT5051_IDEAPAD:
  1633. spec->init_verbs[spec->num_init_verbs++] =
  1634. cxt5051_ideapad_init_verbs;
  1635. spec->ideapad = 1;
  1636. break;
  1637. }
  1638. if (spec->beep_amp)
  1639. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  1640. return 0;
  1641. }
  1642. /* Conexant 5066 specific */
  1643. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1644. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1645. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1646. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1647. static const struct hda_channel_mode cxt5066_modes[1] = {
  1648. { 2, NULL },
  1649. };
  1650. #define HP_PRESENT_PORT_A (1 << 0)
  1651. #define HP_PRESENT_PORT_D (1 << 1)
  1652. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1653. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1654. static void cxt5066_update_speaker(struct hda_codec *codec)
  1655. {
  1656. struct conexant_spec *spec = codec->spec;
  1657. unsigned int pinctl;
  1658. codec_dbg(codec,
  1659. "CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1660. spec->hp_present, spec->cur_eapd);
  1661. /* Port A (HP) */
  1662. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1663. snd_hda_set_pin_ctl(codec, 0x19, pinctl);
  1664. /* Port D (HP/LO) */
  1665. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1666. if (spec->dell_automute || spec->thinkpad) {
  1667. /* Mute if Port A is connected */
  1668. if (hp_port_a_present(spec))
  1669. pinctl = 0;
  1670. } else {
  1671. /* Thinkpad/Dell doesn't give pin-D status */
  1672. if (!hp_port_d_present(spec))
  1673. pinctl = 0;
  1674. }
  1675. snd_hda_set_pin_ctl(codec, 0x1c, pinctl);
  1676. /* CLASS_D AMP */
  1677. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1678. snd_hda_set_pin_ctl(codec, 0x1f, pinctl);
  1679. }
  1680. /* turn on/off EAPD (+ mute HP) as a master switch */
  1681. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1682. struct snd_ctl_elem_value *ucontrol)
  1683. {
  1684. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1685. if (!cxt_eapd_put(kcontrol, ucontrol))
  1686. return 0;
  1687. cxt5066_update_speaker(codec);
  1688. return 1;
  1689. }
  1690. /* toggle input of built-in digital mic and mic jack appropriately */
  1691. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1692. {
  1693. unsigned int present;
  1694. struct hda_verb ext_mic_present[] = {
  1695. /* enable external mic, port B */
  1696. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1697. /* switch to external mic input */
  1698. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1699. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1700. /* disable internal digital mic */
  1701. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1702. {}
  1703. };
  1704. static const struct hda_verb ext_mic_absent[] = {
  1705. /* enable internal mic, port C */
  1706. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1707. /* switch to internal mic input */
  1708. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1709. /* disable external mic, port B */
  1710. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1711. {}
  1712. };
  1713. present = snd_hda_jack_detect(codec, 0x1a);
  1714. if (present) {
  1715. codec_dbg(codec, "CXT5066: external microphone detected\n");
  1716. snd_hda_sequence_write(codec, ext_mic_present);
  1717. } else {
  1718. codec_dbg(codec, "CXT5066: external microphone absent\n");
  1719. snd_hda_sequence_write(codec, ext_mic_absent);
  1720. }
  1721. }
  1722. /* toggle input of built-in digital mic and mic jack appropriately */
  1723. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1724. {
  1725. unsigned int present;
  1726. struct hda_verb ext_mic_present[] = {
  1727. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1728. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1729. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1730. {}
  1731. };
  1732. static const struct hda_verb ext_mic_absent[] = {
  1733. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1734. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1735. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1736. {}
  1737. };
  1738. present = snd_hda_jack_detect(codec, 0x1b);
  1739. if (present) {
  1740. codec_dbg(codec, "CXT5066: external microphone detected\n");
  1741. snd_hda_sequence_write(codec, ext_mic_present);
  1742. } else {
  1743. codec_dbg(codec, "CXT5066: external microphone absent\n");
  1744. snd_hda_sequence_write(codec, ext_mic_absent);
  1745. }
  1746. }
  1747. /* toggle input of built-in digital mic and mic jack appropriately */
  1748. static void cxt5066_asus_automic(struct hda_codec *codec)
  1749. {
  1750. unsigned int present;
  1751. present = snd_hda_jack_detect(codec, 0x1b);
  1752. codec_dbg(codec, "CXT5066: external microphone present=%d\n", present);
  1753. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1754. present ? 1 : 0);
  1755. }
  1756. /* toggle input of built-in digital mic and mic jack appropriately */
  1757. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  1758. {
  1759. unsigned int present;
  1760. present = snd_hda_jack_detect(codec, 0x1b);
  1761. codec_dbg(codec, "CXT5066: external microphone present=%d\n", present);
  1762. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1763. present ? 1 : 3);
  1764. }
  1765. /* toggle input of built-in digital mic and mic jack appropriately
  1766. order is: external mic -> dock mic -> interal mic */
  1767. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1768. {
  1769. unsigned int ext_present, dock_present;
  1770. static const struct hda_verb ext_mic_present[] = {
  1771. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1772. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1773. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1774. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1775. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1776. {}
  1777. };
  1778. static const struct hda_verb dock_mic_present[] = {
  1779. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1780. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1781. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1782. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1783. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1784. {}
  1785. };
  1786. static const struct hda_verb ext_mic_absent[] = {
  1787. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1788. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1789. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1790. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1791. {}
  1792. };
  1793. ext_present = snd_hda_jack_detect(codec, 0x1b);
  1794. dock_present = snd_hda_jack_detect(codec, 0x1a);
  1795. if (ext_present) {
  1796. codec_dbg(codec, "CXT5066: external microphone detected\n");
  1797. snd_hda_sequence_write(codec, ext_mic_present);
  1798. } else if (dock_present) {
  1799. codec_dbg(codec, "CXT5066: dock microphone detected\n");
  1800. snd_hda_sequence_write(codec, dock_mic_present);
  1801. } else {
  1802. codec_dbg(codec, "CXT5066: external microphone absent\n");
  1803. snd_hda_sequence_write(codec, ext_mic_absent);
  1804. }
  1805. }
  1806. /* mute internal speaker if HP is plugged */
  1807. static void cxt5066_hp_automute(struct hda_codec *codec)
  1808. {
  1809. struct conexant_spec *spec = codec->spec;
  1810. unsigned int portA, portD;
  1811. /* Port A */
  1812. portA = snd_hda_jack_detect(codec, 0x19);
  1813. /* Port D */
  1814. portD = snd_hda_jack_detect(codec, 0x1c);
  1815. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  1816. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  1817. codec_dbg(codec, "CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1818. portA, portD, spec->hp_present);
  1819. cxt5066_update_speaker(codec);
  1820. }
  1821. /* Dispatch the right mic autoswitch function */
  1822. static void cxt5066_automic(struct hda_codec *codec)
  1823. {
  1824. struct conexant_spec *spec = codec->spec;
  1825. if (spec->dell_vostro)
  1826. cxt5066_vostro_automic(codec);
  1827. else if (spec->ideapad)
  1828. cxt5066_ideapad_automic(codec);
  1829. else if (spec->thinkpad)
  1830. cxt5066_thinkpad_automic(codec);
  1831. else if (spec->hp_laptop)
  1832. cxt5066_hp_laptop_automic(codec);
  1833. else if (spec->asus)
  1834. cxt5066_asus_automic(codec);
  1835. }
  1836. /* unsolicited event for jack sensing */
  1837. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  1838. {
  1839. codec_dbg(codec, "CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1840. switch (res >> 26) {
  1841. case CONEXANT_HP_EVENT:
  1842. cxt5066_hp_automute(codec);
  1843. break;
  1844. case CONEXANT_MIC_EVENT:
  1845. cxt5066_automic(codec);
  1846. break;
  1847. }
  1848. }
  1849. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  1850. .num_items = 5,
  1851. .items = {
  1852. { "0dB", 0 },
  1853. { "10dB", 1 },
  1854. { "20dB", 2 },
  1855. { "30dB", 3 },
  1856. { "40dB", 4 },
  1857. },
  1858. };
  1859. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  1860. {
  1861. struct conexant_spec *spec = codec->spec;
  1862. snd_hda_codec_write_cache(codec, 0x17, 0,
  1863. AC_VERB_SET_AMP_GAIN_MUTE,
  1864. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  1865. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  1866. if (spec->ideapad || spec->thinkpad) {
  1867. /* adjust the internal mic as well...it is not through 0x17 */
  1868. snd_hda_codec_write_cache(codec, 0x23, 0,
  1869. AC_VERB_SET_AMP_GAIN_MUTE,
  1870. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  1871. cxt5066_analog_mic_boost.
  1872. items[spec->mic_boost].index);
  1873. }
  1874. }
  1875. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  1876. struct snd_ctl_elem_info *uinfo)
  1877. {
  1878. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  1879. }
  1880. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  1881. struct snd_ctl_elem_value *ucontrol)
  1882. {
  1883. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1884. struct conexant_spec *spec = codec->spec;
  1885. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  1886. return 0;
  1887. }
  1888. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  1889. struct snd_ctl_elem_value *ucontrol)
  1890. {
  1891. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1892. struct conexant_spec *spec = codec->spec;
  1893. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  1894. unsigned int idx;
  1895. idx = ucontrol->value.enumerated.item[0];
  1896. if (idx >= imux->num_items)
  1897. idx = imux->num_items - 1;
  1898. spec->mic_boost = idx;
  1899. cxt5066_set_mic_boost(codec);
  1900. return 1;
  1901. }
  1902. static void conexant_check_dig_outs(struct hda_codec *codec,
  1903. const hda_nid_t *dig_pins,
  1904. int num_pins)
  1905. {
  1906. struct conexant_spec *spec = codec->spec;
  1907. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  1908. int i;
  1909. for (i = 0; i < num_pins; i++, dig_pins++) {
  1910. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  1911. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  1912. continue;
  1913. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  1914. continue;
  1915. }
  1916. }
  1917. static const struct hda_input_mux cxt5066_capture_source = {
  1918. .num_items = 4,
  1919. .items = {
  1920. { "Mic B", 0 },
  1921. { "Mic C", 1 },
  1922. { "Mic E", 2 },
  1923. { "Mic F", 3 },
  1924. },
  1925. };
  1926. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  1927. .ops = &snd_hda_bind_vol,
  1928. .values = {
  1929. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1930. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1931. 0
  1932. },
  1933. };
  1934. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  1935. .ops = &snd_hda_bind_sw,
  1936. .values = {
  1937. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  1938. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  1939. 0
  1940. },
  1941. };
  1942. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  1943. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1944. {}
  1945. };
  1946. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  1947. {
  1948. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1949. .name = "Master Playback Switch",
  1950. .info = cxt_eapd_info,
  1951. .get = cxt_eapd_get,
  1952. .put = cxt5066_hp_master_sw_put,
  1953. .private_value = 0x1d,
  1954. },
  1955. {
  1956. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1957. .name = "Analog Mic Boost Capture Enum",
  1958. .info = cxt5066_mic_boost_mux_enum_info,
  1959. .get = cxt5066_mic_boost_mux_enum_get,
  1960. .put = cxt5066_mic_boost_mux_enum_put,
  1961. },
  1962. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  1963. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  1964. {}
  1965. };
  1966. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  1967. {
  1968. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1969. .name = "Internal Mic Boost Capture Enum",
  1970. .info = cxt5066_mic_boost_mux_enum_info,
  1971. .get = cxt5066_mic_boost_mux_enum_get,
  1972. .put = cxt5066_mic_boost_mux_enum_put,
  1973. .private_value = 0x23 | 0x100,
  1974. },
  1975. {}
  1976. };
  1977. static const struct hda_verb cxt5066_init_verbs[] = {
  1978. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  1979. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  1980. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  1981. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  1982. /* Speakers */
  1983. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1984. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1985. /* HP, Amp */
  1986. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1987. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1988. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1989. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  1990. /* DAC1 */
  1991. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1992. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  1993. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  1994. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1995. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  1996. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  1997. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  1998. /* no digital microphone support yet */
  1999. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2000. /* Audio input selector */
  2001. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2002. /* SPDIF route: PCM */
  2003. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2004. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2005. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2006. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2007. /* EAPD */
  2008. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2009. /* not handling these yet */
  2010. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2011. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2012. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2013. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2014. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2015. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2016. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2017. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2018. { } /* end */
  2019. };
  2020. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2021. /* Port A: headphones */
  2022. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2023. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2024. /* Port B: external microphone */
  2025. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2026. /* Port C: unused */
  2027. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2028. /* Port D: unused */
  2029. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2030. /* Port E: unused, but has primary EAPD */
  2031. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2032. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2033. /* Port F: unused */
  2034. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2035. /* Port G: internal speakers */
  2036. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2037. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2038. /* DAC1 */
  2039. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2040. /* DAC2: unused */
  2041. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2042. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2043. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2044. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2045. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2046. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2047. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2048. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2049. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2050. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2051. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2052. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2053. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2054. /* Digital microphone port */
  2055. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2056. /* Audio input selectors */
  2057. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2058. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2059. /* Disable SPDIF */
  2060. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2061. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2062. /* enable unsolicited events for Port A and B */
  2063. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2064. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2065. { } /* end */
  2066. };
  2067. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2068. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2069. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2070. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2071. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2072. /* Speakers */
  2073. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2074. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2075. /* HP, Amp */
  2076. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2077. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2078. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2079. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2080. /* DAC1 */
  2081. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2082. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2083. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2084. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2085. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2086. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2087. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2088. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2089. /* Audio input selector */
  2090. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2091. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2092. /* SPDIF route: PCM */
  2093. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2094. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2095. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2096. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2097. /* internal microphone */
  2098. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2099. /* EAPD */
  2100. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2101. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2102. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2103. { } /* end */
  2104. };
  2105. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2106. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2107. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2108. /* Port G: internal speakers */
  2109. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2110. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2111. /* Port A: HP, Amp */
  2112. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2113. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2114. /* Port B: Mic Dock */
  2115. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2116. /* Port C: Mic */
  2117. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2118. /* Port D: HP Dock, Amp */
  2119. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2120. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2121. /* DAC1 */
  2122. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2123. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2124. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2125. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2126. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2127. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2128. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2129. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2130. /* Audio input selector */
  2131. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2132. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2133. /* SPDIF route: PCM */
  2134. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2135. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2136. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2137. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2138. /* internal microphone */
  2139. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2140. /* EAPD */
  2141. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2142. /* enable unsolicited events for Port A, B, C and D */
  2143. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2144. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2145. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2146. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2147. { } /* end */
  2148. };
  2149. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2150. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2151. { } /* end */
  2152. };
  2153. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2154. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2155. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2156. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2157. { } /* end */
  2158. };
  2159. /* initialize jack-sensing, too */
  2160. static int cxt5066_init(struct hda_codec *codec)
  2161. {
  2162. codec_dbg(codec, "CXT5066: init\n");
  2163. conexant_init(codec);
  2164. if (codec->patch_ops.unsol_event) {
  2165. cxt5066_hp_automute(codec);
  2166. cxt5066_automic(codec);
  2167. }
  2168. cxt5066_set_mic_boost(codec);
  2169. return 0;
  2170. }
  2171. enum {
  2172. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2173. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2174. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2175. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2176. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2177. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2178. CXT5066_HP_LAPTOP, /* HP Laptop */
  2179. CXT5066_AUTO, /* BIOS auto-parser */
  2180. CXT5066_MODELS
  2181. };
  2182. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2183. [CXT5066_LAPTOP] = "laptop",
  2184. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2185. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2186. [CXT5066_IDEAPAD] = "ideapad",
  2187. [CXT5066_THINKPAD] = "thinkpad",
  2188. [CXT5066_ASUS] = "asus",
  2189. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2190. [CXT5066_AUTO] = "auto",
  2191. };
  2192. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2193. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2194. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2195. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2196. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2197. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2198. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2199. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2200. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2201. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2202. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2203. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2204. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2205. CXT5066_LAPTOP),
  2206. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2207. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2208. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2209. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
  2210. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2211. {}
  2212. };
  2213. static int patch_cxt5066(struct hda_codec *codec)
  2214. {
  2215. struct conexant_spec *spec;
  2216. int board_config;
  2217. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2218. cxt5066_models, cxt5066_cfg_tbl);
  2219. if (board_config < 0)
  2220. board_config = CXT5066_AUTO; /* model=auto as default */
  2221. if (board_config == CXT5066_AUTO)
  2222. return patch_conexant_auto(codec);
  2223. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2224. if (!spec)
  2225. return -ENOMEM;
  2226. codec->spec = spec;
  2227. codec->patch_ops = conexant_patch_ops;
  2228. codec->patch_ops.init = conexant_init;
  2229. spec->dell_automute = 0;
  2230. spec->multiout.max_channels = 2;
  2231. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2232. spec->multiout.dac_nids = cxt5066_dac_nids;
  2233. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2234. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2235. spec->num_adc_nids = 1;
  2236. spec->adc_nids = cxt5066_adc_nids;
  2237. spec->capsrc_nids = cxt5066_capsrc_nids;
  2238. spec->input_mux = &cxt5066_capture_source;
  2239. spec->port_d_mode = PIN_HP;
  2240. spec->num_init_verbs = 1;
  2241. spec->init_verbs[0] = cxt5066_init_verbs;
  2242. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2243. spec->channel_mode = cxt5066_modes;
  2244. spec->cur_adc = 0;
  2245. spec->cur_adc_idx = 0;
  2246. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2247. switch (board_config) {
  2248. default:
  2249. case CXT5066_LAPTOP:
  2250. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2251. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2252. break;
  2253. case CXT5066_DELL_LAPTOP:
  2254. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2255. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2256. spec->port_d_mode = PIN_OUT;
  2257. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2258. spec->num_init_verbs++;
  2259. spec->dell_automute = 1;
  2260. break;
  2261. case CXT5066_ASUS:
  2262. case CXT5066_HP_LAPTOP:
  2263. codec->patch_ops.init = cxt5066_init;
  2264. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2265. spec->init_verbs[spec->num_init_verbs] =
  2266. cxt5066_init_verbs_hp_laptop;
  2267. spec->num_init_verbs++;
  2268. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2269. spec->asus = board_config == CXT5066_ASUS;
  2270. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2271. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2272. /* no S/PDIF out */
  2273. if (board_config == CXT5066_HP_LAPTOP)
  2274. spec->multiout.dig_out_nid = 0;
  2275. /* input source automatically selected */
  2276. spec->input_mux = NULL;
  2277. spec->port_d_mode = 0;
  2278. spec->mic_boost = 3; /* default 30dB gain */
  2279. break;
  2280. case CXT5066_DELL_VOSTRO:
  2281. codec->patch_ops.init = cxt5066_init;
  2282. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2283. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2284. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2285. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2286. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2287. spec->port_d_mode = 0;
  2288. spec->dell_vostro = 1;
  2289. spec->mic_boost = 3; /* default 30dB gain */
  2290. /* no S/PDIF out */
  2291. spec->multiout.dig_out_nid = 0;
  2292. /* input source automatically selected */
  2293. spec->input_mux = NULL;
  2294. break;
  2295. case CXT5066_IDEAPAD:
  2296. codec->patch_ops.init = cxt5066_init;
  2297. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2298. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2299. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2300. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2301. spec->port_d_mode = 0;
  2302. spec->ideapad = 1;
  2303. spec->mic_boost = 2; /* default 20dB gain */
  2304. /* no S/PDIF out */
  2305. spec->multiout.dig_out_nid = 0;
  2306. /* input source automatically selected */
  2307. spec->input_mux = NULL;
  2308. break;
  2309. case CXT5066_THINKPAD:
  2310. codec->patch_ops.init = cxt5066_init;
  2311. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2312. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2313. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2314. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2315. spec->thinkpad = 1;
  2316. spec->port_d_mode = PIN_OUT;
  2317. spec->mic_boost = 2; /* default 20dB gain */
  2318. /* no S/PDIF out */
  2319. spec->multiout.dig_out_nid = 0;
  2320. /* input source automatically selected */
  2321. spec->input_mux = NULL;
  2322. break;
  2323. }
  2324. if (spec->beep_amp)
  2325. snd_hda_attach_beep_device(codec, get_amp_nid_(spec->beep_amp));
  2326. return 0;
  2327. }
  2328. #endif /* ENABLE_CXT_STATIC_QUIRKS */
  2329. /*
  2330. * Automatic parser for CX20641 & co
  2331. */
  2332. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  2333. static void cx_auto_parse_beep(struct hda_codec *codec)
  2334. {
  2335. struct conexant_spec *spec = codec->spec;
  2336. hda_nid_t nid, end_nid;
  2337. end_nid = codec->start_nid + codec->num_nodes;
  2338. for (nid = codec->start_nid; nid < end_nid; nid++)
  2339. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  2340. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  2341. break;
  2342. }
  2343. }
  2344. #else
  2345. #define cx_auto_parse_beep(codec)
  2346. #endif
  2347. /* parse EAPDs */
  2348. static void cx_auto_parse_eapd(struct hda_codec *codec)
  2349. {
  2350. struct conexant_spec *spec = codec->spec;
  2351. hda_nid_t nid, end_nid;
  2352. end_nid = codec->start_nid + codec->num_nodes;
  2353. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2354. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  2355. continue;
  2356. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
  2357. continue;
  2358. spec->eapds[spec->num_eapds++] = nid;
  2359. if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
  2360. break;
  2361. }
  2362. /* NOTE: below is a wild guess; if we have more than two EAPDs,
  2363. * it's a new chip, where EAPDs are supposed to be associated to
  2364. * pins, and we can control EAPD per pin.
  2365. * OTOH, if only one or two EAPDs are found, it's an old chip,
  2366. * thus it might control over all pins.
  2367. */
  2368. if (spec->num_eapds > 2)
  2369. spec->dynamic_eapd = 1;
  2370. }
  2371. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  2372. hda_nid_t *pins, bool on)
  2373. {
  2374. int i;
  2375. for (i = 0; i < num_pins; i++) {
  2376. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  2377. snd_hda_codec_write(codec, pins[i], 0,
  2378. AC_VERB_SET_EAPD_BTLENABLE,
  2379. on ? 0x02 : 0);
  2380. }
  2381. }
  2382. /* turn on/off EAPD according to Master switch */
  2383. static void cx_auto_vmaster_hook(void *private_data, int enabled)
  2384. {
  2385. struct hda_codec *codec = private_data;
  2386. struct conexant_spec *spec = codec->spec;
  2387. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, enabled);
  2388. }
  2389. static int cx_auto_build_controls(struct hda_codec *codec)
  2390. {
  2391. int err;
  2392. err = snd_hda_gen_build_controls(codec);
  2393. if (err < 0)
  2394. return err;
  2395. err = add_beep_ctls(codec);
  2396. if (err < 0)
  2397. return err;
  2398. return 0;
  2399. }
  2400. static int cx_auto_init(struct hda_codec *codec)
  2401. {
  2402. struct conexant_spec *spec = codec->spec;
  2403. snd_hda_gen_init(codec);
  2404. if (!spec->dynamic_eapd)
  2405. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
  2406. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_INIT);
  2407. return 0;
  2408. }
  2409. #define cx_auto_free snd_hda_gen_free
  2410. static const struct hda_codec_ops cx_auto_patch_ops = {
  2411. .build_controls = cx_auto_build_controls,
  2412. .build_pcms = snd_hda_gen_build_pcms,
  2413. .init = cx_auto_init,
  2414. .free = cx_auto_free,
  2415. .unsol_event = snd_hda_jack_unsol_event,
  2416. #ifdef CONFIG_PM
  2417. .check_power_status = snd_hda_gen_check_power_status,
  2418. #endif
  2419. };
  2420. /*
  2421. * pin fix-up
  2422. */
  2423. enum {
  2424. CXT_PINCFG_LENOVO_X200,
  2425. CXT_PINCFG_LENOVO_TP410,
  2426. CXT_PINCFG_LEMOTE_A1004,
  2427. CXT_PINCFG_LEMOTE_A1205,
  2428. CXT_FIXUP_STEREO_DMIC,
  2429. CXT_FIXUP_INC_MIC_BOOST,
  2430. CXT_FIXUP_HEADPHONE_MIC_PIN,
  2431. CXT_FIXUP_HEADPHONE_MIC,
  2432. CXT_FIXUP_GPIO1,
  2433. CXT_FIXUP_THINKPAD_ACPI,
  2434. CXT_FIXUP_OLPC_XO,
  2435. CXT_FIXUP_CAP_MIX_AMP,
  2436. CXT_FIXUP_TOSHIBA_P105,
  2437. CXT_FIXUP_HP_530,
  2438. CXT_FIXUP_CAP_MIX_AMP_5047,
  2439. };
  2440. /* for hda_fixup_thinkpad_acpi() */
  2441. #include "thinkpad_helper.c"
  2442. static void cxt_fixup_stereo_dmic(struct hda_codec *codec,
  2443. const struct hda_fixup *fix, int action)
  2444. {
  2445. struct conexant_spec *spec = codec->spec;
  2446. spec->gen.inv_dmic_split = 1;
  2447. }
  2448. static void cxt5066_increase_mic_boost(struct hda_codec *codec,
  2449. const struct hda_fixup *fix, int action)
  2450. {
  2451. if (action != HDA_FIXUP_ACT_PRE_PROBE)
  2452. return;
  2453. snd_hda_override_amp_caps(codec, 0x17, HDA_OUTPUT,
  2454. (0x3 << AC_AMPCAP_OFFSET_SHIFT) |
  2455. (0x4 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2456. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2457. (0 << AC_AMPCAP_MUTE_SHIFT));
  2458. }
  2459. static void cxt_update_headset_mode(struct hda_codec *codec)
  2460. {
  2461. /* The verbs used in this function were tested on a Conexant CX20751/2 codec. */
  2462. int i;
  2463. bool mic_mode = false;
  2464. struct conexant_spec *spec = codec->spec;
  2465. struct auto_pin_cfg *cfg = &spec->gen.autocfg;
  2466. hda_nid_t mux_pin = spec->gen.imux_pins[spec->gen.cur_mux[0]];
  2467. for (i = 0; i < cfg->num_inputs; i++)
  2468. if (cfg->inputs[i].pin == mux_pin) {
  2469. mic_mode = !!cfg->inputs[i].is_headphone_mic;
  2470. break;
  2471. }
  2472. if (mic_mode) {
  2473. snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x7c); /* enable merged mode for analog int-mic */
  2474. spec->gen.hp_jack_present = false;
  2475. } else {
  2476. snd_hda_codec_write_cache(codec, 0x1c, 0, 0x410, 0x54); /* disable merged mode for analog int-mic */
  2477. spec->gen.hp_jack_present = snd_hda_jack_detect(codec, spec->gen.autocfg.hp_pins[0]);
  2478. }
  2479. snd_hda_gen_update_outputs(codec);
  2480. }
  2481. static void cxt_update_headset_mode_hook(struct hda_codec *codec,
  2482. struct snd_kcontrol *kcontrol,
  2483. struct snd_ctl_elem_value *ucontrol)
  2484. {
  2485. cxt_update_headset_mode(codec);
  2486. }
  2487. static void cxt_fixup_headphone_mic(struct hda_codec *codec,
  2488. const struct hda_fixup *fix, int action)
  2489. {
  2490. struct conexant_spec *spec = codec->spec;
  2491. switch (action) {
  2492. case HDA_FIXUP_ACT_PRE_PROBE:
  2493. spec->parse_flags |= HDA_PINCFG_HEADPHONE_MIC;
  2494. break;
  2495. case HDA_FIXUP_ACT_PROBE:
  2496. spec->gen.cap_sync_hook = cxt_update_headset_mode_hook;
  2497. spec->gen.automute_hook = cxt_update_headset_mode;
  2498. break;
  2499. case HDA_FIXUP_ACT_INIT:
  2500. cxt_update_headset_mode(codec);
  2501. break;
  2502. }
  2503. }
  2504. /* OPLC XO 1.5 fixup */
  2505. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  2506. * through the microphone jack.
  2507. * When the user enables this through a mixer switch, both internal and
  2508. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  2509. * we also allow the bias to be configured through a separate mixer
  2510. * control. */
  2511. #define update_mic_pin(codec, nid, val) \
  2512. snd_hda_codec_update_cache(codec, nid, 0, \
  2513. AC_VERB_SET_PIN_WIDGET_CONTROL, val)
  2514. static const struct hda_input_mux olpc_xo_dc_bias = {
  2515. .num_items = 3,
  2516. .items = {
  2517. { "Off", PIN_IN },
  2518. { "50%", PIN_VREF50 },
  2519. { "80%", PIN_VREF80 },
  2520. },
  2521. };
  2522. static void olpc_xo_update_mic_boost(struct hda_codec *codec)
  2523. {
  2524. struct conexant_spec *spec = codec->spec;
  2525. int ch, val;
  2526. for (ch = 0; ch < 2; ch++) {
  2527. val = AC_AMP_SET_OUTPUT |
  2528. (ch ? AC_AMP_SET_RIGHT : AC_AMP_SET_LEFT);
  2529. if (!spec->dc_enable)
  2530. val |= snd_hda_codec_amp_read(codec, 0x17, ch, HDA_OUTPUT, 0);
  2531. snd_hda_codec_write(codec, 0x17, 0,
  2532. AC_VERB_SET_AMP_GAIN_MUTE, val);
  2533. }
  2534. }
  2535. static void olpc_xo_update_mic_pins(struct hda_codec *codec)
  2536. {
  2537. struct conexant_spec *spec = codec->spec;
  2538. int cur_input, val;
  2539. struct nid_path *path;
  2540. cur_input = spec->gen.input_paths[0][spec->gen.cur_mux[0]];
  2541. /* Set up mic pins for port-B, C and F dynamically as the recording
  2542. * LED is turned on/off by these pin controls
  2543. */
  2544. if (!spec->dc_enable) {
  2545. /* disable DC bias path and pin for port F */
  2546. update_mic_pin(codec, 0x1e, 0);
  2547. snd_hda_activate_path(codec, spec->dc_mode_path, false, false);
  2548. /* update port B (ext mic) and C (int mic) */
  2549. /* OLPC defers mic widget control until when capture is
  2550. * started because the microphone LED comes on as soon as
  2551. * these settings are put in place. if we did this before
  2552. * recording, it would give the false indication that
  2553. * recording is happening when it is not.
  2554. */
  2555. update_mic_pin(codec, 0x1a, spec->recording ?
  2556. snd_hda_codec_get_pin_target(codec, 0x1a) : 0);
  2557. update_mic_pin(codec, 0x1b, spec->recording ?
  2558. snd_hda_codec_get_pin_target(codec, 0x1b) : 0);
  2559. /* enable normal mic path */
  2560. path = snd_hda_get_path_from_idx(codec, cur_input);
  2561. if (path)
  2562. snd_hda_activate_path(codec, path, true, false);
  2563. } else {
  2564. /* disable normal mic path */
  2565. path = snd_hda_get_path_from_idx(codec, cur_input);
  2566. if (path)
  2567. snd_hda_activate_path(codec, path, false, false);
  2568. /* Even though port F is the DC input, the bias is controlled
  2569. * on port B. We also leave that port as an active input (but
  2570. * unselected) in DC mode just in case that is necessary to
  2571. * make the bias setting take effect.
  2572. */
  2573. if (spec->recording)
  2574. val = olpc_xo_dc_bias.items[spec->dc_input_bias].index;
  2575. else
  2576. val = 0;
  2577. update_mic_pin(codec, 0x1a, val);
  2578. update_mic_pin(codec, 0x1b, 0);
  2579. /* enable DC bias path and pin */
  2580. update_mic_pin(codec, 0x1e, spec->recording ? PIN_IN : 0);
  2581. snd_hda_activate_path(codec, spec->dc_mode_path, true, false);
  2582. }
  2583. }
  2584. /* mic_autoswitch hook */
  2585. static void olpc_xo_automic(struct hda_codec *codec, struct hda_jack_tbl *jack)
  2586. {
  2587. struct conexant_spec *spec = codec->spec;
  2588. int saved_cached_write = codec->cached_write;
  2589. codec->cached_write = 1;
  2590. /* in DC mode, we don't handle automic */
  2591. if (!spec->dc_enable)
  2592. snd_hda_gen_mic_autoswitch(codec, jack);
  2593. olpc_xo_update_mic_pins(codec);
  2594. snd_hda_codec_flush_cache(codec);
  2595. codec->cached_write = saved_cached_write;
  2596. if (spec->dc_enable)
  2597. olpc_xo_update_mic_boost(codec);
  2598. }
  2599. /* pcm_capture hook */
  2600. static void olpc_xo_capture_hook(struct hda_pcm_stream *hinfo,
  2601. struct hda_codec *codec,
  2602. struct snd_pcm_substream *substream,
  2603. int action)
  2604. {
  2605. struct conexant_spec *spec = codec->spec;
  2606. /* toggle spec->recording flag and update mic pins accordingly
  2607. * for turning on/off LED
  2608. */
  2609. switch (action) {
  2610. case HDA_GEN_PCM_ACT_PREPARE:
  2611. spec->recording = 1;
  2612. olpc_xo_update_mic_pins(codec);
  2613. break;
  2614. case HDA_GEN_PCM_ACT_CLEANUP:
  2615. spec->recording = 0;
  2616. olpc_xo_update_mic_pins(codec);
  2617. break;
  2618. }
  2619. }
  2620. static int olpc_xo_dc_mode_get(struct snd_kcontrol *kcontrol,
  2621. struct snd_ctl_elem_value *ucontrol)
  2622. {
  2623. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2624. struct conexant_spec *spec = codec->spec;
  2625. ucontrol->value.integer.value[0] = spec->dc_enable;
  2626. return 0;
  2627. }
  2628. static int olpc_xo_dc_mode_put(struct snd_kcontrol *kcontrol,
  2629. struct snd_ctl_elem_value *ucontrol)
  2630. {
  2631. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2632. struct conexant_spec *spec = codec->spec;
  2633. int dc_enable = !!ucontrol->value.integer.value[0];
  2634. if (dc_enable == spec->dc_enable)
  2635. return 0;
  2636. spec->dc_enable = dc_enable;
  2637. olpc_xo_update_mic_pins(codec);
  2638. olpc_xo_update_mic_boost(codec);
  2639. return 1;
  2640. }
  2641. static int olpc_xo_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2642. struct snd_ctl_elem_value *ucontrol)
  2643. {
  2644. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2645. struct conexant_spec *spec = codec->spec;
  2646. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2647. return 0;
  2648. }
  2649. static int olpc_xo_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2650. struct snd_ctl_elem_info *uinfo)
  2651. {
  2652. return snd_hda_input_mux_info(&olpc_xo_dc_bias, uinfo);
  2653. }
  2654. static int olpc_xo_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2655. struct snd_ctl_elem_value *ucontrol)
  2656. {
  2657. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2658. struct conexant_spec *spec = codec->spec;
  2659. const struct hda_input_mux *imux = &olpc_xo_dc_bias;
  2660. unsigned int idx;
  2661. idx = ucontrol->value.enumerated.item[0];
  2662. if (idx >= imux->num_items)
  2663. idx = imux->num_items - 1;
  2664. if (spec->dc_input_bias == idx)
  2665. return 0;
  2666. spec->dc_input_bias = idx;
  2667. if (spec->dc_enable)
  2668. olpc_xo_update_mic_pins(codec);
  2669. return 1;
  2670. }
  2671. static const struct snd_kcontrol_new olpc_xo_mixers[] = {
  2672. {
  2673. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2674. .name = "DC Mode Enable Switch",
  2675. .info = snd_ctl_boolean_mono_info,
  2676. .get = olpc_xo_dc_mode_get,
  2677. .put = olpc_xo_dc_mode_put,
  2678. },
  2679. {
  2680. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2681. .name = "DC Input Bias Enum",
  2682. .info = olpc_xo_dc_bias_enum_info,
  2683. .get = olpc_xo_dc_bias_enum_get,
  2684. .put = olpc_xo_dc_bias_enum_put,
  2685. },
  2686. {}
  2687. };
  2688. /* overriding mic boost put callback; update mic boost volume only when
  2689. * DC mode is disabled
  2690. */
  2691. static int olpc_xo_mic_boost_put(struct snd_kcontrol *kcontrol,
  2692. struct snd_ctl_elem_value *ucontrol)
  2693. {
  2694. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2695. struct conexant_spec *spec = codec->spec;
  2696. int ret = snd_hda_mixer_amp_volume_put(kcontrol, ucontrol);
  2697. if (ret > 0 && spec->dc_enable)
  2698. olpc_xo_update_mic_boost(codec);
  2699. return ret;
  2700. }
  2701. static void cxt_fixup_olpc_xo(struct hda_codec *codec,
  2702. const struct hda_fixup *fix, int action)
  2703. {
  2704. struct conexant_spec *spec = codec->spec;
  2705. int i;
  2706. if (action != HDA_FIXUP_ACT_PROBE)
  2707. return;
  2708. spec->gen.mic_autoswitch_hook = olpc_xo_automic;
  2709. spec->gen.pcm_capture_hook = olpc_xo_capture_hook;
  2710. spec->dc_mode_path = snd_hda_add_new_path(codec, 0x1e, 0x14, 0);
  2711. snd_hda_add_new_ctls(codec, olpc_xo_mixers);
  2712. /* OLPC's microphone port is DC coupled for use with external sensors,
  2713. * therefore we use a 50% mic bias in order to center the input signal
  2714. * with the DC input range of the codec.
  2715. */
  2716. snd_hda_codec_set_pin_target(codec, 0x1a, PIN_VREF50);
  2717. /* override mic boost control */
  2718. for (i = 0; i < spec->gen.kctls.used; i++) {
  2719. struct snd_kcontrol_new *kctl =
  2720. snd_array_elem(&spec->gen.kctls, i);
  2721. if (!strcmp(kctl->name, "Mic Boost Volume")) {
  2722. kctl->put = olpc_xo_mic_boost_put;
  2723. break;
  2724. }
  2725. }
  2726. }
  2727. /*
  2728. * Fix max input level on mixer widget to 0dB
  2729. * (originally it has 0x2b steps with 0dB offset 0x14)
  2730. */
  2731. static void cxt_fixup_cap_mix_amp(struct hda_codec *codec,
  2732. const struct hda_fixup *fix, int action)
  2733. {
  2734. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  2735. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  2736. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2737. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2738. (1 << AC_AMPCAP_MUTE_SHIFT));
  2739. }
  2740. /*
  2741. * Fix max input level on mixer widget to 0dB
  2742. * (originally it has 0x1e steps with 0 dB offset 0x17)
  2743. */
  2744. static void cxt_fixup_cap_mix_amp_5047(struct hda_codec *codec,
  2745. const struct hda_fixup *fix, int action)
  2746. {
  2747. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  2748. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  2749. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2750. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2751. (1 << AC_AMPCAP_MUTE_SHIFT));
  2752. }
  2753. /* ThinkPad X200 & co with cxt5051 */
  2754. static const struct hda_pintbl cxt_pincfg_lenovo_x200[] = {
  2755. { 0x16, 0x042140ff }, /* HP (seq# overridden) */
  2756. { 0x17, 0x21a11000 }, /* dock-mic */
  2757. { 0x19, 0x2121103f }, /* dock-HP */
  2758. { 0x1c, 0x21440100 }, /* dock SPDIF out */
  2759. {}
  2760. };
  2761. /* ThinkPad 410/420/510/520, X201 & co with cxt5066 */
  2762. static const struct hda_pintbl cxt_pincfg_lenovo_tp410[] = {
  2763. { 0x19, 0x042110ff }, /* HP (seq# overridden) */
  2764. { 0x1a, 0x21a190f0 }, /* dock-mic */
  2765. { 0x1c, 0x212140ff }, /* dock-HP */
  2766. {}
  2767. };
  2768. /* Lemote A1004/A1205 with cxt5066 */
  2769. static const struct hda_pintbl cxt_pincfg_lemote[] = {
  2770. { 0x1a, 0x90a10020 }, /* Internal mic */
  2771. { 0x1b, 0x03a11020 }, /* External mic */
  2772. { 0x1d, 0x400101f0 }, /* Not used */
  2773. { 0x1e, 0x40a701f0 }, /* Not used */
  2774. { 0x20, 0x404501f0 }, /* Not used */
  2775. { 0x22, 0x404401f0 }, /* Not used */
  2776. { 0x23, 0x40a701f0 }, /* Not used */
  2777. {}
  2778. };
  2779. static const struct hda_fixup cxt_fixups[] = {
  2780. [CXT_PINCFG_LENOVO_X200] = {
  2781. .type = HDA_FIXUP_PINS,
  2782. .v.pins = cxt_pincfg_lenovo_x200,
  2783. },
  2784. [CXT_PINCFG_LENOVO_TP410] = {
  2785. .type = HDA_FIXUP_PINS,
  2786. .v.pins = cxt_pincfg_lenovo_tp410,
  2787. .chained = true,
  2788. .chain_id = CXT_FIXUP_THINKPAD_ACPI,
  2789. },
  2790. [CXT_PINCFG_LEMOTE_A1004] = {
  2791. .type = HDA_FIXUP_PINS,
  2792. .chained = true,
  2793. .chain_id = CXT_FIXUP_INC_MIC_BOOST,
  2794. .v.pins = cxt_pincfg_lemote,
  2795. },
  2796. [CXT_PINCFG_LEMOTE_A1205] = {
  2797. .type = HDA_FIXUP_PINS,
  2798. .v.pins = cxt_pincfg_lemote,
  2799. },
  2800. [CXT_FIXUP_STEREO_DMIC] = {
  2801. .type = HDA_FIXUP_FUNC,
  2802. .v.func = cxt_fixup_stereo_dmic,
  2803. },
  2804. [CXT_FIXUP_INC_MIC_BOOST] = {
  2805. .type = HDA_FIXUP_FUNC,
  2806. .v.func = cxt5066_increase_mic_boost,
  2807. },
  2808. [CXT_FIXUP_HEADPHONE_MIC_PIN] = {
  2809. .type = HDA_FIXUP_PINS,
  2810. .chained = true,
  2811. .chain_id = CXT_FIXUP_HEADPHONE_MIC,
  2812. .v.pins = (const struct hda_pintbl[]) {
  2813. { 0x18, 0x03a1913d }, /* use as headphone mic, without its own jack detect */
  2814. { }
  2815. }
  2816. },
  2817. [CXT_FIXUP_HEADPHONE_MIC] = {
  2818. .type = HDA_FIXUP_FUNC,
  2819. .v.func = cxt_fixup_headphone_mic,
  2820. },
  2821. [CXT_FIXUP_GPIO1] = {
  2822. .type = HDA_FIXUP_VERBS,
  2823. .v.verbs = (const struct hda_verb[]) {
  2824. { 0x01, AC_VERB_SET_GPIO_MASK, 0x01 },
  2825. { 0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01 },
  2826. { 0x01, AC_VERB_SET_GPIO_DATA, 0x01 },
  2827. { }
  2828. },
  2829. },
  2830. [CXT_FIXUP_THINKPAD_ACPI] = {
  2831. .type = HDA_FIXUP_FUNC,
  2832. .v.func = hda_fixup_thinkpad_acpi,
  2833. },
  2834. [CXT_FIXUP_OLPC_XO] = {
  2835. .type = HDA_FIXUP_FUNC,
  2836. .v.func = cxt_fixup_olpc_xo,
  2837. },
  2838. [CXT_FIXUP_CAP_MIX_AMP] = {
  2839. .type = HDA_FIXUP_FUNC,
  2840. .v.func = cxt_fixup_cap_mix_amp,
  2841. },
  2842. [CXT_FIXUP_TOSHIBA_P105] = {
  2843. .type = HDA_FIXUP_PINS,
  2844. .v.pins = (const struct hda_pintbl[]) {
  2845. { 0x10, 0x961701f0 }, /* speaker/hp */
  2846. { 0x12, 0x02a1901e }, /* ext mic */
  2847. { 0x14, 0x95a70110 }, /* int mic */
  2848. {}
  2849. },
  2850. },
  2851. [CXT_FIXUP_HP_530] = {
  2852. .type = HDA_FIXUP_PINS,
  2853. .v.pins = (const struct hda_pintbl[]) {
  2854. { 0x12, 0x90a60160 }, /* int mic */
  2855. {}
  2856. },
  2857. .chained = true,
  2858. .chain_id = CXT_FIXUP_CAP_MIX_AMP,
  2859. },
  2860. [CXT_FIXUP_CAP_MIX_AMP_5047] = {
  2861. .type = HDA_FIXUP_FUNC,
  2862. .v.func = cxt_fixup_cap_mix_amp_5047,
  2863. },
  2864. };
  2865. static const struct snd_pci_quirk cxt5045_fixups[] = {
  2866. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT_FIXUP_HP_530),
  2867. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT_FIXUP_TOSHIBA_P105),
  2868. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  2869. * really bad sound over 0dB on NID 0x17.
  2870. */
  2871. SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP),
  2872. SND_PCI_QUIRK_VENDOR(0x1631, "Packard Bell", CXT_FIXUP_CAP_MIX_AMP),
  2873. SND_PCI_QUIRK_VENDOR(0x1734, "Fujitsu", CXT_FIXUP_CAP_MIX_AMP),
  2874. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT_FIXUP_CAP_MIX_AMP),
  2875. {}
  2876. };
  2877. static const struct hda_model_fixup cxt5045_fixup_models[] = {
  2878. { .id = CXT_FIXUP_CAP_MIX_AMP, .name = "cap-mix-amp" },
  2879. { .id = CXT_FIXUP_TOSHIBA_P105, .name = "toshiba-p105" },
  2880. { .id = CXT_FIXUP_HP_530, .name = "hp-530" },
  2881. {}
  2882. };
  2883. static const struct snd_pci_quirk cxt5047_fixups[] = {
  2884. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  2885. */
  2886. SND_PCI_QUIRK_VENDOR(0x103c, "HP", CXT_FIXUP_CAP_MIX_AMP_5047),
  2887. {}
  2888. };
  2889. static const struct hda_model_fixup cxt5047_fixup_models[] = {
  2890. { .id = CXT_FIXUP_CAP_MIX_AMP_5047, .name = "cap-mix-amp" },
  2891. {}
  2892. };
  2893. static const struct snd_pci_quirk cxt5051_fixups[] = {
  2894. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
  2895. {}
  2896. };
  2897. static const struct hda_model_fixup cxt5051_fixup_models[] = {
  2898. { .id = CXT_PINCFG_LENOVO_X200, .name = "lenovo-x200" },
  2899. {}
  2900. };
  2901. static const struct snd_pci_quirk cxt5066_fixups[] = {
  2902. SND_PCI_QUIRK(0x1025, 0x0543, "Acer Aspire One 522", CXT_FIXUP_STEREO_DMIC),
  2903. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT_FIXUP_GPIO1),
  2904. SND_PCI_QUIRK(0x1043, 0x138d, "Asus", CXT_FIXUP_HEADPHONE_MIC_PIN),
  2905. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT_FIXUP_OLPC_XO),
  2906. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400", CXT_PINCFG_LENOVO_TP410),
  2907. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo T410", CXT_PINCFG_LENOVO_TP410),
  2908. SND_PCI_QUIRK(0x17aa, 0x215f, "Lenovo T510", CXT_PINCFG_LENOVO_TP410),
  2909. SND_PCI_QUIRK(0x17aa, 0x21ce, "Lenovo T420", CXT_PINCFG_LENOVO_TP410),
  2910. SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520", CXT_PINCFG_LENOVO_TP410),
  2911. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT_PINCFG_LENOVO_TP410),
  2912. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT_PINCFG_LENOVO_TP410),
  2913. SND_PCI_QUIRK(0x17aa, 0x3975, "Lenovo U300s", CXT_FIXUP_STEREO_DMIC),
  2914. SND_PCI_QUIRK(0x17aa, 0x3977, "Lenovo IdeaPad U310", CXT_FIXUP_STEREO_DMIC),
  2915. SND_PCI_QUIRK(0x17aa, 0x397b, "Lenovo S205", CXT_FIXUP_STEREO_DMIC),
  2916. SND_PCI_QUIRK_VENDOR(0x17aa, "Thinkpad", CXT_FIXUP_THINKPAD_ACPI),
  2917. SND_PCI_QUIRK(0x1c06, 0x2011, "Lemote A1004", CXT_PINCFG_LEMOTE_A1004),
  2918. SND_PCI_QUIRK(0x1c06, 0x2012, "Lemote A1205", CXT_PINCFG_LEMOTE_A1205),
  2919. {}
  2920. };
  2921. static const struct hda_model_fixup cxt5066_fixup_models[] = {
  2922. { .id = CXT_FIXUP_STEREO_DMIC, .name = "stereo-dmic" },
  2923. { .id = CXT_FIXUP_GPIO1, .name = "gpio1" },
  2924. { .id = CXT_FIXUP_HEADPHONE_MIC_PIN, .name = "headphone-mic-pin" },
  2925. { .id = CXT_PINCFG_LENOVO_TP410, .name = "tp410" },
  2926. { .id = CXT_FIXUP_THINKPAD_ACPI, .name = "thinkpad" },
  2927. { .id = CXT_PINCFG_LEMOTE_A1004, .name = "lemote-a1004" },
  2928. { .id = CXT_FIXUP_OLPC_XO, .name = "olpc-xo" },
  2929. {}
  2930. };
  2931. /* add "fake" mute amp-caps to DACs on cx5051 so that mixer mute switches
  2932. * can be created (bko#42825)
  2933. */
  2934. static void add_cx5051_fake_mutes(struct hda_codec *codec)
  2935. {
  2936. static hda_nid_t out_nids[] = {
  2937. 0x10, 0x11, 0
  2938. };
  2939. hda_nid_t *p;
  2940. for (p = out_nids; *p; p++)
  2941. snd_hda_override_amp_caps(codec, *p, HDA_OUTPUT,
  2942. AC_AMPCAP_MIN_MUTE |
  2943. query_amp_caps(codec, *p, HDA_OUTPUT));
  2944. }
  2945. static int patch_conexant_auto(struct hda_codec *codec)
  2946. {
  2947. struct conexant_spec *spec;
  2948. int err;
  2949. codec_info(codec, "%s: BIOS auto-probing.\n", codec->chip_name);
  2950. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2951. if (!spec)
  2952. return -ENOMEM;
  2953. snd_hda_gen_spec_init(&spec->gen);
  2954. codec->spec = spec;
  2955. cx_auto_parse_beep(codec);
  2956. cx_auto_parse_eapd(codec);
  2957. spec->gen.own_eapd_ctl = 1;
  2958. if (spec->dynamic_eapd)
  2959. spec->gen.vmaster_mute.hook = cx_auto_vmaster_hook;
  2960. switch (codec->vendor_id) {
  2961. case 0x14f15045:
  2962. codec->single_adc_amp = 1;
  2963. spec->gen.mixer_nid = 0x17;
  2964. spec->gen.add_stereo_mix_input = 1;
  2965. snd_hda_pick_fixup(codec, cxt5045_fixup_models,
  2966. cxt5045_fixups, cxt_fixups);
  2967. break;
  2968. case 0x14f15047:
  2969. codec->pin_amp_workaround = 1;
  2970. spec->gen.mixer_nid = 0x19;
  2971. spec->gen.add_stereo_mix_input = 1;
  2972. snd_hda_pick_fixup(codec, cxt5047_fixup_models,
  2973. cxt5047_fixups, cxt_fixups);
  2974. break;
  2975. case 0x14f15051:
  2976. add_cx5051_fake_mutes(codec);
  2977. codec->pin_amp_workaround = 1;
  2978. snd_hda_pick_fixup(codec, cxt5051_fixup_models,
  2979. cxt5051_fixups, cxt_fixups);
  2980. break;
  2981. default:
  2982. codec->pin_amp_workaround = 1;
  2983. snd_hda_pick_fixup(codec, cxt5066_fixup_models,
  2984. cxt5066_fixups, cxt_fixups);
  2985. break;
  2986. }
  2987. /* Show mute-led control only on HP laptops
  2988. * This is a sort of white-list: on HP laptops, EAPD corresponds
  2989. * only to the mute-LED without actualy amp function. Meanwhile,
  2990. * others may use EAPD really as an amp switch, so it might be
  2991. * not good to expose it blindly.
  2992. */
  2993. switch (codec->subsystem_id >> 16) {
  2994. case 0x103c:
  2995. spec->gen.vmaster_mute_enum = 1;
  2996. break;
  2997. }
  2998. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PRE_PROBE);
  2999. err = snd_hda_parse_pin_defcfg(codec, &spec->gen.autocfg, NULL,
  3000. spec->parse_flags);
  3001. if (err < 0)
  3002. goto error;
  3003. err = snd_hda_gen_parse_auto_config(codec, &spec->gen.autocfg);
  3004. if (err < 0)
  3005. goto error;
  3006. codec->patch_ops = cx_auto_patch_ops;
  3007. /* Some laptops with Conexant chips show stalls in S3 resume,
  3008. * which falls into the single-cmd mode.
  3009. * Better to make reset, then.
  3010. */
  3011. if (!codec->bus->sync_write) {
  3012. codec_info(codec,
  3013. "Enable sync_write for stable communication\n");
  3014. codec->bus->sync_write = 1;
  3015. codec->bus->allow_bus_reset = 1;
  3016. }
  3017. snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
  3018. return 0;
  3019. error:
  3020. cx_auto_free(codec);
  3021. return err;
  3022. }
  3023. #ifndef ENABLE_CXT_STATIC_QUIRKS
  3024. #define patch_cxt5045 patch_conexant_auto
  3025. #define patch_cxt5047 patch_conexant_auto
  3026. #define patch_cxt5051 patch_conexant_auto
  3027. #define patch_cxt5066 patch_conexant_auto
  3028. #endif
  3029. /*
  3030. */
  3031. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3032. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3033. .patch = patch_cxt5045 },
  3034. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  3035. .patch = patch_cxt5047 },
  3036. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  3037. .patch = patch_cxt5051 },
  3038. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  3039. .patch = patch_cxt5066 },
  3040. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  3041. .patch = patch_cxt5066 },
  3042. { .id = 0x14f15068, .name = "CX20584",
  3043. .patch = patch_cxt5066 },
  3044. { .id = 0x14f15069, .name = "CX20585",
  3045. .patch = patch_cxt5066 },
  3046. { .id = 0x14f1506c, .name = "CX20588",
  3047. .patch = patch_cxt5066 },
  3048. { .id = 0x14f1506e, .name = "CX20590",
  3049. .patch = patch_cxt5066 },
  3050. { .id = 0x14f15097, .name = "CX20631",
  3051. .patch = patch_conexant_auto },
  3052. { .id = 0x14f15098, .name = "CX20632",
  3053. .patch = patch_conexant_auto },
  3054. { .id = 0x14f150a1, .name = "CX20641",
  3055. .patch = patch_conexant_auto },
  3056. { .id = 0x14f150a2, .name = "CX20642",
  3057. .patch = patch_conexant_auto },
  3058. { .id = 0x14f150ab, .name = "CX20651",
  3059. .patch = patch_conexant_auto },
  3060. { .id = 0x14f150ac, .name = "CX20652",
  3061. .patch = patch_conexant_auto },
  3062. { .id = 0x14f150b8, .name = "CX20664",
  3063. .patch = patch_conexant_auto },
  3064. { .id = 0x14f150b9, .name = "CX20665",
  3065. .patch = patch_conexant_auto },
  3066. { .id = 0x14f1510f, .name = "CX20751/2",
  3067. .patch = patch_conexant_auto },
  3068. { .id = 0x14f15110, .name = "CX20751/2",
  3069. .patch = patch_conexant_auto },
  3070. { .id = 0x14f15111, .name = "CX20753/4",
  3071. .patch = patch_conexant_auto },
  3072. { .id = 0x14f15113, .name = "CX20755",
  3073. .patch = patch_conexant_auto },
  3074. { .id = 0x14f15114, .name = "CX20756",
  3075. .patch = patch_conexant_auto },
  3076. { .id = 0x14f15115, .name = "CX20757",
  3077. .patch = patch_conexant_auto },
  3078. { .id = 0x14f151d7, .name = "CX20952",
  3079. .patch = patch_conexant_auto },
  3080. {} /* terminator */
  3081. };
  3082. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  3083. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  3084. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  3085. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  3086. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  3087. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  3088. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  3089. MODULE_ALIAS("snd-hda-codec-id:14f1506c");
  3090. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  3091. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  3092. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  3093. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  3094. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  3095. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  3096. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  3097. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  3098. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  3099. MODULE_ALIAS("snd-hda-codec-id:14f1510f");
  3100. MODULE_ALIAS("snd-hda-codec-id:14f15110");
  3101. MODULE_ALIAS("snd-hda-codec-id:14f15111");
  3102. MODULE_ALIAS("snd-hda-codec-id:14f15113");
  3103. MODULE_ALIAS("snd-hda-codec-id:14f15114");
  3104. MODULE_ALIAS("snd-hda-codec-id:14f15115");
  3105. MODULE_ALIAS("snd-hda-codec-id:14f151d7");
  3106. MODULE_LICENSE("GPL");
  3107. MODULE_DESCRIPTION("Conexant HD-audio codec");
  3108. static struct hda_codec_preset_list conexant_list = {
  3109. .preset = snd_hda_preset_conexant,
  3110. .owner = THIS_MODULE,
  3111. };
  3112. static int __init patch_conexant_init(void)
  3113. {
  3114. return snd_hda_add_codec_preset(&conexant_list);
  3115. }
  3116. static void __exit patch_conexant_exit(void)
  3117. {
  3118. snd_hda_delete_codec_preset(&conexant_list);
  3119. }
  3120. module_init(patch_conexant_init)
  3121. module_exit(patch_conexant_exit)