patch_conexant.c 117 KB

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