patch_conexant.c 131 KB

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