patch_conexant.c 133 KB

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