patch_conexant.c 131 KB

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