patch_conexant.c 133 KB

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