patch_conexant.c 105 KB

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