patch_conexant.c 133 KB

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