patch_conexant.c 117 KB

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