patch_conexant.c 116 KB

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