patch_conexant.c 137 KB

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