patch_conexant.c 138 KB

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