patch_conexant.c 126 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247
  1. /*
  2. * HD audio interface patch for Conexant HDA audio codec
  3. *
  4. * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
  5. * Takashi Iwai <tiwai@suse.de>
  6. * Tobin Davis <tdavis@dsl-only.net>
  7. *
  8. * This driver is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This driver is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <sound/core.h>
  27. #include <sound/jack.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #include "hda_beep.h"
  31. #define CXT_PIN_DIR_IN 0x00
  32. #define CXT_PIN_DIR_OUT 0x01
  33. #define CXT_PIN_DIR_INOUT 0x02
  34. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  35. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  36. #define CONEXANT_HP_EVENT 0x37
  37. #define CONEXANT_MIC_EVENT 0x38
  38. /* Conexant 5051 specific */
  39. #define CXT5051_SPDIF_OUT 0x12
  40. #define CXT5051_PORTB_EVENT 0x38
  41. #define CXT5051_PORTC_EVENT 0x39
  42. #define AUTO_MIC_PORTB (1 << 1)
  43. #define AUTO_MIC_PORTC (1 << 2)
  44. struct pin_dac_pair {
  45. hda_nid_t pin;
  46. hda_nid_t dac;
  47. int type;
  48. };
  49. struct imux_info {
  50. hda_nid_t pin; /* input pin NID */
  51. hda_nid_t adc; /* connected ADC NID */
  52. hda_nid_t boost; /* optional boost volume NID */
  53. int index; /* corresponding to autocfg.input */
  54. };
  55. struct conexant_spec {
  56. const struct snd_kcontrol_new *mixers[5];
  57. int num_mixers;
  58. hda_nid_t vmaster_nid;
  59. const struct hda_verb *init_verbs[5]; /* initialization verbs
  60. * don't forget NULL
  61. * termination!
  62. */
  63. unsigned int num_init_verbs;
  64. /* playback */
  65. struct hda_multi_out multiout; /* playback set-up
  66. * max_channels, dacs must be set
  67. * dig_out_nid and hp_nid are optional
  68. */
  69. unsigned int cur_eapd;
  70. unsigned int hp_present;
  71. unsigned int auto_mic;
  72. int auto_mic_ext; /* imux_pins[] index for ext mic */
  73. unsigned int need_dac_fix;
  74. hda_nid_t slave_dig_outs[2];
  75. /* capture */
  76. unsigned int num_adc_nids;
  77. const hda_nid_t *adc_nids;
  78. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  79. unsigned int cur_adc_idx;
  80. hda_nid_t cur_adc;
  81. unsigned int cur_adc_stream_tag;
  82. unsigned int cur_adc_format;
  83. const struct hda_pcm_stream *capture_stream;
  84. /* capture source */
  85. const struct hda_input_mux *input_mux;
  86. const hda_nid_t *capsrc_nids;
  87. unsigned int cur_mux[3];
  88. /* channel model */
  89. const struct hda_channel_mode *channel_mode;
  90. int num_channel_mode;
  91. /* PCM information */
  92. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  93. unsigned int spdif_route;
  94. /* dynamic controls, init_verbs and input_mux */
  95. struct auto_pin_cfg autocfg;
  96. struct hda_input_mux private_imux;
  97. struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
  98. hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
  99. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  100. struct pin_dac_pair dac_info[8];
  101. int dac_info_filled;
  102. unsigned int port_d_mode;
  103. unsigned int auto_mute:1; /* used in auto-parser */
  104. unsigned int dell_automute:1;
  105. unsigned int dell_vostro:1;
  106. unsigned int ideapad:1;
  107. unsigned int thinkpad:1;
  108. unsigned int hp_laptop:1;
  109. unsigned int asus:1;
  110. unsigned int adc_switching:1;
  111. unsigned int ext_mic_present;
  112. unsigned int recording;
  113. void (*capture_prepare)(struct hda_codec *codec);
  114. void (*capture_cleanup)(struct hda_codec *codec);
  115. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  116. * through the microphone jack.
  117. * When the user enables this through a mixer switch, both internal and
  118. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  119. * we also allow the bias to be configured through a separate mixer
  120. * control. */
  121. unsigned int dc_enable;
  122. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  123. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  124. unsigned int beep_amp;
  125. };
  126. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  127. struct hda_codec *codec,
  128. struct snd_pcm_substream *substream)
  129. {
  130. struct conexant_spec *spec = codec->spec;
  131. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  132. hinfo);
  133. }
  134. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  135. struct hda_codec *codec,
  136. unsigned int stream_tag,
  137. unsigned int format,
  138. struct snd_pcm_substream *substream)
  139. {
  140. struct conexant_spec *spec = codec->spec;
  141. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  142. stream_tag,
  143. format, substream);
  144. }
  145. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  146. struct hda_codec *codec,
  147. struct snd_pcm_substream *substream)
  148. {
  149. struct conexant_spec *spec = codec->spec;
  150. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  151. }
  152. /*
  153. * Digital out
  154. */
  155. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  156. struct hda_codec *codec,
  157. struct snd_pcm_substream *substream)
  158. {
  159. struct conexant_spec *spec = codec->spec;
  160. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  161. }
  162. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  163. struct hda_codec *codec,
  164. struct snd_pcm_substream *substream)
  165. {
  166. struct conexant_spec *spec = codec->spec;
  167. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  168. }
  169. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  170. struct hda_codec *codec,
  171. unsigned int stream_tag,
  172. unsigned int format,
  173. struct snd_pcm_substream *substream)
  174. {
  175. struct conexant_spec *spec = codec->spec;
  176. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  177. stream_tag,
  178. format, substream);
  179. }
  180. /*
  181. * Analog capture
  182. */
  183. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  184. struct hda_codec *codec,
  185. unsigned int stream_tag,
  186. unsigned int format,
  187. struct snd_pcm_substream *substream)
  188. {
  189. struct conexant_spec *spec = codec->spec;
  190. if (spec->capture_prepare)
  191. spec->capture_prepare(codec);
  192. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  193. stream_tag, 0, format);
  194. return 0;
  195. }
  196. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  197. struct hda_codec *codec,
  198. struct snd_pcm_substream *substream)
  199. {
  200. struct conexant_spec *spec = codec->spec;
  201. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  202. if (spec->capture_cleanup)
  203. spec->capture_cleanup(codec);
  204. return 0;
  205. }
  206. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  207. .substreams = 1,
  208. .channels_min = 2,
  209. .channels_max = 2,
  210. .nid = 0, /* fill later */
  211. .ops = {
  212. .open = conexant_playback_pcm_open,
  213. .prepare = conexant_playback_pcm_prepare,
  214. .cleanup = conexant_playback_pcm_cleanup
  215. },
  216. };
  217. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  218. .substreams = 1,
  219. .channels_min = 2,
  220. .channels_max = 2,
  221. .nid = 0, /* fill later */
  222. .ops = {
  223. .prepare = conexant_capture_pcm_prepare,
  224. .cleanup = conexant_capture_pcm_cleanup
  225. },
  226. };
  227. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  228. .substreams = 1,
  229. .channels_min = 2,
  230. .channels_max = 2,
  231. .nid = 0, /* fill later */
  232. .ops = {
  233. .open = conexant_dig_playback_pcm_open,
  234. .close = conexant_dig_playback_pcm_close,
  235. .prepare = conexant_dig_playback_pcm_prepare
  236. },
  237. };
  238. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  239. .substreams = 1,
  240. .channels_min = 2,
  241. .channels_max = 2,
  242. /* NID is set in alc_build_pcms */
  243. };
  244. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  245. struct hda_codec *codec,
  246. unsigned int stream_tag,
  247. unsigned int format,
  248. struct snd_pcm_substream *substream)
  249. {
  250. struct conexant_spec *spec = codec->spec;
  251. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  252. spec->cur_adc_stream_tag = stream_tag;
  253. spec->cur_adc_format = format;
  254. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  255. return 0;
  256. }
  257. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  258. struct hda_codec *codec,
  259. struct snd_pcm_substream *substream)
  260. {
  261. struct conexant_spec *spec = codec->spec;
  262. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  263. spec->cur_adc = 0;
  264. return 0;
  265. }
  266. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  267. .substreams = 1,
  268. .channels_min = 2,
  269. .channels_max = 2,
  270. .nid = 0, /* fill later */
  271. .ops = {
  272. .prepare = cx5051_capture_pcm_prepare,
  273. .cleanup = cx5051_capture_pcm_cleanup
  274. },
  275. };
  276. static int conexant_build_pcms(struct hda_codec *codec)
  277. {
  278. struct conexant_spec *spec = codec->spec;
  279. struct hda_pcm *info = spec->pcm_rec;
  280. codec->num_pcms = 1;
  281. codec->pcm_info = info;
  282. info->name = "CONEXANT Analog";
  283. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  284. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  285. spec->multiout.max_channels;
  286. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  287. spec->multiout.dac_nids[0];
  288. if (spec->capture_stream)
  289. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  290. else {
  291. if (codec->vendor_id == 0x14f15051)
  292. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  293. cx5051_pcm_analog_capture;
  294. else {
  295. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  296. conexant_pcm_analog_capture;
  297. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  298. spec->num_adc_nids;
  299. }
  300. }
  301. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  302. if (spec->multiout.dig_out_nid) {
  303. info++;
  304. codec->num_pcms++;
  305. info->name = "Conexant Digital";
  306. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  307. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  308. conexant_pcm_digital_playback;
  309. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  310. spec->multiout.dig_out_nid;
  311. if (spec->dig_in_nid) {
  312. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  313. conexant_pcm_digital_capture;
  314. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  315. spec->dig_in_nid;
  316. }
  317. if (spec->slave_dig_outs[0])
  318. codec->slave_dig_outs = spec->slave_dig_outs;
  319. }
  320. return 0;
  321. }
  322. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  323. struct snd_ctl_elem_info *uinfo)
  324. {
  325. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  326. struct conexant_spec *spec = codec->spec;
  327. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  328. }
  329. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  330. struct snd_ctl_elem_value *ucontrol)
  331. {
  332. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  333. struct conexant_spec *spec = codec->spec;
  334. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  335. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  336. return 0;
  337. }
  338. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  339. struct snd_ctl_elem_value *ucontrol)
  340. {
  341. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  342. struct conexant_spec *spec = codec->spec;
  343. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  344. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  345. spec->capsrc_nids[adc_idx],
  346. &spec->cur_mux[adc_idx]);
  347. }
  348. static int conexant_init_jacks(struct hda_codec *codec)
  349. {
  350. #ifdef CONFIG_SND_HDA_INPUT_JACK
  351. struct conexant_spec *spec = codec->spec;
  352. int i;
  353. for (i = 0; i < spec->num_init_verbs; i++) {
  354. const struct hda_verb *hv;
  355. hv = spec->init_verbs[i];
  356. while (hv->nid) {
  357. int err = 0;
  358. switch (hv->param ^ AC_USRSP_EN) {
  359. case CONEXANT_HP_EVENT:
  360. err = snd_hda_input_jack_add(codec, hv->nid,
  361. SND_JACK_HEADPHONE, NULL);
  362. snd_hda_input_jack_report(codec, hv->nid);
  363. break;
  364. case CXT5051_PORTC_EVENT:
  365. case CONEXANT_MIC_EVENT:
  366. err = snd_hda_input_jack_add(codec, hv->nid,
  367. SND_JACK_MICROPHONE, NULL);
  368. snd_hda_input_jack_report(codec, hv->nid);
  369. break;
  370. }
  371. if (err < 0)
  372. return err;
  373. ++hv;
  374. }
  375. }
  376. #endif /* CONFIG_SND_HDA_INPUT_JACK */
  377. return 0;
  378. }
  379. static int conexant_init(struct hda_codec *codec)
  380. {
  381. struct conexant_spec *spec = codec->spec;
  382. int i;
  383. for (i = 0; i < spec->num_init_verbs; i++)
  384. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  385. return 0;
  386. }
  387. static void conexant_free(struct hda_codec *codec)
  388. {
  389. snd_hda_input_jack_free(codec);
  390. snd_hda_detach_beep_device(codec);
  391. kfree(codec->spec);
  392. }
  393. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  394. {
  395. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  396. .name = "Capture Source",
  397. .info = conexant_mux_enum_info,
  398. .get = conexant_mux_enum_get,
  399. .put = conexant_mux_enum_put
  400. },
  401. {}
  402. };
  403. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  404. /* additional beep mixers; the actual parameters are overwritten at build */
  405. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  406. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  407. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  408. { } /* end */
  409. };
  410. #endif
  411. static const char * const slave_vols[] = {
  412. "Headphone Playback Volume",
  413. "Speaker Playback Volume",
  414. NULL
  415. };
  416. static const char * const slave_sws[] = {
  417. "Headphone Playback Switch",
  418. "Speaker Playback Switch",
  419. NULL
  420. };
  421. static int conexant_build_controls(struct hda_codec *codec)
  422. {
  423. struct conexant_spec *spec = codec->spec;
  424. unsigned int i;
  425. int err;
  426. for (i = 0; i < spec->num_mixers; i++) {
  427. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  428. if (err < 0)
  429. return err;
  430. }
  431. if (spec->multiout.dig_out_nid) {
  432. err = snd_hda_create_spdif_out_ctls(codec,
  433. spec->multiout.dig_out_nid);
  434. if (err < 0)
  435. return err;
  436. err = snd_hda_create_spdif_share_sw(codec,
  437. &spec->multiout);
  438. if (err < 0)
  439. return err;
  440. spec->multiout.share_spdif = 1;
  441. }
  442. if (spec->dig_in_nid) {
  443. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  444. if (err < 0)
  445. return err;
  446. }
  447. /* if we have no master control, let's create it */
  448. if (spec->vmaster_nid &&
  449. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  450. unsigned int vmaster_tlv[4];
  451. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  452. HDA_OUTPUT, vmaster_tlv);
  453. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  454. vmaster_tlv, slave_vols);
  455. if (err < 0)
  456. return err;
  457. }
  458. if (spec->vmaster_nid &&
  459. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  460. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  461. NULL, slave_sws);
  462. if (err < 0)
  463. return err;
  464. }
  465. if (spec->input_mux) {
  466. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  467. if (err < 0)
  468. return err;
  469. }
  470. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  471. /* create beep controls if needed */
  472. if (spec->beep_amp) {
  473. const struct snd_kcontrol_new *knew;
  474. for (knew = cxt_beep_mixer; knew->name; knew++) {
  475. struct snd_kcontrol *kctl;
  476. kctl = snd_ctl_new1(knew, codec);
  477. if (!kctl)
  478. return -ENOMEM;
  479. kctl->private_value = spec->beep_amp;
  480. err = snd_hda_ctl_add(codec, 0, kctl);
  481. if (err < 0)
  482. return err;
  483. }
  484. }
  485. #endif
  486. return 0;
  487. }
  488. #ifdef CONFIG_SND_HDA_POWER_SAVE
  489. static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
  490. {
  491. snd_hda_shutup_pins(codec);
  492. return 0;
  493. }
  494. #endif
  495. static const struct hda_codec_ops conexant_patch_ops = {
  496. .build_controls = conexant_build_controls,
  497. .build_pcms = conexant_build_pcms,
  498. .init = conexant_init,
  499. .free = conexant_free,
  500. #ifdef CONFIG_SND_HDA_POWER_SAVE
  501. .suspend = conexant_suspend,
  502. #endif
  503. .reboot_notify = snd_hda_shutup_pins,
  504. };
  505. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  506. #define set_beep_amp(spec, nid, idx, dir) \
  507. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
  508. #else
  509. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  510. #endif
  511. static int patch_conexant_auto(struct hda_codec *codec);
  512. /*
  513. * EAPD control
  514. * the private value = nid | (invert << 8)
  515. */
  516. #define cxt_eapd_info snd_ctl_boolean_mono_info
  517. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  518. struct snd_ctl_elem_value *ucontrol)
  519. {
  520. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  521. struct conexant_spec *spec = codec->spec;
  522. int invert = (kcontrol->private_value >> 8) & 1;
  523. if (invert)
  524. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  525. else
  526. ucontrol->value.integer.value[0] = spec->cur_eapd;
  527. return 0;
  528. }
  529. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  530. struct snd_ctl_elem_value *ucontrol)
  531. {
  532. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  533. struct conexant_spec *spec = codec->spec;
  534. int invert = (kcontrol->private_value >> 8) & 1;
  535. hda_nid_t nid = kcontrol->private_value & 0xff;
  536. unsigned int eapd;
  537. eapd = !!ucontrol->value.integer.value[0];
  538. if (invert)
  539. eapd = !eapd;
  540. if (eapd == spec->cur_eapd)
  541. return 0;
  542. spec->cur_eapd = eapd;
  543. snd_hda_codec_write_cache(codec, nid,
  544. 0, AC_VERB_SET_EAPD_BTLENABLE,
  545. eapd ? 0x02 : 0x00);
  546. return 1;
  547. }
  548. /* controls for test mode */
  549. #ifdef CONFIG_SND_DEBUG
  550. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  551. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  552. .info = cxt_eapd_info, \
  553. .get = cxt_eapd_get, \
  554. .put = cxt_eapd_put, \
  555. .private_value = nid | (mask<<16) }
  556. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  557. struct snd_ctl_elem_info *uinfo)
  558. {
  559. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  560. struct conexant_spec *spec = codec->spec;
  561. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  562. spec->num_channel_mode);
  563. }
  564. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  565. struct snd_ctl_elem_value *ucontrol)
  566. {
  567. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  568. struct conexant_spec *spec = codec->spec;
  569. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  570. spec->num_channel_mode,
  571. spec->multiout.max_channels);
  572. }
  573. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  574. struct snd_ctl_elem_value *ucontrol)
  575. {
  576. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  577. struct conexant_spec *spec = codec->spec;
  578. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  579. spec->num_channel_mode,
  580. &spec->multiout.max_channels);
  581. if (err >= 0 && spec->need_dac_fix)
  582. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  583. return err;
  584. }
  585. #define CXT_PIN_MODE(xname, nid, dir) \
  586. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  587. .info = conexant_ch_mode_info, \
  588. .get = conexant_ch_mode_get, \
  589. .put = conexant_ch_mode_put, \
  590. .private_value = nid | (dir<<16) }
  591. #endif /* CONFIG_SND_DEBUG */
  592. /* Conexant 5045 specific */
  593. static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  594. static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  595. static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  596. #define CXT5045_SPDIF_OUT 0x18
  597. static const struct hda_channel_mode cxt5045_modes[1] = {
  598. { 2, NULL },
  599. };
  600. static const struct hda_input_mux cxt5045_capture_source = {
  601. .num_items = 2,
  602. .items = {
  603. { "IntMic", 0x1 },
  604. { "ExtMic", 0x2 },
  605. }
  606. };
  607. static const struct hda_input_mux cxt5045_capture_source_benq = {
  608. .num_items = 5,
  609. .items = {
  610. { "IntMic", 0x1 },
  611. { "ExtMic", 0x2 },
  612. { "LineIn", 0x3 },
  613. { "CD", 0x4 },
  614. { "Mixer", 0x0 },
  615. }
  616. };
  617. static const struct hda_input_mux cxt5045_capture_source_hp530 = {
  618. .num_items = 2,
  619. .items = {
  620. { "ExtMic", 0x1 },
  621. { "IntMic", 0x2 },
  622. }
  623. };
  624. /* turn on/off EAPD (+ mute HP) as a master switch */
  625. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  626. struct snd_ctl_elem_value *ucontrol)
  627. {
  628. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  629. struct conexant_spec *spec = codec->spec;
  630. unsigned int bits;
  631. if (!cxt_eapd_put(kcontrol, ucontrol))
  632. return 0;
  633. /* toggle internal speakers mute depending of presence of
  634. * the headphone jack
  635. */
  636. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  637. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  638. HDA_AMP_MUTE, bits);
  639. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  640. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  641. HDA_AMP_MUTE, bits);
  642. return 1;
  643. }
  644. /* bind volumes of both NID 0x10 and 0x11 */
  645. static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  646. .ops = &snd_hda_bind_vol,
  647. .values = {
  648. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  649. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  650. 0
  651. },
  652. };
  653. /* toggle input of built-in and mic jack appropriately */
  654. static void cxt5045_hp_automic(struct hda_codec *codec)
  655. {
  656. static const struct hda_verb mic_jack_on[] = {
  657. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  658. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  659. {}
  660. };
  661. static const struct hda_verb mic_jack_off[] = {
  662. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  663. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  664. {}
  665. };
  666. unsigned int present;
  667. present = snd_hda_jack_detect(codec, 0x12);
  668. if (present)
  669. snd_hda_sequence_write(codec, mic_jack_on);
  670. else
  671. snd_hda_sequence_write(codec, mic_jack_off);
  672. }
  673. /* mute internal speaker if HP is plugged */
  674. static void cxt5045_hp_automute(struct hda_codec *codec)
  675. {
  676. struct conexant_spec *spec = codec->spec;
  677. unsigned int bits;
  678. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  679. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  680. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  681. HDA_AMP_MUTE, bits);
  682. }
  683. /* unsolicited event for HP jack sensing */
  684. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  685. unsigned int res)
  686. {
  687. res >>= 26;
  688. switch (res) {
  689. case CONEXANT_HP_EVENT:
  690. cxt5045_hp_automute(codec);
  691. break;
  692. case CONEXANT_MIC_EVENT:
  693. cxt5045_hp_automic(codec);
  694. break;
  695. }
  696. }
  697. static const struct snd_kcontrol_new cxt5045_mixers[] = {
  698. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  699. HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  700. HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  701. HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  702. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  703. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  704. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  705. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  706. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  707. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  708. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  709. {
  710. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  711. .name = "Master Playback Switch",
  712. .info = cxt_eapd_info,
  713. .get = cxt_eapd_get,
  714. .put = cxt5045_hp_master_sw_put,
  715. .private_value = 0x10,
  716. },
  717. {}
  718. };
  719. static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  720. HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
  721. HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
  722. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
  723. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
  724. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  725. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  726. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  727. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  728. HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
  729. HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
  730. {}
  731. };
  732. static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  733. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  734. HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  735. HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  736. HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  737. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  738. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  739. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  740. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  741. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  742. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  743. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  744. {
  745. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  746. .name = "Master Playback Switch",
  747. .info = cxt_eapd_info,
  748. .get = cxt_eapd_get,
  749. .put = cxt5045_hp_master_sw_put,
  750. .private_value = 0x10,
  751. },
  752. {}
  753. };
  754. static const struct hda_verb cxt5045_init_verbs[] = {
  755. /* Line in, Mic */
  756. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  757. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  758. /* HP, Amp */
  759. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  760. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  761. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  762. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  763. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  764. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  765. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  766. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  767. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  768. /* Record selector: Internal mic */
  769. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  770. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  771. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  772. /* SPDIF route: PCM */
  773. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  774. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  775. /* EAPD */
  776. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  777. { } /* end */
  778. };
  779. static const struct hda_verb cxt5045_benq_init_verbs[] = {
  780. /* Internal Mic, Mic */
  781. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  782. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  783. /* Line In,HP, Amp */
  784. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  785. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  786. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  787. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  788. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  789. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  790. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  791. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  792. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  793. /* Record selector: Internal mic */
  794. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  795. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  796. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  797. /* SPDIF route: PCM */
  798. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  799. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  800. /* EAPD */
  801. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  802. { } /* end */
  803. };
  804. static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  805. /* pin sensing on HP jack */
  806. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  807. { } /* end */
  808. };
  809. static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  810. /* pin sensing on HP jack */
  811. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  812. { } /* end */
  813. };
  814. #ifdef CONFIG_SND_DEBUG
  815. /* Test configuration for debugging, modelled after the ALC260 test
  816. * configuration.
  817. */
  818. static const struct hda_input_mux cxt5045_test_capture_source = {
  819. .num_items = 5,
  820. .items = {
  821. { "MIXER", 0x0 },
  822. { "MIC1 pin", 0x1 },
  823. { "LINE1 pin", 0x2 },
  824. { "HP-OUT pin", 0x3 },
  825. { "CD pin", 0x4 },
  826. },
  827. };
  828. static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
  829. /* Output controls */
  830. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  831. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  832. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  833. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  834. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  835. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  836. /* Modes for retasking pin widgets */
  837. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  838. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  839. /* EAPD Switch Control */
  840. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  841. /* Loopback mixer controls */
  842. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  843. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  844. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  845. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  846. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  847. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  848. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  849. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  850. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  851. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  852. {
  853. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  854. .name = "Input Source",
  855. .info = conexant_mux_enum_info,
  856. .get = conexant_mux_enum_get,
  857. .put = conexant_mux_enum_put,
  858. },
  859. /* Audio input controls */
  860. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  861. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  862. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  863. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  864. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  865. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  866. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  867. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  868. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  869. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  870. { } /* end */
  871. };
  872. static const struct hda_verb cxt5045_test_init_verbs[] = {
  873. /* Set connections */
  874. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  875. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  876. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  877. /* Enable retasking pins as output, initially without power amp */
  878. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  879. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  880. /* Disable digital (SPDIF) pins initially, but users can enable
  881. * them via a mixer switch. In the case of SPDIF-out, this initverb
  882. * payload also sets the generation to 0, output to be in "consumer"
  883. * PCM format, copyright asserted, no pre-emphasis and no validity
  884. * control.
  885. */
  886. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  887. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  888. /* Start with output sum widgets muted and their output gains at min */
  889. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  890. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  891. /* Unmute retasking pin widget output buffers since the default
  892. * state appears to be output. As the pin mode is changed by the
  893. * user the pin mode control will take care of enabling the pin's
  894. * input/output buffers as needed.
  895. */
  896. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  897. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  898. /* Mute capture amp left and right */
  899. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  900. /* Set ADC connection select to match default mixer setting (mic1
  901. * pin)
  902. */
  903. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  904. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  905. /* Mute all inputs to mixer widget (even unconnected ones) */
  906. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  907. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  908. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  909. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  910. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  911. { }
  912. };
  913. #endif
  914. /* initialize jack-sensing, too */
  915. static int cxt5045_init(struct hda_codec *codec)
  916. {
  917. conexant_init(codec);
  918. cxt5045_hp_automute(codec);
  919. return 0;
  920. }
  921. enum {
  922. CXT5045_LAPTOP_HPSENSE,
  923. CXT5045_LAPTOP_MICSENSE,
  924. CXT5045_LAPTOP_HPMICSENSE,
  925. CXT5045_BENQ,
  926. CXT5045_LAPTOP_HP530,
  927. #ifdef CONFIG_SND_DEBUG
  928. CXT5045_TEST,
  929. #endif
  930. CXT5045_AUTO,
  931. CXT5045_MODELS
  932. };
  933. static const char * const cxt5045_models[CXT5045_MODELS] = {
  934. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  935. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  936. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  937. [CXT5045_BENQ] = "benq",
  938. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  939. #ifdef CONFIG_SND_DEBUG
  940. [CXT5045_TEST] = "test",
  941. #endif
  942. [CXT5045_AUTO] = "auto",
  943. };
  944. static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  945. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  946. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  947. CXT5045_LAPTOP_HPSENSE),
  948. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  949. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  950. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  951. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  952. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  953. CXT5045_LAPTOP_HPMICSENSE),
  954. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  955. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  956. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  957. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  958. CXT5045_LAPTOP_HPMICSENSE),
  959. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  960. {}
  961. };
  962. static int patch_cxt5045(struct hda_codec *codec)
  963. {
  964. struct conexant_spec *spec;
  965. int board_config;
  966. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  967. cxt5045_models,
  968. cxt5045_cfg_tbl);
  969. #if 0 /* use the old method just for safety */
  970. if (board_config < 0)
  971. board_config = CXT5045_AUTO;
  972. #endif
  973. if (board_config == CXT5045_AUTO)
  974. return patch_conexant_auto(codec);
  975. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  976. if (!spec)
  977. return -ENOMEM;
  978. codec->spec = spec;
  979. codec->pin_amp_workaround = 1;
  980. spec->multiout.max_channels = 2;
  981. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  982. spec->multiout.dac_nids = cxt5045_dac_nids;
  983. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  984. spec->num_adc_nids = 1;
  985. spec->adc_nids = cxt5045_adc_nids;
  986. spec->capsrc_nids = cxt5045_capsrc_nids;
  987. spec->input_mux = &cxt5045_capture_source;
  988. spec->num_mixers = 1;
  989. spec->mixers[0] = cxt5045_mixers;
  990. spec->num_init_verbs = 1;
  991. spec->init_verbs[0] = cxt5045_init_verbs;
  992. spec->spdif_route = 0;
  993. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
  994. spec->channel_mode = cxt5045_modes;
  995. set_beep_amp(spec, 0x16, 0, 1);
  996. codec->patch_ops = conexant_patch_ops;
  997. switch (board_config) {
  998. case CXT5045_LAPTOP_HPSENSE:
  999. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1000. spec->input_mux = &cxt5045_capture_source;
  1001. spec->num_init_verbs = 2;
  1002. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1003. spec->mixers[0] = cxt5045_mixers;
  1004. codec->patch_ops.init = cxt5045_init;
  1005. break;
  1006. case CXT5045_LAPTOP_MICSENSE:
  1007. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1008. spec->input_mux = &cxt5045_capture_source;
  1009. spec->num_init_verbs = 2;
  1010. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  1011. spec->mixers[0] = cxt5045_mixers;
  1012. codec->patch_ops.init = cxt5045_init;
  1013. break;
  1014. default:
  1015. case CXT5045_LAPTOP_HPMICSENSE:
  1016. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1017. spec->input_mux = &cxt5045_capture_source;
  1018. spec->num_init_verbs = 3;
  1019. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1020. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  1021. spec->mixers[0] = cxt5045_mixers;
  1022. codec->patch_ops.init = cxt5045_init;
  1023. break;
  1024. case CXT5045_BENQ:
  1025. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1026. spec->input_mux = &cxt5045_capture_source_benq;
  1027. spec->num_init_verbs = 1;
  1028. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  1029. spec->mixers[0] = cxt5045_mixers;
  1030. spec->mixers[1] = cxt5045_benq_mixers;
  1031. spec->num_mixers = 2;
  1032. codec->patch_ops.init = cxt5045_init;
  1033. break;
  1034. case CXT5045_LAPTOP_HP530:
  1035. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1036. spec->input_mux = &cxt5045_capture_source_hp530;
  1037. spec->num_init_verbs = 2;
  1038. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1039. spec->mixers[0] = cxt5045_mixers_hp530;
  1040. codec->patch_ops.init = cxt5045_init;
  1041. break;
  1042. #ifdef CONFIG_SND_DEBUG
  1043. case CXT5045_TEST:
  1044. spec->input_mux = &cxt5045_test_capture_source;
  1045. spec->mixers[0] = cxt5045_test_mixer;
  1046. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1047. break;
  1048. #endif
  1049. }
  1050. switch (codec->subsystem_id >> 16) {
  1051. case 0x103c:
  1052. case 0x1631:
  1053. case 0x1734:
  1054. case 0x17aa:
  1055. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  1056. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  1057. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  1058. */
  1059. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1060. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1061. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1062. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1063. (1 << AC_AMPCAP_MUTE_SHIFT));
  1064. break;
  1065. }
  1066. if (spec->beep_amp)
  1067. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1068. return 0;
  1069. }
  1070. /* Conexant 5047 specific */
  1071. #define CXT5047_SPDIF_OUT 0x11
  1072. static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1073. static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1074. static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1075. static const struct hda_channel_mode cxt5047_modes[1] = {
  1076. { 2, NULL },
  1077. };
  1078. static const struct hda_input_mux cxt5047_toshiba_capture_source = {
  1079. .num_items = 2,
  1080. .items = {
  1081. { "ExtMic", 0x2 },
  1082. { "Line-In", 0x1 },
  1083. }
  1084. };
  1085. /* turn on/off EAPD (+ mute HP) as a master switch */
  1086. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1087. struct snd_ctl_elem_value *ucontrol)
  1088. {
  1089. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1090. struct conexant_spec *spec = codec->spec;
  1091. unsigned int bits;
  1092. if (!cxt_eapd_put(kcontrol, ucontrol))
  1093. return 0;
  1094. /* toggle internal speakers mute depending of presence of
  1095. * the headphone jack
  1096. */
  1097. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1098. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1099. * pin widgets unlike other codecs. In this case, we need to
  1100. * set index 0x01 for the volume from the mixer amp 0x19.
  1101. */
  1102. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1103. HDA_AMP_MUTE, bits);
  1104. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1105. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1106. HDA_AMP_MUTE, bits);
  1107. return 1;
  1108. }
  1109. /* mute internal speaker if HP is plugged */
  1110. static void cxt5047_hp_automute(struct hda_codec *codec)
  1111. {
  1112. struct conexant_spec *spec = codec->spec;
  1113. unsigned int bits;
  1114. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1115. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1116. /* See the note in cxt5047_hp_master_sw_put */
  1117. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1118. HDA_AMP_MUTE, bits);
  1119. }
  1120. /* toggle input of built-in and mic jack appropriately */
  1121. static void cxt5047_hp_automic(struct hda_codec *codec)
  1122. {
  1123. static const struct hda_verb mic_jack_on[] = {
  1124. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1125. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1126. {}
  1127. };
  1128. static const struct hda_verb mic_jack_off[] = {
  1129. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1130. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1131. {}
  1132. };
  1133. unsigned int present;
  1134. present = snd_hda_jack_detect(codec, 0x15);
  1135. if (present)
  1136. snd_hda_sequence_write(codec, mic_jack_on);
  1137. else
  1138. snd_hda_sequence_write(codec, mic_jack_off);
  1139. }
  1140. /* unsolicited event for HP jack sensing */
  1141. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1142. unsigned int res)
  1143. {
  1144. switch (res >> 26) {
  1145. case CONEXANT_HP_EVENT:
  1146. cxt5047_hp_automute(codec);
  1147. break;
  1148. case CONEXANT_MIC_EVENT:
  1149. cxt5047_hp_automic(codec);
  1150. break;
  1151. }
  1152. }
  1153. static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1154. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1155. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1156. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1157. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1158. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1159. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1160. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1161. {
  1162. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1163. .name = "Master Playback Switch",
  1164. .info = cxt_eapd_info,
  1165. .get = cxt_eapd_get,
  1166. .put = cxt5047_hp_master_sw_put,
  1167. .private_value = 0x13,
  1168. },
  1169. {}
  1170. };
  1171. static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1172. /* See the note in cxt5047_hp_master_sw_put */
  1173. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1174. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1175. {}
  1176. };
  1177. static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1178. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1179. { } /* end */
  1180. };
  1181. static const struct hda_verb cxt5047_init_verbs[] = {
  1182. /* Line in, Mic, Built-in Mic */
  1183. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1184. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1185. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1186. /* HP, Speaker */
  1187. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1188. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1189. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1190. /* Record selector: Mic */
  1191. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1192. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1193. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1194. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1195. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1196. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1197. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1198. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1199. /* SPDIF route: PCM */
  1200. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1201. /* Enable unsolicited events */
  1202. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1203. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1204. { } /* end */
  1205. };
  1206. /* configuration for Toshiba Laptops */
  1207. static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1208. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1209. {}
  1210. };
  1211. /* Test configuration for debugging, modelled after the ALC260 test
  1212. * configuration.
  1213. */
  1214. #ifdef CONFIG_SND_DEBUG
  1215. static const struct hda_input_mux cxt5047_test_capture_source = {
  1216. .num_items = 4,
  1217. .items = {
  1218. { "LINE1 pin", 0x0 },
  1219. { "MIC1 pin", 0x1 },
  1220. { "MIC2 pin", 0x2 },
  1221. { "CD pin", 0x3 },
  1222. },
  1223. };
  1224. static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1225. /* Output only controls */
  1226. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1227. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1228. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1229. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1230. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1231. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1232. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1233. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1234. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1235. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1236. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1237. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1238. /* Modes for retasking pin widgets */
  1239. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1240. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1241. /* EAPD Switch Control */
  1242. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1243. /* Loopback mixer controls */
  1244. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1245. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1246. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1247. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1248. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1249. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1250. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1251. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1252. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1253. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1254. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1255. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1256. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1257. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1258. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1259. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1260. {
  1261. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1262. .name = "Input Source",
  1263. .info = conexant_mux_enum_info,
  1264. .get = conexant_mux_enum_get,
  1265. .put = conexant_mux_enum_put,
  1266. },
  1267. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1268. { } /* end */
  1269. };
  1270. static const struct hda_verb cxt5047_test_init_verbs[] = {
  1271. /* Enable retasking pins as output, initially without power amp */
  1272. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1273. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1274. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1275. /* Disable digital (SPDIF) pins initially, but users can enable
  1276. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1277. * payload also sets the generation to 0, output to be in "consumer"
  1278. * PCM format, copyright asserted, no pre-emphasis and no validity
  1279. * control.
  1280. */
  1281. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1282. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1283. * OUT1 sum bus when acting as an output.
  1284. */
  1285. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1286. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1287. /* Start with output sum widgets muted and their output gains at min */
  1288. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1289. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1290. /* Unmute retasking pin widget output buffers since the default
  1291. * state appears to be output. As the pin mode is changed by the
  1292. * user the pin mode control will take care of enabling the pin's
  1293. * input/output buffers as needed.
  1294. */
  1295. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1296. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1297. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1298. /* Mute capture amp left and right */
  1299. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1300. /* Set ADC connection select to match default mixer setting (mic1
  1301. * pin)
  1302. */
  1303. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1304. /* Mute all inputs to mixer widget (even unconnected ones) */
  1305. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1306. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1307. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1308. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1309. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1310. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1311. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1312. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1313. { }
  1314. };
  1315. #endif
  1316. /* initialize jack-sensing, too */
  1317. static int cxt5047_hp_init(struct hda_codec *codec)
  1318. {
  1319. conexant_init(codec);
  1320. cxt5047_hp_automute(codec);
  1321. return 0;
  1322. }
  1323. enum {
  1324. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1325. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1326. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1327. #ifdef CONFIG_SND_DEBUG
  1328. CXT5047_TEST,
  1329. #endif
  1330. CXT5047_AUTO,
  1331. CXT5047_MODELS
  1332. };
  1333. static const char * const cxt5047_models[CXT5047_MODELS] = {
  1334. [CXT5047_LAPTOP] = "laptop",
  1335. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1336. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1337. #ifdef CONFIG_SND_DEBUG
  1338. [CXT5047_TEST] = "test",
  1339. #endif
  1340. [CXT5047_AUTO] = "auto",
  1341. };
  1342. static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1343. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1344. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1345. CXT5047_LAPTOP),
  1346. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1347. {}
  1348. };
  1349. static int patch_cxt5047(struct hda_codec *codec)
  1350. {
  1351. struct conexant_spec *spec;
  1352. int board_config;
  1353. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1354. cxt5047_models,
  1355. cxt5047_cfg_tbl);
  1356. #if 0 /* not enabled as default, as BIOS often broken for this codec */
  1357. if (board_config < 0)
  1358. board_config = CXT5047_AUTO;
  1359. #endif
  1360. if (board_config == CXT5047_AUTO)
  1361. return patch_conexant_auto(codec);
  1362. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1363. if (!spec)
  1364. return -ENOMEM;
  1365. codec->spec = spec;
  1366. codec->pin_amp_workaround = 1;
  1367. spec->multiout.max_channels = 2;
  1368. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1369. spec->multiout.dac_nids = cxt5047_dac_nids;
  1370. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1371. spec->num_adc_nids = 1;
  1372. spec->adc_nids = cxt5047_adc_nids;
  1373. spec->capsrc_nids = cxt5047_capsrc_nids;
  1374. spec->num_mixers = 1;
  1375. spec->mixers[0] = cxt5047_base_mixers;
  1376. spec->num_init_verbs = 1;
  1377. spec->init_verbs[0] = cxt5047_init_verbs;
  1378. spec->spdif_route = 0;
  1379. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1380. spec->channel_mode = cxt5047_modes,
  1381. codec->patch_ops = conexant_patch_ops;
  1382. switch (board_config) {
  1383. case CXT5047_LAPTOP:
  1384. spec->num_mixers = 2;
  1385. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1386. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1387. break;
  1388. case CXT5047_LAPTOP_HP:
  1389. spec->num_mixers = 2;
  1390. spec->mixers[1] = cxt5047_hp_only_mixers;
  1391. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1392. codec->patch_ops.init = cxt5047_hp_init;
  1393. break;
  1394. case CXT5047_LAPTOP_EAPD:
  1395. spec->input_mux = &cxt5047_toshiba_capture_source;
  1396. spec->num_mixers = 2;
  1397. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1398. spec->num_init_verbs = 2;
  1399. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1400. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1401. break;
  1402. #ifdef CONFIG_SND_DEBUG
  1403. case CXT5047_TEST:
  1404. spec->input_mux = &cxt5047_test_capture_source;
  1405. spec->mixers[0] = cxt5047_test_mixer;
  1406. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1407. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1408. #endif
  1409. }
  1410. spec->vmaster_nid = 0x13;
  1411. switch (codec->subsystem_id >> 16) {
  1412. case 0x103c:
  1413. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1414. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1415. * with 0 dB offset 0x17)
  1416. */
  1417. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1418. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1419. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1420. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1421. (1 << AC_AMPCAP_MUTE_SHIFT));
  1422. break;
  1423. }
  1424. return 0;
  1425. }
  1426. /* Conexant 5051 specific */
  1427. static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1428. static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1429. static const struct hda_channel_mode cxt5051_modes[1] = {
  1430. { 2, NULL },
  1431. };
  1432. static void cxt5051_update_speaker(struct hda_codec *codec)
  1433. {
  1434. struct conexant_spec *spec = codec->spec;
  1435. unsigned int pinctl;
  1436. /* headphone pin */
  1437. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1438. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1439. pinctl);
  1440. /* speaker pin */
  1441. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1442. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1443. pinctl);
  1444. /* on ideapad there is an aditional speaker (subwoofer) to mute */
  1445. if (spec->ideapad)
  1446. snd_hda_codec_write(codec, 0x1b, 0,
  1447. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1448. pinctl);
  1449. }
  1450. /* turn on/off EAPD (+ mute HP) as a master switch */
  1451. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1452. struct snd_ctl_elem_value *ucontrol)
  1453. {
  1454. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1455. if (!cxt_eapd_put(kcontrol, ucontrol))
  1456. return 0;
  1457. cxt5051_update_speaker(codec);
  1458. return 1;
  1459. }
  1460. /* toggle input of built-in and mic jack appropriately */
  1461. static void cxt5051_portb_automic(struct hda_codec *codec)
  1462. {
  1463. struct conexant_spec *spec = codec->spec;
  1464. unsigned int present;
  1465. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1466. return;
  1467. present = snd_hda_jack_detect(codec, 0x17);
  1468. snd_hda_codec_write(codec, 0x14, 0,
  1469. AC_VERB_SET_CONNECT_SEL,
  1470. present ? 0x01 : 0x00);
  1471. }
  1472. /* switch the current ADC according to the jack state */
  1473. static void cxt5051_portc_automic(struct hda_codec *codec)
  1474. {
  1475. struct conexant_spec *spec = codec->spec;
  1476. unsigned int present;
  1477. hda_nid_t new_adc;
  1478. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1479. return;
  1480. present = snd_hda_jack_detect(codec, 0x18);
  1481. if (present)
  1482. spec->cur_adc_idx = 1;
  1483. else
  1484. spec->cur_adc_idx = 0;
  1485. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1486. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1487. /* stream is running, let's swap the current ADC */
  1488. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1489. spec->cur_adc = new_adc;
  1490. snd_hda_codec_setup_stream(codec, new_adc,
  1491. spec->cur_adc_stream_tag, 0,
  1492. spec->cur_adc_format);
  1493. }
  1494. }
  1495. /* mute internal speaker if HP is plugged */
  1496. static void cxt5051_hp_automute(struct hda_codec *codec)
  1497. {
  1498. struct conexant_spec *spec = codec->spec;
  1499. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1500. cxt5051_update_speaker(codec);
  1501. }
  1502. /* unsolicited event for HP jack sensing */
  1503. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1504. unsigned int res)
  1505. {
  1506. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1507. switch (res >> 26) {
  1508. case CONEXANT_HP_EVENT:
  1509. cxt5051_hp_automute(codec);
  1510. break;
  1511. case CXT5051_PORTB_EVENT:
  1512. cxt5051_portb_automic(codec);
  1513. break;
  1514. case CXT5051_PORTC_EVENT:
  1515. cxt5051_portc_automic(codec);
  1516. break;
  1517. }
  1518. snd_hda_input_jack_report(codec, nid);
  1519. }
  1520. static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1521. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1522. {
  1523. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1524. .name = "Master Playback Switch",
  1525. .info = cxt_eapd_info,
  1526. .get = cxt_eapd_get,
  1527. .put = cxt5051_hp_master_sw_put,
  1528. .private_value = 0x1a,
  1529. },
  1530. {}
  1531. };
  1532. static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1533. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1534. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1535. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1536. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1537. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1538. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1539. {}
  1540. };
  1541. static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1542. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1543. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1544. HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
  1545. HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
  1546. {}
  1547. };
  1548. static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1549. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1550. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1551. {}
  1552. };
  1553. static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1554. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1555. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1556. {}
  1557. };
  1558. static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1559. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1560. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1561. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1562. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1563. {}
  1564. };
  1565. static const struct hda_verb cxt5051_init_verbs[] = {
  1566. /* Line in, Mic */
  1567. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1568. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1569. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1570. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1571. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1572. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1573. /* SPK */
  1574. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1575. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1576. /* HP, Amp */
  1577. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1578. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1579. /* DAC1 */
  1580. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1581. /* Record selector: Internal mic */
  1582. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1583. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1584. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1585. /* SPDIF route: PCM */
  1586. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1587. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1588. /* EAPD */
  1589. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1590. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1591. { } /* end */
  1592. };
  1593. static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1594. /* Line in, Mic */
  1595. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1596. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1597. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1598. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1599. /* SPK */
  1600. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1601. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1602. /* HP, Amp */
  1603. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1604. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1605. /* DAC1 */
  1606. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1607. /* Record selector: Internal mic */
  1608. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1609. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1610. /* SPDIF route: PCM */
  1611. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1612. /* EAPD */
  1613. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1614. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1615. { } /* end */
  1616. };
  1617. static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1618. /* Line in, Mic */
  1619. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1620. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1621. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1622. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1623. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1624. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1625. /* SPK */
  1626. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1627. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1628. /* HP, Amp */
  1629. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1630. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1631. /* Docking HP */
  1632. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1633. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1634. /* DAC1 */
  1635. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1636. /* Record selector: Internal mic */
  1637. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1638. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1639. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1640. /* SPDIF route: PCM */
  1641. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
  1642. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1643. /* EAPD */
  1644. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1645. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1646. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1647. { } /* end */
  1648. };
  1649. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1650. /* Line in, Mic */
  1651. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1652. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1653. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1654. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1655. /* SPK */
  1656. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1657. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1658. /* HP, Amp */
  1659. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1660. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1661. /* DAC1 */
  1662. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1663. /* Record selector: Internal mic */
  1664. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1665. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1666. /* SPDIF route: PCM */
  1667. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1668. /* EAPD */
  1669. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1670. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1671. { } /* end */
  1672. };
  1673. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1674. unsigned int event)
  1675. {
  1676. snd_hda_codec_write(codec, nid, 0,
  1677. AC_VERB_SET_UNSOLICITED_ENABLE,
  1678. AC_USRSP_EN | event);
  1679. snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
  1680. snd_hda_input_jack_report(codec, nid);
  1681. }
  1682. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1683. /* Subwoofer */
  1684. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1685. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1686. { } /* end */
  1687. };
  1688. /* initialize jack-sensing, too */
  1689. static int cxt5051_init(struct hda_codec *codec)
  1690. {
  1691. struct conexant_spec *spec = codec->spec;
  1692. conexant_init(codec);
  1693. conexant_init_jacks(codec);
  1694. if (spec->auto_mic & AUTO_MIC_PORTB)
  1695. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1696. if (spec->auto_mic & AUTO_MIC_PORTC)
  1697. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1698. if (codec->patch_ops.unsol_event) {
  1699. cxt5051_hp_automute(codec);
  1700. cxt5051_portb_automic(codec);
  1701. cxt5051_portc_automic(codec);
  1702. }
  1703. return 0;
  1704. }
  1705. enum {
  1706. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1707. CXT5051_HP, /* no docking */
  1708. CXT5051_HP_DV6736, /* HP without mic switch */
  1709. CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
  1710. CXT5051_F700, /* HP Compaq Presario F700 */
  1711. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1712. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1713. CXT5051_AUTO, /* auto-parser */
  1714. CXT5051_MODELS
  1715. };
  1716. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1717. [CXT5051_LAPTOP] = "laptop",
  1718. [CXT5051_HP] = "hp",
  1719. [CXT5051_HP_DV6736] = "hp-dv6736",
  1720. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1721. [CXT5051_F700] = "hp-700",
  1722. [CXT5051_TOSHIBA] = "toshiba",
  1723. [CXT5051_IDEAPAD] = "ideapad",
  1724. [CXT5051_AUTO] = "auto",
  1725. };
  1726. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1727. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1728. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1729. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1730. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1731. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1732. CXT5051_LAPTOP),
  1733. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1734. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1735. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1736. {}
  1737. };
  1738. static int patch_cxt5051(struct hda_codec *codec)
  1739. {
  1740. struct conexant_spec *spec;
  1741. int board_config;
  1742. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1743. cxt5051_models,
  1744. cxt5051_cfg_tbl);
  1745. #if 0 /* use the old method just for safety */
  1746. if (board_config < 0)
  1747. board_config = CXT5051_AUTO;
  1748. #endif
  1749. if (board_config == CXT5051_AUTO)
  1750. return patch_conexant_auto(codec);
  1751. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1752. if (!spec)
  1753. return -ENOMEM;
  1754. codec->spec = spec;
  1755. codec->pin_amp_workaround = 1;
  1756. codec->patch_ops = conexant_patch_ops;
  1757. codec->patch_ops.init = cxt5051_init;
  1758. spec->multiout.max_channels = 2;
  1759. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1760. spec->multiout.dac_nids = cxt5051_dac_nids;
  1761. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1762. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1763. spec->adc_nids = cxt5051_adc_nids;
  1764. spec->num_mixers = 2;
  1765. spec->mixers[0] = cxt5051_capture_mixers;
  1766. spec->mixers[1] = cxt5051_playback_mixers;
  1767. spec->num_init_verbs = 1;
  1768. spec->init_verbs[0] = cxt5051_init_verbs;
  1769. spec->spdif_route = 0;
  1770. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1771. spec->channel_mode = cxt5051_modes;
  1772. spec->cur_adc = 0;
  1773. spec->cur_adc_idx = 0;
  1774. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1775. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1776. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1777. switch (board_config) {
  1778. case CXT5051_HP:
  1779. spec->mixers[0] = cxt5051_hp_mixers;
  1780. break;
  1781. case CXT5051_HP_DV6736:
  1782. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1783. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1784. spec->auto_mic = 0;
  1785. break;
  1786. case CXT5051_LENOVO_X200:
  1787. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1788. /* Thinkpad X301 does not have S/PDIF wired and no ability
  1789. to use a docking station. */
  1790. if (codec->subsystem_id == 0x17aa211f)
  1791. spec->multiout.dig_out_nid = 0;
  1792. break;
  1793. case CXT5051_F700:
  1794. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1795. spec->mixers[0] = cxt5051_f700_mixers;
  1796. spec->auto_mic = 0;
  1797. break;
  1798. case CXT5051_TOSHIBA:
  1799. spec->mixers[0] = cxt5051_toshiba_mixers;
  1800. spec->auto_mic = AUTO_MIC_PORTB;
  1801. break;
  1802. case CXT5051_IDEAPAD:
  1803. spec->init_verbs[spec->num_init_verbs++] =
  1804. cxt5051_ideapad_init_verbs;
  1805. spec->ideapad = 1;
  1806. break;
  1807. }
  1808. if (spec->beep_amp)
  1809. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1810. return 0;
  1811. }
  1812. /* Conexant 5066 specific */
  1813. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1814. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1815. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1816. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1817. /* OLPC's microphone port is DC coupled for use with external sensors,
  1818. * therefore we use a 50% mic bias in order to center the input signal with
  1819. * the DC input range of the codec. */
  1820. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1821. static const struct hda_channel_mode cxt5066_modes[1] = {
  1822. { 2, NULL },
  1823. };
  1824. #define HP_PRESENT_PORT_A (1 << 0)
  1825. #define HP_PRESENT_PORT_D (1 << 1)
  1826. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1827. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1828. static void cxt5066_update_speaker(struct hda_codec *codec)
  1829. {
  1830. struct conexant_spec *spec = codec->spec;
  1831. unsigned int pinctl;
  1832. snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1833. spec->hp_present, spec->cur_eapd);
  1834. /* Port A (HP) */
  1835. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1836. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1837. pinctl);
  1838. /* Port D (HP/LO) */
  1839. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1840. if (spec->dell_automute || spec->thinkpad) {
  1841. /* Mute if Port A is connected */
  1842. if (hp_port_a_present(spec))
  1843. pinctl = 0;
  1844. } else {
  1845. /* Thinkpad/Dell doesn't give pin-D status */
  1846. if (!hp_port_d_present(spec))
  1847. pinctl = 0;
  1848. }
  1849. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1850. pinctl);
  1851. /* CLASS_D AMP */
  1852. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1853. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1854. pinctl);
  1855. }
  1856. /* turn on/off EAPD (+ mute HP) as a master switch */
  1857. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1858. struct snd_ctl_elem_value *ucontrol)
  1859. {
  1860. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1861. if (!cxt_eapd_put(kcontrol, ucontrol))
  1862. return 0;
  1863. cxt5066_update_speaker(codec);
  1864. return 1;
  1865. }
  1866. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1867. .num_items = 3,
  1868. .items = {
  1869. { "Off", PIN_IN },
  1870. { "50%", PIN_VREF50 },
  1871. { "80%", PIN_VREF80 },
  1872. },
  1873. };
  1874. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1875. {
  1876. struct conexant_spec *spec = codec->spec;
  1877. /* Even though port F is the DC input, the bias is controlled on port B.
  1878. * we also leave that port as an active input (but unselected) in DC mode
  1879. * just in case that is necessary to make the bias setting take effect. */
  1880. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1881. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1882. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1883. }
  1884. /* OLPC defers mic widget control until when capture is started because the
  1885. * microphone LED comes on as soon as these settings are put in place. if we
  1886. * did this before recording, it would give the false indication that recording
  1887. * is happening when it is not. */
  1888. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1889. {
  1890. struct conexant_spec *spec = codec->spec;
  1891. if (!spec->recording)
  1892. return;
  1893. if (spec->dc_enable) {
  1894. /* in DC mode we ignore presence detection and just use the jack
  1895. * through our special DC port */
  1896. const struct hda_verb enable_dc_mode[] = {
  1897. /* disble internal mic, port C */
  1898. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1899. /* enable DC capture, port F */
  1900. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1901. {},
  1902. };
  1903. snd_hda_sequence_write(codec, enable_dc_mode);
  1904. /* port B input disabled (and bias set) through the following call */
  1905. cxt5066_set_olpc_dc_bias(codec);
  1906. return;
  1907. }
  1908. /* disable DC (port F) */
  1909. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1910. /* external mic, port B */
  1911. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1912. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1913. /* internal mic, port C */
  1914. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1915. spec->ext_mic_present ? 0 : PIN_VREF80);
  1916. }
  1917. /* toggle input of built-in and mic jack appropriately */
  1918. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1919. {
  1920. struct conexant_spec *spec = codec->spec;
  1921. unsigned int present;
  1922. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1923. return;
  1924. present = snd_hda_codec_read(codec, 0x1a, 0,
  1925. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1926. if (present)
  1927. snd_printdd("CXT5066: external microphone detected\n");
  1928. else
  1929. snd_printdd("CXT5066: external microphone absent\n");
  1930. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1931. present ? 0 : 1);
  1932. spec->ext_mic_present = !!present;
  1933. cxt5066_olpc_select_mic(codec);
  1934. }
  1935. /* toggle input of built-in digital mic and mic jack appropriately */
  1936. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1937. {
  1938. unsigned int present;
  1939. struct hda_verb ext_mic_present[] = {
  1940. /* enable external mic, port B */
  1941. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1942. /* switch to external mic input */
  1943. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1944. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1945. /* disable internal digital mic */
  1946. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1947. {}
  1948. };
  1949. static const struct hda_verb ext_mic_absent[] = {
  1950. /* enable internal mic, port C */
  1951. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1952. /* switch to internal mic input */
  1953. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1954. /* disable external mic, port B */
  1955. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1956. {}
  1957. };
  1958. present = snd_hda_jack_detect(codec, 0x1a);
  1959. if (present) {
  1960. snd_printdd("CXT5066: external microphone detected\n");
  1961. snd_hda_sequence_write(codec, ext_mic_present);
  1962. } else {
  1963. snd_printdd("CXT5066: external microphone absent\n");
  1964. snd_hda_sequence_write(codec, ext_mic_absent);
  1965. }
  1966. }
  1967. /* toggle input of built-in digital mic and mic jack appropriately */
  1968. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1969. {
  1970. unsigned int present;
  1971. struct hda_verb ext_mic_present[] = {
  1972. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1973. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1974. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1975. {}
  1976. };
  1977. static const struct hda_verb ext_mic_absent[] = {
  1978. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1979. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1980. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1981. {}
  1982. };
  1983. present = snd_hda_jack_detect(codec, 0x1b);
  1984. if (present) {
  1985. snd_printdd("CXT5066: external microphone detected\n");
  1986. snd_hda_sequence_write(codec, ext_mic_present);
  1987. } else {
  1988. snd_printdd("CXT5066: external microphone absent\n");
  1989. snd_hda_sequence_write(codec, ext_mic_absent);
  1990. }
  1991. }
  1992. /* toggle input of built-in digital mic and mic jack appropriately */
  1993. static void cxt5066_asus_automic(struct hda_codec *codec)
  1994. {
  1995. unsigned int present;
  1996. present = snd_hda_jack_detect(codec, 0x1b);
  1997. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1998. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1999. present ? 1 : 0);
  2000. }
  2001. /* toggle input of built-in digital mic and mic jack appropriately */
  2002. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  2003. {
  2004. unsigned int present;
  2005. present = snd_hda_jack_detect(codec, 0x1b);
  2006. snd_printdd("CXT5066: external microphone present=%d\n", present);
  2007. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  2008. present ? 1 : 3);
  2009. }
  2010. /* toggle input of built-in digital mic and mic jack appropriately
  2011. order is: external mic -> dock mic -> interal mic */
  2012. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  2013. {
  2014. unsigned int ext_present, dock_present;
  2015. static const struct hda_verb ext_mic_present[] = {
  2016. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2017. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  2018. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2019. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2020. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2021. {}
  2022. };
  2023. static const struct hda_verb dock_mic_present[] = {
  2024. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2025. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  2026. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2027. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2028. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2029. {}
  2030. };
  2031. static const struct hda_verb ext_mic_absent[] = {
  2032. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  2033. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2034. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2035. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2036. {}
  2037. };
  2038. ext_present = snd_hda_jack_detect(codec, 0x1b);
  2039. dock_present = snd_hda_jack_detect(codec, 0x1a);
  2040. if (ext_present) {
  2041. snd_printdd("CXT5066: external microphone detected\n");
  2042. snd_hda_sequence_write(codec, ext_mic_present);
  2043. } else if (dock_present) {
  2044. snd_printdd("CXT5066: dock microphone detected\n");
  2045. snd_hda_sequence_write(codec, dock_mic_present);
  2046. } else {
  2047. snd_printdd("CXT5066: external microphone absent\n");
  2048. snd_hda_sequence_write(codec, ext_mic_absent);
  2049. }
  2050. }
  2051. /* mute internal speaker if HP is plugged */
  2052. static void cxt5066_hp_automute(struct hda_codec *codec)
  2053. {
  2054. struct conexant_spec *spec = codec->spec;
  2055. unsigned int portA, portD;
  2056. /* Port A */
  2057. portA = snd_hda_jack_detect(codec, 0x19);
  2058. /* Port D */
  2059. portD = snd_hda_jack_detect(codec, 0x1c);
  2060. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  2061. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  2062. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  2063. portA, portD, spec->hp_present);
  2064. cxt5066_update_speaker(codec);
  2065. }
  2066. /* Dispatch the right mic autoswitch function */
  2067. static void cxt5066_automic(struct hda_codec *codec)
  2068. {
  2069. struct conexant_spec *spec = codec->spec;
  2070. if (spec->dell_vostro)
  2071. cxt5066_vostro_automic(codec);
  2072. else if (spec->ideapad)
  2073. cxt5066_ideapad_automic(codec);
  2074. else if (spec->thinkpad)
  2075. cxt5066_thinkpad_automic(codec);
  2076. else if (spec->hp_laptop)
  2077. cxt5066_hp_laptop_automic(codec);
  2078. else if (spec->asus)
  2079. cxt5066_asus_automic(codec);
  2080. }
  2081. /* unsolicited event for jack sensing */
  2082. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  2083. {
  2084. struct conexant_spec *spec = codec->spec;
  2085. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2086. switch (res >> 26) {
  2087. case CONEXANT_HP_EVENT:
  2088. cxt5066_hp_automute(codec);
  2089. break;
  2090. case CONEXANT_MIC_EVENT:
  2091. /* ignore mic events in DC mode; we're always using the jack */
  2092. if (!spec->dc_enable)
  2093. cxt5066_olpc_automic(codec);
  2094. break;
  2095. }
  2096. }
  2097. /* unsolicited event for jack sensing */
  2098. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  2099. {
  2100. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2101. switch (res >> 26) {
  2102. case CONEXANT_HP_EVENT:
  2103. cxt5066_hp_automute(codec);
  2104. break;
  2105. case CONEXANT_MIC_EVENT:
  2106. cxt5066_automic(codec);
  2107. break;
  2108. }
  2109. }
  2110. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2111. .num_items = 5,
  2112. .items = {
  2113. { "0dB", 0 },
  2114. { "10dB", 1 },
  2115. { "20dB", 2 },
  2116. { "30dB", 3 },
  2117. { "40dB", 4 },
  2118. },
  2119. };
  2120. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2121. {
  2122. struct conexant_spec *spec = codec->spec;
  2123. snd_hda_codec_write_cache(codec, 0x17, 0,
  2124. AC_VERB_SET_AMP_GAIN_MUTE,
  2125. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2126. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2127. if (spec->ideapad || spec->thinkpad) {
  2128. /* adjust the internal mic as well...it is not through 0x17 */
  2129. snd_hda_codec_write_cache(codec, 0x23, 0,
  2130. AC_VERB_SET_AMP_GAIN_MUTE,
  2131. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2132. cxt5066_analog_mic_boost.
  2133. items[spec->mic_boost].index);
  2134. }
  2135. }
  2136. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2137. struct snd_ctl_elem_info *uinfo)
  2138. {
  2139. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2140. }
  2141. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2142. struct snd_ctl_elem_value *ucontrol)
  2143. {
  2144. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2145. struct conexant_spec *spec = codec->spec;
  2146. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2147. return 0;
  2148. }
  2149. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2150. struct snd_ctl_elem_value *ucontrol)
  2151. {
  2152. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2153. struct conexant_spec *spec = codec->spec;
  2154. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2155. unsigned int idx;
  2156. idx = ucontrol->value.enumerated.item[0];
  2157. if (idx >= imux->num_items)
  2158. idx = imux->num_items - 1;
  2159. spec->mic_boost = idx;
  2160. if (!spec->dc_enable)
  2161. cxt5066_set_mic_boost(codec);
  2162. return 1;
  2163. }
  2164. static void cxt5066_enable_dc(struct hda_codec *codec)
  2165. {
  2166. const struct hda_verb enable_dc_mode[] = {
  2167. /* disable gain */
  2168. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2169. /* switch to DC input */
  2170. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2171. {}
  2172. };
  2173. /* configure as input source */
  2174. snd_hda_sequence_write(codec, enable_dc_mode);
  2175. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2176. }
  2177. static void cxt5066_disable_dc(struct hda_codec *codec)
  2178. {
  2179. /* reconfigure input source */
  2180. cxt5066_set_mic_boost(codec);
  2181. /* automic also selects the right mic if we're recording */
  2182. cxt5066_olpc_automic(codec);
  2183. }
  2184. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2185. struct snd_ctl_elem_value *ucontrol)
  2186. {
  2187. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2188. struct conexant_spec *spec = codec->spec;
  2189. ucontrol->value.integer.value[0] = spec->dc_enable;
  2190. return 0;
  2191. }
  2192. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2193. struct snd_ctl_elem_value *ucontrol)
  2194. {
  2195. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2196. struct conexant_spec *spec = codec->spec;
  2197. int dc_enable = !!ucontrol->value.integer.value[0];
  2198. if (dc_enable == spec->dc_enable)
  2199. return 0;
  2200. spec->dc_enable = dc_enable;
  2201. if (dc_enable)
  2202. cxt5066_enable_dc(codec);
  2203. else
  2204. cxt5066_disable_dc(codec);
  2205. return 1;
  2206. }
  2207. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2208. struct snd_ctl_elem_info *uinfo)
  2209. {
  2210. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2211. }
  2212. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2213. struct snd_ctl_elem_value *ucontrol)
  2214. {
  2215. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2216. struct conexant_spec *spec = codec->spec;
  2217. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2218. return 0;
  2219. }
  2220. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2221. struct snd_ctl_elem_value *ucontrol)
  2222. {
  2223. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2224. struct conexant_spec *spec = codec->spec;
  2225. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2226. unsigned int idx;
  2227. idx = ucontrol->value.enumerated.item[0];
  2228. if (idx >= imux->num_items)
  2229. idx = imux->num_items - 1;
  2230. spec->dc_input_bias = idx;
  2231. if (spec->dc_enable)
  2232. cxt5066_set_olpc_dc_bias(codec);
  2233. return 1;
  2234. }
  2235. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2236. {
  2237. struct conexant_spec *spec = codec->spec;
  2238. /* mark as recording and configure the microphone widget so that the
  2239. * recording LED comes on. */
  2240. spec->recording = 1;
  2241. cxt5066_olpc_select_mic(codec);
  2242. }
  2243. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2244. {
  2245. struct conexant_spec *spec = codec->spec;
  2246. const struct hda_verb disable_mics[] = {
  2247. /* disable external mic, port B */
  2248. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2249. /* disble internal mic, port C */
  2250. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2251. /* disable DC capture, port F */
  2252. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2253. {},
  2254. };
  2255. snd_hda_sequence_write(codec, disable_mics);
  2256. spec->recording = 0;
  2257. }
  2258. static void conexant_check_dig_outs(struct hda_codec *codec,
  2259. const hda_nid_t *dig_pins,
  2260. int num_pins)
  2261. {
  2262. struct conexant_spec *spec = codec->spec;
  2263. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  2264. int i;
  2265. for (i = 0; i < num_pins; i++, dig_pins++) {
  2266. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  2267. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  2268. continue;
  2269. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  2270. continue;
  2271. if (spec->slave_dig_outs[0])
  2272. nid_loc++;
  2273. else
  2274. nid_loc = spec->slave_dig_outs;
  2275. }
  2276. }
  2277. static const struct hda_input_mux cxt5066_capture_source = {
  2278. .num_items = 4,
  2279. .items = {
  2280. { "Mic B", 0 },
  2281. { "Mic C", 1 },
  2282. { "Mic E", 2 },
  2283. { "Mic F", 3 },
  2284. },
  2285. };
  2286. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2287. .ops = &snd_hda_bind_vol,
  2288. .values = {
  2289. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2290. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2291. 0
  2292. },
  2293. };
  2294. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2295. .ops = &snd_hda_bind_sw,
  2296. .values = {
  2297. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2298. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2299. 0
  2300. },
  2301. };
  2302. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2303. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2304. {}
  2305. };
  2306. static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2307. {
  2308. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2309. .name = "Master Playback Volume",
  2310. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2311. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2312. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2313. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2314. .info = snd_hda_mixer_amp_volume_info,
  2315. .get = snd_hda_mixer_amp_volume_get,
  2316. .put = snd_hda_mixer_amp_volume_put,
  2317. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2318. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2319. .private_value =
  2320. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2321. },
  2322. {}
  2323. };
  2324. static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2325. {
  2326. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2327. .name = "DC Mode Enable Switch",
  2328. .info = snd_ctl_boolean_mono_info,
  2329. .get = cxt5066_olpc_dc_get,
  2330. .put = cxt5066_olpc_dc_put,
  2331. },
  2332. {
  2333. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2334. .name = "DC Input Bias Enum",
  2335. .info = cxt5066_olpc_dc_bias_enum_info,
  2336. .get = cxt5066_olpc_dc_bias_enum_get,
  2337. .put = cxt5066_olpc_dc_bias_enum_put,
  2338. },
  2339. {}
  2340. };
  2341. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  2342. {
  2343. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2344. .name = "Master Playback Switch",
  2345. .info = cxt_eapd_info,
  2346. .get = cxt_eapd_get,
  2347. .put = cxt5066_hp_master_sw_put,
  2348. .private_value = 0x1d,
  2349. },
  2350. {
  2351. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2352. .name = "Analog Mic Boost Capture Enum",
  2353. .info = cxt5066_mic_boost_mux_enum_info,
  2354. .get = cxt5066_mic_boost_mux_enum_get,
  2355. .put = cxt5066_mic_boost_mux_enum_put,
  2356. },
  2357. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2358. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2359. {}
  2360. };
  2361. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2362. {
  2363. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2364. .name = "Internal Mic Boost Capture Enum",
  2365. .info = cxt5066_mic_boost_mux_enum_info,
  2366. .get = cxt5066_mic_boost_mux_enum_get,
  2367. .put = cxt5066_mic_boost_mux_enum_put,
  2368. .private_value = 0x23 | 0x100,
  2369. },
  2370. {}
  2371. };
  2372. static const struct hda_verb cxt5066_init_verbs[] = {
  2373. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2374. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2375. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2376. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2377. /* Speakers */
  2378. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2379. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2380. /* HP, Amp */
  2381. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2382. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2383. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2384. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2385. /* DAC1 */
  2386. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2387. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2388. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2389. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2390. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2391. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2392. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2393. /* no digital microphone support yet */
  2394. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2395. /* Audio input selector */
  2396. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2397. /* SPDIF route: PCM */
  2398. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2399. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2400. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2401. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2402. /* EAPD */
  2403. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2404. /* not handling these yet */
  2405. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2406. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2407. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2408. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2409. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2410. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2411. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2412. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2413. { } /* end */
  2414. };
  2415. static const struct hda_verb cxt5066_init_verbs_olpc[] = {
  2416. /* Port A: headphones */
  2417. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2418. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2419. /* Port B: external microphone */
  2420. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2421. /* Port C: internal microphone */
  2422. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2423. /* Port D: unused */
  2424. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2425. /* Port E: unused, but has primary EAPD */
  2426. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2427. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2428. /* Port F: external DC input through microphone port */
  2429. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2430. /* Port G: internal speakers */
  2431. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2432. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2433. /* DAC1 */
  2434. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2435. /* DAC2: unused */
  2436. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2437. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2438. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2439. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2440. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2441. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2442. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2443. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2444. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2445. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2446. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2447. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2448. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2449. /* Disable digital microphone port */
  2450. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2451. /* Audio input selectors */
  2452. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2453. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2454. /* Disable SPDIF */
  2455. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2456. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2457. /* enable unsolicited events for Port A and B */
  2458. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2459. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2460. { } /* end */
  2461. };
  2462. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2463. /* Port A: headphones */
  2464. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2465. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2466. /* Port B: external microphone */
  2467. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2468. /* Port C: unused */
  2469. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2470. /* Port D: unused */
  2471. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2472. /* Port E: unused, but has primary EAPD */
  2473. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2474. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2475. /* Port F: unused */
  2476. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2477. /* Port G: internal speakers */
  2478. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2479. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2480. /* DAC1 */
  2481. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2482. /* DAC2: unused */
  2483. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2484. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2485. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2486. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2487. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2488. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2489. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2490. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2491. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2492. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2493. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2494. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2495. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2496. /* Digital microphone port */
  2497. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2498. /* Audio input selectors */
  2499. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2500. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2501. /* Disable SPDIF */
  2502. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2503. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2504. /* enable unsolicited events for Port A and B */
  2505. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2506. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2507. { } /* end */
  2508. };
  2509. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2510. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2511. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2512. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2513. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2514. /* Speakers */
  2515. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2516. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2517. /* HP, Amp */
  2518. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2519. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2520. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2521. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2522. /* DAC1 */
  2523. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2524. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2525. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2526. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2527. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2528. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2529. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2530. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2531. /* Audio input selector */
  2532. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2533. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2534. /* SPDIF route: PCM */
  2535. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2536. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2537. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2538. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2539. /* internal microphone */
  2540. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2541. /* EAPD */
  2542. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2543. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2544. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2545. { } /* end */
  2546. };
  2547. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2548. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2549. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2550. /* Port G: internal speakers */
  2551. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2552. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2553. /* Port A: HP, Amp */
  2554. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2555. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2556. /* Port B: Mic Dock */
  2557. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2558. /* Port C: Mic */
  2559. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2560. /* Port D: HP Dock, Amp */
  2561. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2562. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2563. /* DAC1 */
  2564. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2565. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2566. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2567. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2568. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2569. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2570. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2571. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2572. /* Audio input selector */
  2573. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2574. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2575. /* SPDIF route: PCM */
  2576. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2577. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2578. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2579. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2580. /* internal microphone */
  2581. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2582. /* EAPD */
  2583. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2584. /* enable unsolicited events for Port A, B, C and D */
  2585. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2586. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2587. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2588. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2589. { } /* end */
  2590. };
  2591. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2592. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2593. { } /* end */
  2594. };
  2595. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2596. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2597. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2598. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2599. { } /* end */
  2600. };
  2601. /* initialize jack-sensing, too */
  2602. static int cxt5066_init(struct hda_codec *codec)
  2603. {
  2604. snd_printdd("CXT5066: init\n");
  2605. conexant_init(codec);
  2606. if (codec->patch_ops.unsol_event) {
  2607. cxt5066_hp_automute(codec);
  2608. cxt5066_automic(codec);
  2609. }
  2610. cxt5066_set_mic_boost(codec);
  2611. return 0;
  2612. }
  2613. static int cxt5066_olpc_init(struct hda_codec *codec)
  2614. {
  2615. struct conexant_spec *spec = codec->spec;
  2616. snd_printdd("CXT5066: init\n");
  2617. conexant_init(codec);
  2618. cxt5066_hp_automute(codec);
  2619. if (!spec->dc_enable) {
  2620. cxt5066_set_mic_boost(codec);
  2621. cxt5066_olpc_automic(codec);
  2622. } else {
  2623. cxt5066_enable_dc(codec);
  2624. }
  2625. return 0;
  2626. }
  2627. enum {
  2628. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2629. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2630. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2631. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2632. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2633. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2634. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2635. CXT5066_HP_LAPTOP, /* HP Laptop */
  2636. CXT5066_AUTO, /* BIOS auto-parser */
  2637. CXT5066_MODELS
  2638. };
  2639. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2640. [CXT5066_LAPTOP] = "laptop",
  2641. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2642. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2643. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2644. [CXT5066_IDEAPAD] = "ideapad",
  2645. [CXT5066_THINKPAD] = "thinkpad",
  2646. [CXT5066_ASUS] = "asus",
  2647. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2648. [CXT5066_AUTO] = "auto",
  2649. };
  2650. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2651. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2652. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2653. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2654. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2655. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2656. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2657. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2658. SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
  2659. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2660. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2661. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2662. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2663. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2664. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2665. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2666. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2667. CXT5066_LAPTOP),
  2668. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2669. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2670. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2671. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2672. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2673. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
  2674. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
  2675. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2676. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
  2677. {}
  2678. };
  2679. static int patch_cxt5066(struct hda_codec *codec)
  2680. {
  2681. struct conexant_spec *spec;
  2682. int board_config;
  2683. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2684. cxt5066_models, cxt5066_cfg_tbl);
  2685. #if 0 /* use the old method just for safety */
  2686. if (board_config < 0)
  2687. board_config = CXT5066_AUTO;
  2688. #endif
  2689. if (board_config == CXT5066_AUTO)
  2690. return patch_conexant_auto(codec);
  2691. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2692. if (!spec)
  2693. return -ENOMEM;
  2694. codec->spec = spec;
  2695. codec->patch_ops = conexant_patch_ops;
  2696. codec->patch_ops.init = conexant_init;
  2697. spec->dell_automute = 0;
  2698. spec->multiout.max_channels = 2;
  2699. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2700. spec->multiout.dac_nids = cxt5066_dac_nids;
  2701. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2702. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2703. spec->num_adc_nids = 1;
  2704. spec->adc_nids = cxt5066_adc_nids;
  2705. spec->capsrc_nids = cxt5066_capsrc_nids;
  2706. spec->input_mux = &cxt5066_capture_source;
  2707. spec->port_d_mode = PIN_HP;
  2708. spec->num_init_verbs = 1;
  2709. spec->init_verbs[0] = cxt5066_init_verbs;
  2710. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2711. spec->channel_mode = cxt5066_modes;
  2712. spec->cur_adc = 0;
  2713. spec->cur_adc_idx = 0;
  2714. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2715. switch (board_config) {
  2716. default:
  2717. case CXT5066_LAPTOP:
  2718. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2719. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2720. break;
  2721. case CXT5066_DELL_LAPTOP:
  2722. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2723. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2724. spec->port_d_mode = PIN_OUT;
  2725. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2726. spec->num_init_verbs++;
  2727. spec->dell_automute = 1;
  2728. break;
  2729. case CXT5066_ASUS:
  2730. case CXT5066_HP_LAPTOP:
  2731. codec->patch_ops.init = cxt5066_init;
  2732. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2733. spec->init_verbs[spec->num_init_verbs] =
  2734. cxt5066_init_verbs_hp_laptop;
  2735. spec->num_init_verbs++;
  2736. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2737. spec->asus = board_config == CXT5066_ASUS;
  2738. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2739. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2740. /* no S/PDIF out */
  2741. if (board_config == CXT5066_HP_LAPTOP)
  2742. spec->multiout.dig_out_nid = 0;
  2743. /* input source automatically selected */
  2744. spec->input_mux = NULL;
  2745. spec->port_d_mode = 0;
  2746. spec->mic_boost = 3; /* default 30dB gain */
  2747. break;
  2748. case CXT5066_OLPC_XO_1_5:
  2749. codec->patch_ops.init = cxt5066_olpc_init;
  2750. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2751. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2752. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2753. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2754. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2755. spec->port_d_mode = 0;
  2756. spec->mic_boost = 3; /* default 30dB gain */
  2757. /* no S/PDIF out */
  2758. spec->multiout.dig_out_nid = 0;
  2759. /* input source automatically selected */
  2760. spec->input_mux = NULL;
  2761. /* our capture hooks which allow us to turn on the microphone LED
  2762. * at the right time */
  2763. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2764. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2765. break;
  2766. case CXT5066_DELL_VOSTRO:
  2767. codec->patch_ops.init = cxt5066_init;
  2768. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2769. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2770. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2771. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2772. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2773. spec->port_d_mode = 0;
  2774. spec->dell_vostro = 1;
  2775. spec->mic_boost = 3; /* default 30dB gain */
  2776. /* no S/PDIF out */
  2777. spec->multiout.dig_out_nid = 0;
  2778. /* input source automatically selected */
  2779. spec->input_mux = NULL;
  2780. break;
  2781. case CXT5066_IDEAPAD:
  2782. codec->patch_ops.init = cxt5066_init;
  2783. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2784. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2785. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2786. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2787. spec->port_d_mode = 0;
  2788. spec->ideapad = 1;
  2789. spec->mic_boost = 2; /* default 20dB gain */
  2790. /* no S/PDIF out */
  2791. spec->multiout.dig_out_nid = 0;
  2792. /* input source automatically selected */
  2793. spec->input_mux = NULL;
  2794. break;
  2795. case CXT5066_THINKPAD:
  2796. codec->patch_ops.init = cxt5066_init;
  2797. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2798. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2799. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2800. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2801. spec->thinkpad = 1;
  2802. spec->port_d_mode = PIN_OUT;
  2803. spec->mic_boost = 2; /* default 20dB gain */
  2804. /* no S/PDIF out */
  2805. spec->multiout.dig_out_nid = 0;
  2806. /* input source automatically selected */
  2807. spec->input_mux = NULL;
  2808. break;
  2809. }
  2810. if (spec->beep_amp)
  2811. snd_hda_attach_beep_device(codec, spec->beep_amp);
  2812. return 0;
  2813. }
  2814. /*
  2815. * Automatic parser for CX20641 & co
  2816. */
  2817. static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2818. struct hda_codec *codec,
  2819. unsigned int stream_tag,
  2820. unsigned int format,
  2821. struct snd_pcm_substream *substream)
  2822. {
  2823. struct conexant_spec *spec = codec->spec;
  2824. hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
  2825. if (spec->adc_switching) {
  2826. spec->cur_adc = adc;
  2827. spec->cur_adc_stream_tag = stream_tag;
  2828. spec->cur_adc_format = format;
  2829. }
  2830. snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
  2831. return 0;
  2832. }
  2833. static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2834. struct hda_codec *codec,
  2835. struct snd_pcm_substream *substream)
  2836. {
  2837. struct conexant_spec *spec = codec->spec;
  2838. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  2839. spec->cur_adc = 0;
  2840. return 0;
  2841. }
  2842. static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
  2843. .substreams = 1,
  2844. .channels_min = 2,
  2845. .channels_max = 2,
  2846. .nid = 0, /* fill later */
  2847. .ops = {
  2848. .prepare = cx_auto_capture_pcm_prepare,
  2849. .cleanup = cx_auto_capture_pcm_cleanup
  2850. },
  2851. };
  2852. static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
  2853. /* get the connection index of @nid in the widget @mux */
  2854. static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
  2855. hda_nid_t nid)
  2856. {
  2857. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  2858. int i, nums;
  2859. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  2860. for (i = 0; i < nums; i++)
  2861. if (conn[i] == nid)
  2862. return i;
  2863. return -1;
  2864. }
  2865. /* get an unassigned DAC from the given list.
  2866. * Return the nid if found and reduce the DAC list, or return zero if
  2867. * not found
  2868. */
  2869. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
  2870. hda_nid_t *dacs, int *num_dacs)
  2871. {
  2872. int i, nums = *num_dacs;
  2873. hda_nid_t ret = 0;
  2874. for (i = 0; i < nums; i++) {
  2875. if (get_connection_index(codec, pin, dacs[i]) >= 0) {
  2876. ret = dacs[i];
  2877. break;
  2878. }
  2879. }
  2880. if (!ret)
  2881. return 0;
  2882. if (--nums > 0)
  2883. memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
  2884. *num_dacs = nums;
  2885. return ret;
  2886. }
  2887. #define MAX_AUTO_DACS 5
  2888. /* fill analog DAC list from the widget tree */
  2889. static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  2890. {
  2891. hda_nid_t nid, end_nid;
  2892. int nums = 0;
  2893. end_nid = codec->start_nid + codec->num_nodes;
  2894. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2895. unsigned int wcaps = get_wcaps(codec, nid);
  2896. unsigned int type = get_wcaps_type(wcaps);
  2897. if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
  2898. dacs[nums++] = nid;
  2899. if (nums >= MAX_AUTO_DACS)
  2900. break;
  2901. }
  2902. }
  2903. return nums;
  2904. }
  2905. /* fill pin_dac_pair list from the pin and dac list */
  2906. static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  2907. int num_pins, hda_nid_t *dacs, int *rest,
  2908. struct pin_dac_pair *filled, int type)
  2909. {
  2910. int i, nums;
  2911. nums = 0;
  2912. for (i = 0; i < num_pins; i++) {
  2913. filled[nums].pin = pins[i];
  2914. filled[nums].type = type;
  2915. filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
  2916. nums++;
  2917. }
  2918. return nums;
  2919. }
  2920. /* parse analog output paths */
  2921. static void cx_auto_parse_output(struct hda_codec *codec)
  2922. {
  2923. struct conexant_spec *spec = codec->spec;
  2924. struct auto_pin_cfg *cfg = &spec->autocfg;
  2925. hda_nid_t dacs[MAX_AUTO_DACS];
  2926. int i, j, nums, rest;
  2927. rest = fill_cx_auto_dacs(codec, dacs);
  2928. /* parse all analog output pins */
  2929. nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
  2930. dacs, &rest, spec->dac_info,
  2931. AUTO_PIN_LINE_OUT);
  2932. nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
  2933. dacs, &rest, spec->dac_info + nums,
  2934. AUTO_PIN_HP_OUT);
  2935. nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
  2936. dacs, &rest, spec->dac_info + nums,
  2937. AUTO_PIN_SPEAKER_OUT);
  2938. spec->dac_info_filled = nums;
  2939. /* fill multiout struct */
  2940. for (i = 0; i < nums; i++) {
  2941. hda_nid_t dac = spec->dac_info[i].dac;
  2942. if (!dac)
  2943. continue;
  2944. switch (spec->dac_info[i].type) {
  2945. case AUTO_PIN_LINE_OUT:
  2946. spec->private_dac_nids[spec->multiout.num_dacs] = dac;
  2947. spec->multiout.num_dacs++;
  2948. break;
  2949. case AUTO_PIN_HP_OUT:
  2950. case AUTO_PIN_SPEAKER_OUT:
  2951. if (!spec->multiout.hp_nid) {
  2952. spec->multiout.hp_nid = dac;
  2953. break;
  2954. }
  2955. for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
  2956. if (!spec->multiout.extra_out_nid[j]) {
  2957. spec->multiout.extra_out_nid[j] = dac;
  2958. break;
  2959. }
  2960. break;
  2961. }
  2962. }
  2963. spec->multiout.dac_nids = spec->private_dac_nids;
  2964. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2965. if (cfg->hp_outs > 0)
  2966. spec->auto_mute = 1;
  2967. spec->vmaster_nid = spec->private_dac_nids[0];
  2968. }
  2969. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  2970. hda_nid_t *pins, bool on);
  2971. /* auto-mute/unmute speaker and line outs according to headphone jack */
  2972. static void cx_auto_hp_automute(struct hda_codec *codec)
  2973. {
  2974. struct conexant_spec *spec = codec->spec;
  2975. struct auto_pin_cfg *cfg = &spec->autocfg;
  2976. int i, present;
  2977. if (!spec->auto_mute)
  2978. return;
  2979. present = 0;
  2980. for (i = 0; i < cfg->hp_outs; i++) {
  2981. if (snd_hda_jack_detect(codec, cfg->hp_pins[i])) {
  2982. present = 1;
  2983. break;
  2984. }
  2985. }
  2986. cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, present);
  2987. for (i = 0; i < cfg->line_outs; i++) {
  2988. snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
  2989. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2990. present ? 0 : PIN_OUT);
  2991. }
  2992. cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins, !present);
  2993. for (i = 0; !present && i < cfg->line_outs; i++)
  2994. if (snd_hda_jack_detect(codec, cfg->line_out_pins[i]))
  2995. present = 1;
  2996. for (i = 0; i < cfg->speaker_outs; i++) {
  2997. snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
  2998. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2999. present ? 0 : PIN_OUT);
  3000. }
  3001. cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins, !present);
  3002. }
  3003. static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
  3004. struct snd_ctl_elem_info *uinfo)
  3005. {
  3006. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3007. struct conexant_spec *spec = codec->spec;
  3008. return snd_hda_input_mux_info(&spec->private_imux, uinfo);
  3009. }
  3010. static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
  3011. struct snd_ctl_elem_value *ucontrol)
  3012. {
  3013. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3014. struct conexant_spec *spec = codec->spec;
  3015. ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
  3016. return 0;
  3017. }
  3018. /* look for the route the given pin from mux and return the index;
  3019. * if do_select is set, actually select the route.
  3020. */
  3021. static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3022. hda_nid_t pin, hda_nid_t *srcp,
  3023. bool do_select, int depth)
  3024. {
  3025. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  3026. int i, nums;
  3027. switch (get_wcaps_type(get_wcaps(codec, mux))) {
  3028. case AC_WID_AUD_IN:
  3029. case AC_WID_AUD_SEL:
  3030. case AC_WID_AUD_MIX:
  3031. break;
  3032. default:
  3033. return -1;
  3034. }
  3035. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  3036. for (i = 0; i < nums; i++)
  3037. if (conn[i] == pin) {
  3038. if (do_select)
  3039. snd_hda_codec_write(codec, mux, 0,
  3040. AC_VERB_SET_CONNECT_SEL, i);
  3041. if (srcp)
  3042. *srcp = mux;
  3043. return i;
  3044. }
  3045. depth++;
  3046. if (depth == 2)
  3047. return -1;
  3048. for (i = 0; i < nums; i++) {
  3049. int ret = __select_input_connection(codec, conn[i], pin, srcp,
  3050. do_select, depth);
  3051. if (ret >= 0) {
  3052. if (do_select)
  3053. snd_hda_codec_write(codec, mux, 0,
  3054. AC_VERB_SET_CONNECT_SEL, i);
  3055. return i;
  3056. }
  3057. }
  3058. return -1;
  3059. }
  3060. static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3061. hda_nid_t pin)
  3062. {
  3063. __select_input_connection(codec, mux, pin, NULL, true, 0);
  3064. }
  3065. static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3066. hda_nid_t pin)
  3067. {
  3068. return __select_input_connection(codec, mux, pin, NULL, false, 0);
  3069. }
  3070. static int cx_auto_mux_enum_update(struct hda_codec *codec,
  3071. const struct hda_input_mux *imux,
  3072. unsigned int idx)
  3073. {
  3074. struct conexant_spec *spec = codec->spec;
  3075. hda_nid_t adc;
  3076. if (!imux->num_items)
  3077. return 0;
  3078. if (idx >= imux->num_items)
  3079. idx = imux->num_items - 1;
  3080. if (spec->cur_mux[0] == idx)
  3081. return 0;
  3082. adc = spec->imux_info[idx].adc;
  3083. select_input_connection(codec, spec->imux_info[idx].adc,
  3084. spec->imux_info[idx].pin);
  3085. if (spec->cur_adc && spec->cur_adc != adc) {
  3086. /* stream is running, let's swap the current ADC */
  3087. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  3088. spec->cur_adc = adc;
  3089. snd_hda_codec_setup_stream(codec, adc,
  3090. spec->cur_adc_stream_tag, 0,
  3091. spec->cur_adc_format);
  3092. }
  3093. spec->cur_mux[0] = idx;
  3094. return 1;
  3095. }
  3096. static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
  3097. struct snd_ctl_elem_value *ucontrol)
  3098. {
  3099. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3100. struct conexant_spec *spec = codec->spec;
  3101. return cx_auto_mux_enum_update(codec, &spec->private_imux,
  3102. ucontrol->value.enumerated.item[0]);
  3103. }
  3104. static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
  3105. {
  3106. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3107. .name = "Capture Source",
  3108. .info = cx_auto_mux_enum_info,
  3109. .get = cx_auto_mux_enum_get,
  3110. .put = cx_auto_mux_enum_put
  3111. },
  3112. {}
  3113. };
  3114. /* automatic switch internal and external mic */
  3115. static void cx_auto_automic(struct hda_codec *codec)
  3116. {
  3117. struct conexant_spec *spec = codec->spec;
  3118. int ext_idx = spec->auto_mic_ext;
  3119. if (!spec->auto_mic)
  3120. return;
  3121. if (snd_hda_jack_detect(codec, spec->imux_info[ext_idx].pin))
  3122. cx_auto_mux_enum_update(codec, &spec->private_imux, ext_idx);
  3123. else
  3124. cx_auto_mux_enum_update(codec, &spec->private_imux, !ext_idx);
  3125. }
  3126. static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
  3127. {
  3128. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  3129. switch (res >> 26) {
  3130. case CONEXANT_HP_EVENT:
  3131. cx_auto_hp_automute(codec);
  3132. snd_hda_input_jack_report(codec, nid);
  3133. break;
  3134. case CONEXANT_MIC_EVENT:
  3135. cx_auto_automic(codec);
  3136. snd_hda_input_jack_report(codec, nid);
  3137. break;
  3138. }
  3139. }
  3140. /* return true if it's an internal-mic pin */
  3141. static int is_int_mic(struct hda_codec *codec, hda_nid_t pin)
  3142. {
  3143. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
  3144. return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
  3145. snd_hda_get_input_pin_attr(def_conf) == INPUT_PIN_ATTR_INT;
  3146. }
  3147. /* return true if it's an external-mic pin */
  3148. static int is_ext_mic(struct hda_codec *codec, hda_nid_t pin)
  3149. {
  3150. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
  3151. return get_defcfg_device(def_conf) == AC_JACK_MIC_IN &&
  3152. snd_hda_get_input_pin_attr(def_conf) >= INPUT_PIN_ATTR_NORMAL &&
  3153. (snd_hda_query_pin_caps(codec, pin) & AC_PINCAP_PRES_DETECT);
  3154. }
  3155. /* check whether the pin config is suitable for auto-mic switching;
  3156. * auto-mic is enabled only when one int-mic and one-ext mic exist
  3157. */
  3158. static void cx_auto_check_auto_mic(struct hda_codec *codec)
  3159. {
  3160. struct conexant_spec *spec = codec->spec;
  3161. if (is_ext_mic(codec, spec->imux_info[0].pin) &&
  3162. is_int_mic(codec, spec->imux_info[1].pin)) {
  3163. spec->auto_mic = 1;
  3164. spec->auto_mic_ext = 0;
  3165. return;
  3166. }
  3167. if (is_int_mic(codec, spec->imux_info[0].pin) &&
  3168. is_ext_mic(codec, spec->imux_info[1].pin)) {
  3169. spec->auto_mic = 1;
  3170. spec->auto_mic_ext = 1;
  3171. return;
  3172. }
  3173. }
  3174. static void cx_auto_parse_input(struct hda_codec *codec)
  3175. {
  3176. struct conexant_spec *spec = codec->spec;
  3177. struct auto_pin_cfg *cfg = &spec->autocfg;
  3178. struct hda_input_mux *imux;
  3179. int i, j;
  3180. imux = &spec->private_imux;
  3181. for (i = 0; i < cfg->num_inputs; i++) {
  3182. for (j = 0; j < spec->num_adc_nids; j++) {
  3183. hda_nid_t adc = spec->adc_nids[j];
  3184. int idx = get_input_connection(codec, adc,
  3185. cfg->inputs[i].pin);
  3186. if (idx >= 0) {
  3187. const char *label;
  3188. label = hda_get_autocfg_input_label(codec, cfg, i);
  3189. spec->imux_info[imux->num_items].index = i;
  3190. spec->imux_info[imux->num_items].boost = 0;
  3191. spec->imux_info[imux->num_items].adc = adc;
  3192. spec->imux_info[imux->num_items].pin =
  3193. cfg->inputs[i].pin;
  3194. snd_hda_add_imux_item(imux, label, idx, NULL);
  3195. break;
  3196. }
  3197. }
  3198. }
  3199. if (imux->num_items == 2 && cfg->num_inputs == 2)
  3200. cx_auto_check_auto_mic(codec);
  3201. if (imux->num_items > 1 && !spec->auto_mic) {
  3202. for (i = 1; i < imux->num_items; i++) {
  3203. if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
  3204. spec->adc_switching = 1;
  3205. break;
  3206. }
  3207. }
  3208. }
  3209. }
  3210. /* get digital-input audio widget corresponding to the given pin */
  3211. static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
  3212. {
  3213. hda_nid_t nid, end_nid;
  3214. end_nid = codec->start_nid + codec->num_nodes;
  3215. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3216. unsigned int wcaps = get_wcaps(codec, nid);
  3217. unsigned int type = get_wcaps_type(wcaps);
  3218. if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
  3219. if (get_connection_index(codec, nid, pin) >= 0)
  3220. return nid;
  3221. }
  3222. }
  3223. return 0;
  3224. }
  3225. static void cx_auto_parse_digital(struct hda_codec *codec)
  3226. {
  3227. struct conexant_spec *spec = codec->spec;
  3228. struct auto_pin_cfg *cfg = &spec->autocfg;
  3229. hda_nid_t nid;
  3230. if (cfg->dig_outs &&
  3231. snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
  3232. spec->multiout.dig_out_nid = nid;
  3233. if (cfg->dig_in_pin)
  3234. spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
  3235. }
  3236. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3237. static void cx_auto_parse_beep(struct hda_codec *codec)
  3238. {
  3239. struct conexant_spec *spec = codec->spec;
  3240. hda_nid_t nid, end_nid;
  3241. end_nid = codec->start_nid + codec->num_nodes;
  3242. for (nid = codec->start_nid; nid < end_nid; nid++)
  3243. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  3244. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  3245. break;
  3246. }
  3247. }
  3248. #else
  3249. #define cx_auto_parse_beep(codec)
  3250. #endif
  3251. static int cx_auto_parse_auto_config(struct hda_codec *codec)
  3252. {
  3253. struct conexant_spec *spec = codec->spec;
  3254. int err;
  3255. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3256. if (err < 0)
  3257. return err;
  3258. cx_auto_parse_output(codec);
  3259. cx_auto_parse_input(codec);
  3260. cx_auto_parse_digital(codec);
  3261. cx_auto_parse_beep(codec);
  3262. return 0;
  3263. }
  3264. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  3265. hda_nid_t *pins, bool on)
  3266. {
  3267. int i;
  3268. for (i = 0; i < num_pins; i++) {
  3269. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  3270. snd_hda_codec_write(codec, pins[i], 0,
  3271. AC_VERB_SET_EAPD_BTLENABLE,
  3272. on ? 0x02 : 0);
  3273. }
  3274. }
  3275. static void select_connection(struct hda_codec *codec, hda_nid_t pin,
  3276. hda_nid_t src)
  3277. {
  3278. int idx = get_connection_index(codec, pin, src);
  3279. if (idx >= 0)
  3280. snd_hda_codec_write(codec, pin, 0,
  3281. AC_VERB_SET_CONNECT_SEL, idx);
  3282. }
  3283. static void mute_outputs(struct hda_codec *codec, int num_nids,
  3284. const hda_nid_t *nids)
  3285. {
  3286. int i, val;
  3287. for (i = 0; i < num_nids; i++) {
  3288. hda_nid_t nid = nids[i];
  3289. if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
  3290. continue;
  3291. if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
  3292. val = AMP_OUT_MUTE;
  3293. else
  3294. val = AMP_OUT_ZERO;
  3295. snd_hda_codec_write(codec, nid, 0,
  3296. AC_VERB_SET_AMP_GAIN_MUTE, val);
  3297. }
  3298. }
  3299. static void cx_auto_init_output(struct hda_codec *codec)
  3300. {
  3301. struct conexant_spec *spec = codec->spec;
  3302. struct auto_pin_cfg *cfg = &spec->autocfg;
  3303. hda_nid_t nid;
  3304. int i;
  3305. mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
  3306. for (i = 0; i < cfg->hp_outs; i++)
  3307. snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
  3308. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
  3309. mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
  3310. mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
  3311. mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
  3312. if (spec->auto_mute) {
  3313. for (i = 0; i < cfg->hp_outs; i++) {
  3314. snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
  3315. AC_VERB_SET_UNSOLICITED_ENABLE,
  3316. AC_USRSP_EN | CONEXANT_HP_EVENT);
  3317. }
  3318. cx_auto_hp_automute(codec);
  3319. } else {
  3320. for (i = 0; i < cfg->line_outs; i++)
  3321. snd_hda_codec_write(codec, cfg->line_out_pins[i], 0,
  3322. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3323. for (i = 0; i < cfg->speaker_outs; i++)
  3324. snd_hda_codec_write(codec, cfg->speaker_pins[i], 0,
  3325. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3326. /* turn on EAPD */
  3327. cx_auto_turn_eapd(codec, cfg->line_outs, cfg->line_out_pins,
  3328. true);
  3329. cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins,
  3330. true);
  3331. cx_auto_turn_eapd(codec, cfg->speaker_outs, cfg->speaker_pins,
  3332. true);
  3333. }
  3334. for (i = 0; i < spec->dac_info_filled; i++) {
  3335. nid = spec->dac_info[i].dac;
  3336. if (!nid)
  3337. nid = spec->multiout.dac_nids[0];
  3338. select_connection(codec, spec->dac_info[i].pin, nid);
  3339. }
  3340. }
  3341. static void cx_auto_init_input(struct hda_codec *codec)
  3342. {
  3343. struct conexant_spec *spec = codec->spec;
  3344. struct auto_pin_cfg *cfg = &spec->autocfg;
  3345. int i, val;
  3346. for (i = 0; i < spec->num_adc_nids; i++) {
  3347. hda_nid_t nid = spec->adc_nids[i];
  3348. if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
  3349. continue;
  3350. if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
  3351. val = AMP_IN_MUTE(0);
  3352. else
  3353. val = AMP_IN_UNMUTE(0);
  3354. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3355. val);
  3356. }
  3357. for (i = 0; i < cfg->num_inputs; i++) {
  3358. unsigned int type;
  3359. if (cfg->inputs[i].type == AUTO_PIN_MIC)
  3360. type = PIN_VREF80;
  3361. else
  3362. type = PIN_IN;
  3363. snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
  3364. AC_VERB_SET_PIN_WIDGET_CONTROL, type);
  3365. }
  3366. if (spec->auto_mic) {
  3367. int ext_idx = spec->auto_mic_ext;
  3368. snd_hda_codec_write(codec, cfg->inputs[ext_idx].pin, 0,
  3369. AC_VERB_SET_UNSOLICITED_ENABLE,
  3370. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3371. cx_auto_automic(codec);
  3372. } else {
  3373. select_input_connection(codec, spec->imux_info[0].adc,
  3374. spec->imux_info[0].pin);
  3375. }
  3376. }
  3377. static void cx_auto_init_digital(struct hda_codec *codec)
  3378. {
  3379. struct conexant_spec *spec = codec->spec;
  3380. struct auto_pin_cfg *cfg = &spec->autocfg;
  3381. if (spec->multiout.dig_out_nid)
  3382. snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
  3383. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3384. if (spec->dig_in_nid)
  3385. snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
  3386. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  3387. }
  3388. static int cx_auto_init(struct hda_codec *codec)
  3389. {
  3390. /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
  3391. cx_auto_init_output(codec);
  3392. cx_auto_init_input(codec);
  3393. cx_auto_init_digital(codec);
  3394. return 0;
  3395. }
  3396. static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
  3397. const char *dir, int cidx,
  3398. hda_nid_t nid, int hda_dir, int amp_idx)
  3399. {
  3400. static char name[32];
  3401. static struct snd_kcontrol_new knew[] = {
  3402. HDA_CODEC_VOLUME(name, 0, 0, 0),
  3403. HDA_CODEC_MUTE(name, 0, 0, 0),
  3404. };
  3405. static const char * const sfx[2] = { "Volume", "Switch" };
  3406. int i, err;
  3407. for (i = 0; i < 2; i++) {
  3408. struct snd_kcontrol *kctl;
  3409. knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
  3410. hda_dir);
  3411. knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
  3412. knew[i].index = cidx;
  3413. snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
  3414. kctl = snd_ctl_new1(&knew[i], codec);
  3415. if (!kctl)
  3416. return -ENOMEM;
  3417. err = snd_hda_ctl_add(codec, nid, kctl);
  3418. if (err < 0)
  3419. return err;
  3420. if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
  3421. break;
  3422. }
  3423. return 0;
  3424. }
  3425. #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
  3426. cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
  3427. #define cx_auto_add_pb_volume(codec, nid, str, idx) \
  3428. cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
  3429. static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
  3430. hda_nid_t pin, const char *name, int idx)
  3431. {
  3432. unsigned int caps;
  3433. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  3434. if (caps & AC_AMPCAP_NUM_STEPS)
  3435. return cx_auto_add_pb_volume(codec, dac, name, idx);
  3436. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  3437. if (caps & AC_AMPCAP_NUM_STEPS)
  3438. return cx_auto_add_pb_volume(codec, pin, name, idx);
  3439. return 0;
  3440. }
  3441. static int cx_auto_build_output_controls(struct hda_codec *codec)
  3442. {
  3443. struct conexant_spec *spec = codec->spec;
  3444. int i, err;
  3445. int num_line = 0, num_hp = 0, num_spk = 0;
  3446. static const char * const texts[3] = { "Front", "Surround", "CLFE" };
  3447. if (spec->dac_info_filled == 1)
  3448. return try_add_pb_volume(codec, spec->dac_info[0].dac,
  3449. spec->dac_info[0].pin,
  3450. "Master", 0);
  3451. for (i = 0; i < spec->dac_info_filled; i++) {
  3452. const char *label;
  3453. int idx, type;
  3454. if (!spec->dac_info[i].dac)
  3455. continue;
  3456. type = spec->dac_info[i].type;
  3457. if (type == AUTO_PIN_LINE_OUT)
  3458. type = spec->autocfg.line_out_type;
  3459. switch (type) {
  3460. case AUTO_PIN_LINE_OUT:
  3461. default:
  3462. label = texts[num_line++];
  3463. idx = 0;
  3464. break;
  3465. case AUTO_PIN_HP_OUT:
  3466. label = "Headphone";
  3467. idx = num_hp++;
  3468. break;
  3469. case AUTO_PIN_SPEAKER_OUT:
  3470. label = "Speaker";
  3471. idx = num_spk++;
  3472. break;
  3473. }
  3474. err = try_add_pb_volume(codec, spec->dac_info[i].dac,
  3475. spec->dac_info[i].pin,
  3476. label, idx);
  3477. if (err < 0)
  3478. return err;
  3479. }
  3480. return 0;
  3481. }
  3482. static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
  3483. const char *label, const char *pfx,
  3484. int cidx)
  3485. {
  3486. struct conexant_spec *spec = codec->spec;
  3487. int i;
  3488. for (i = 0; i < spec->num_adc_nids; i++) {
  3489. hda_nid_t adc_nid = spec->adc_nids[i];
  3490. int idx = get_input_connection(codec, adc_nid, nid);
  3491. if (idx < 0)
  3492. continue;
  3493. return cx_auto_add_volume_idx(codec, label, pfx,
  3494. cidx, adc_nid, HDA_INPUT, idx);
  3495. }
  3496. return 0;
  3497. }
  3498. static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
  3499. const char *label, int cidx)
  3500. {
  3501. struct conexant_spec *spec = codec->spec;
  3502. hda_nid_t mux, nid;
  3503. int i, con;
  3504. nid = spec->imux_info[idx].pin;
  3505. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
  3506. return cx_auto_add_volume(codec, label, " Boost", cidx,
  3507. nid, HDA_INPUT);
  3508. con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
  3509. &mux, false, 0);
  3510. if (con < 0)
  3511. return 0;
  3512. for (i = 0; i < idx; i++) {
  3513. if (spec->imux_info[i].boost == mux)
  3514. return 0; /* already present */
  3515. }
  3516. if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
  3517. spec->imux_info[idx].boost = mux;
  3518. return cx_auto_add_volume(codec, label, " Boost", 0,
  3519. mux, HDA_OUTPUT);
  3520. }
  3521. return 0;
  3522. }
  3523. static int cx_auto_build_input_controls(struct hda_codec *codec)
  3524. {
  3525. struct conexant_spec *spec = codec->spec;
  3526. struct hda_input_mux *imux = &spec->private_imux;
  3527. const char *prev_label;
  3528. int input_conn[HDA_MAX_NUM_INPUTS];
  3529. int i, err, cidx;
  3530. int multi_connection;
  3531. multi_connection = 0;
  3532. for (i = 0; i < imux->num_items; i++) {
  3533. cidx = get_input_connection(codec, spec->imux_info[i].adc,
  3534. spec->imux_info[i].pin);
  3535. input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
  3536. if (i > 0 && input_conn[i] != input_conn[0])
  3537. multi_connection = 1;
  3538. }
  3539. prev_label = NULL;
  3540. cidx = 0;
  3541. for (i = 0; i < imux->num_items; i++) {
  3542. hda_nid_t nid = spec->imux_info[i].pin;
  3543. const char *label;
  3544. label = hda_get_autocfg_input_label(codec, &spec->autocfg,
  3545. spec->imux_info[i].index);
  3546. if (label == prev_label)
  3547. cidx++;
  3548. else
  3549. cidx = 0;
  3550. prev_label = label;
  3551. err = cx_auto_add_boost_volume(codec, i, label, cidx);
  3552. if (err < 0)
  3553. return err;
  3554. if (!multi_connection) {
  3555. if (i > 0)
  3556. continue;
  3557. err = cx_auto_add_capture_volume(codec, nid,
  3558. "Capture", "", cidx);
  3559. } else {
  3560. err = cx_auto_add_capture_volume(codec, nid,
  3561. label, " Capture", cidx);
  3562. }
  3563. if (err < 0)
  3564. return err;
  3565. }
  3566. if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
  3567. err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
  3568. if (err < 0)
  3569. return err;
  3570. }
  3571. return 0;
  3572. }
  3573. static int cx_auto_build_controls(struct hda_codec *codec)
  3574. {
  3575. int err;
  3576. err = cx_auto_build_output_controls(codec);
  3577. if (err < 0)
  3578. return err;
  3579. err = cx_auto_build_input_controls(codec);
  3580. if (err < 0)
  3581. return err;
  3582. return conexant_build_controls(codec);
  3583. }
  3584. static int cx_auto_search_adcs(struct hda_codec *codec)
  3585. {
  3586. struct conexant_spec *spec = codec->spec;
  3587. hda_nid_t nid, end_nid;
  3588. end_nid = codec->start_nid + codec->num_nodes;
  3589. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3590. unsigned int caps = get_wcaps(codec, nid);
  3591. if (get_wcaps_type(caps) != AC_WID_AUD_IN)
  3592. continue;
  3593. if (caps & AC_WCAP_DIGITAL)
  3594. continue;
  3595. if (snd_BUG_ON(spec->num_adc_nids >=
  3596. ARRAY_SIZE(spec->private_adc_nids)))
  3597. break;
  3598. spec->private_adc_nids[spec->num_adc_nids++] = nid;
  3599. }
  3600. spec->adc_nids = spec->private_adc_nids;
  3601. return 0;
  3602. }
  3603. static const struct hda_codec_ops cx_auto_patch_ops = {
  3604. .build_controls = cx_auto_build_controls,
  3605. .build_pcms = conexant_build_pcms,
  3606. .init = cx_auto_init,
  3607. .free = conexant_free,
  3608. .unsol_event = cx_auto_unsol_event,
  3609. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3610. .suspend = conexant_suspend,
  3611. #endif
  3612. .reboot_notify = snd_hda_shutup_pins,
  3613. };
  3614. static int patch_conexant_auto(struct hda_codec *codec)
  3615. {
  3616. struct conexant_spec *spec;
  3617. int err;
  3618. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3619. codec->chip_name);
  3620. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3621. if (!spec)
  3622. return -ENOMEM;
  3623. codec->spec = spec;
  3624. codec->pin_amp_workaround = 1;
  3625. err = cx_auto_search_adcs(codec);
  3626. if (err < 0)
  3627. return err;
  3628. err = cx_auto_parse_auto_config(codec);
  3629. if (err < 0) {
  3630. kfree(codec->spec);
  3631. codec->spec = NULL;
  3632. return err;
  3633. }
  3634. spec->capture_stream = &cx_auto_pcm_analog_capture;
  3635. codec->patch_ops = cx_auto_patch_ops;
  3636. if (spec->beep_amp)
  3637. snd_hda_attach_beep_device(codec, spec->beep_amp);
  3638. return 0;
  3639. }
  3640. /*
  3641. */
  3642. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3643. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3644. .patch = patch_cxt5045 },
  3645. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  3646. .patch = patch_cxt5047 },
  3647. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  3648. .patch = patch_cxt5051 },
  3649. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  3650. .patch = patch_cxt5066 },
  3651. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  3652. .patch = patch_cxt5066 },
  3653. { .id = 0x14f15068, .name = "CX20584",
  3654. .patch = patch_cxt5066 },
  3655. { .id = 0x14f15069, .name = "CX20585",
  3656. .patch = patch_cxt5066 },
  3657. { .id = 0x14f1506e, .name = "CX20590",
  3658. .patch = patch_cxt5066 },
  3659. { .id = 0x14f15097, .name = "CX20631",
  3660. .patch = patch_conexant_auto },
  3661. { .id = 0x14f15098, .name = "CX20632",
  3662. .patch = patch_conexant_auto },
  3663. { .id = 0x14f150a1, .name = "CX20641",
  3664. .patch = patch_conexant_auto },
  3665. { .id = 0x14f150a2, .name = "CX20642",
  3666. .patch = patch_conexant_auto },
  3667. { .id = 0x14f150ab, .name = "CX20651",
  3668. .patch = patch_conexant_auto },
  3669. { .id = 0x14f150ac, .name = "CX20652",
  3670. .patch = patch_conexant_auto },
  3671. { .id = 0x14f150b8, .name = "CX20664",
  3672. .patch = patch_conexant_auto },
  3673. { .id = 0x14f150b9, .name = "CX20665",
  3674. .patch = patch_conexant_auto },
  3675. {} /* terminator */
  3676. };
  3677. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  3678. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  3679. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  3680. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  3681. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  3682. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  3683. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  3684. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  3685. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  3686. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  3687. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  3688. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  3689. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  3690. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  3691. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  3692. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  3693. MODULE_LICENSE("GPL");
  3694. MODULE_DESCRIPTION("Conexant HD-audio codec");
  3695. static struct hda_codec_preset_list conexant_list = {
  3696. .preset = snd_hda_preset_conexant,
  3697. .owner = THIS_MODULE,
  3698. };
  3699. static int __init patch_conexant_init(void)
  3700. {
  3701. return snd_hda_add_codec_preset(&conexant_list);
  3702. }
  3703. static void __exit patch_conexant_exit(void)
  3704. {
  3705. snd_hda_delete_codec_preset(&conexant_list);
  3706. }
  3707. module_init(patch_conexant_init)
  3708. module_exit(patch_conexant_exit)