patch_conexant.c 136 KB

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