patch_conexant.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155
  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 conexant_spec {
  50. struct snd_kcontrol_new *mixers[5];
  51. int num_mixers;
  52. hda_nid_t vmaster_nid;
  53. const struct hda_verb *init_verbs[5]; /* initialization verbs
  54. * don't forget NULL
  55. * termination!
  56. */
  57. unsigned int num_init_verbs;
  58. /* playback */
  59. struct hda_multi_out multiout; /* playback set-up
  60. * max_channels, dacs must be set
  61. * dig_out_nid and hp_nid are optional
  62. */
  63. unsigned int cur_eapd;
  64. unsigned int hp_present;
  65. unsigned int auto_mic;
  66. unsigned int need_dac_fix;
  67. /* capture */
  68. unsigned int num_adc_nids;
  69. hda_nid_t *adc_nids;
  70. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  71. unsigned int cur_adc_idx;
  72. hda_nid_t cur_adc;
  73. unsigned int cur_adc_stream_tag;
  74. unsigned int cur_adc_format;
  75. /* capture source */
  76. const struct hda_input_mux *input_mux;
  77. hda_nid_t *capsrc_nids;
  78. unsigned int cur_mux[3];
  79. /* channel model */
  80. const struct hda_channel_mode *channel_mode;
  81. int num_channel_mode;
  82. /* PCM information */
  83. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  84. unsigned int spdif_route;
  85. /* jack detection */
  86. struct snd_array jacks;
  87. /* dynamic controls, init_verbs and input_mux */
  88. struct auto_pin_cfg autocfg;
  89. struct hda_input_mux private_imux;
  90. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  91. unsigned int dell_automute;
  92. unsigned int port_d_mode;
  93. unsigned int dell_vostro:1;
  94. unsigned int ideapad:1;
  95. unsigned int thinkpad:1;
  96. unsigned int ext_mic_present;
  97. unsigned int recording;
  98. void (*capture_prepare)(struct hda_codec *codec);
  99. void (*capture_cleanup)(struct hda_codec *codec);
  100. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  101. * through the microphone jack.
  102. * When the user enables this through a mixer switch, both internal and
  103. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  104. * we also allow the bias to be configured through a separate mixer
  105. * control. */
  106. unsigned int dc_enable;
  107. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  108. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  109. };
  110. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  111. struct hda_codec *codec,
  112. struct snd_pcm_substream *substream)
  113. {
  114. struct conexant_spec *spec = codec->spec;
  115. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  116. hinfo);
  117. }
  118. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  119. struct hda_codec *codec,
  120. unsigned int stream_tag,
  121. unsigned int format,
  122. struct snd_pcm_substream *substream)
  123. {
  124. struct conexant_spec *spec = codec->spec;
  125. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  126. stream_tag,
  127. format, substream);
  128. }
  129. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  130. struct hda_codec *codec,
  131. struct snd_pcm_substream *substream)
  132. {
  133. struct conexant_spec *spec = codec->spec;
  134. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  135. }
  136. /*
  137. * Digital out
  138. */
  139. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  140. struct hda_codec *codec,
  141. struct snd_pcm_substream *substream)
  142. {
  143. struct conexant_spec *spec = codec->spec;
  144. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  145. }
  146. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  147. struct hda_codec *codec,
  148. struct snd_pcm_substream *substream)
  149. {
  150. struct conexant_spec *spec = codec->spec;
  151. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  152. }
  153. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  154. struct hda_codec *codec,
  155. unsigned int stream_tag,
  156. unsigned int format,
  157. struct snd_pcm_substream *substream)
  158. {
  159. struct conexant_spec *spec = codec->spec;
  160. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  161. stream_tag,
  162. format, substream);
  163. }
  164. /*
  165. * Analog capture
  166. */
  167. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  168. struct hda_codec *codec,
  169. unsigned int stream_tag,
  170. unsigned int format,
  171. struct snd_pcm_substream *substream)
  172. {
  173. struct conexant_spec *spec = codec->spec;
  174. if (spec->capture_prepare)
  175. spec->capture_prepare(codec);
  176. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  177. stream_tag, 0, format);
  178. return 0;
  179. }
  180. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  181. struct hda_codec *codec,
  182. struct snd_pcm_substream *substream)
  183. {
  184. struct conexant_spec *spec = codec->spec;
  185. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  186. if (spec->capture_cleanup)
  187. spec->capture_cleanup(codec);
  188. return 0;
  189. }
  190. static struct hda_pcm_stream conexant_pcm_analog_playback = {
  191. .substreams = 1,
  192. .channels_min = 2,
  193. .channels_max = 2,
  194. .nid = 0, /* fill later */
  195. .ops = {
  196. .open = conexant_playback_pcm_open,
  197. .prepare = conexant_playback_pcm_prepare,
  198. .cleanup = conexant_playback_pcm_cleanup
  199. },
  200. };
  201. static struct hda_pcm_stream conexant_pcm_analog_capture = {
  202. .substreams = 1,
  203. .channels_min = 2,
  204. .channels_max = 2,
  205. .nid = 0, /* fill later */
  206. .ops = {
  207. .prepare = conexant_capture_pcm_prepare,
  208. .cleanup = conexant_capture_pcm_cleanup
  209. },
  210. };
  211. static struct hda_pcm_stream conexant_pcm_digital_playback = {
  212. .substreams = 1,
  213. .channels_min = 2,
  214. .channels_max = 2,
  215. .nid = 0, /* fill later */
  216. .ops = {
  217. .open = conexant_dig_playback_pcm_open,
  218. .close = conexant_dig_playback_pcm_close,
  219. .prepare = conexant_dig_playback_pcm_prepare
  220. },
  221. };
  222. static struct hda_pcm_stream conexant_pcm_digital_capture = {
  223. .substreams = 1,
  224. .channels_min = 2,
  225. .channels_max = 2,
  226. /* NID is set in alc_build_pcms */
  227. };
  228. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  229. struct hda_codec *codec,
  230. unsigned int stream_tag,
  231. unsigned int format,
  232. struct snd_pcm_substream *substream)
  233. {
  234. struct conexant_spec *spec = codec->spec;
  235. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  236. spec->cur_adc_stream_tag = stream_tag;
  237. spec->cur_adc_format = format;
  238. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  239. return 0;
  240. }
  241. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  242. struct hda_codec *codec,
  243. struct snd_pcm_substream *substream)
  244. {
  245. struct conexant_spec *spec = codec->spec;
  246. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  247. spec->cur_adc = 0;
  248. return 0;
  249. }
  250. static struct hda_pcm_stream cx5051_pcm_analog_capture = {
  251. .substreams = 1,
  252. .channels_min = 2,
  253. .channels_max = 2,
  254. .nid = 0, /* fill later */
  255. .ops = {
  256. .prepare = cx5051_capture_pcm_prepare,
  257. .cleanup = cx5051_capture_pcm_cleanup
  258. },
  259. };
  260. static int conexant_build_pcms(struct hda_codec *codec)
  261. {
  262. struct conexant_spec *spec = codec->spec;
  263. struct hda_pcm *info = spec->pcm_rec;
  264. codec->num_pcms = 1;
  265. codec->pcm_info = info;
  266. info->name = "CONEXANT Analog";
  267. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  268. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  269. spec->multiout.max_channels;
  270. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  271. spec->multiout.dac_nids[0];
  272. if (codec->vendor_id == 0x14f15051)
  273. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  274. cx5051_pcm_analog_capture;
  275. else
  276. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  277. conexant_pcm_analog_capture;
  278. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adc_nids;
  279. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  280. if (spec->multiout.dig_out_nid) {
  281. info++;
  282. codec->num_pcms++;
  283. info->name = "Conexant Digital";
  284. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  285. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  286. conexant_pcm_digital_playback;
  287. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  288. spec->multiout.dig_out_nid;
  289. if (spec->dig_in_nid) {
  290. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  291. conexant_pcm_digital_capture;
  292. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  293. spec->dig_in_nid;
  294. }
  295. }
  296. return 0;
  297. }
  298. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  299. struct snd_ctl_elem_info *uinfo)
  300. {
  301. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  302. struct conexant_spec *spec = codec->spec;
  303. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  304. }
  305. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  306. struct snd_ctl_elem_value *ucontrol)
  307. {
  308. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  309. struct conexant_spec *spec = codec->spec;
  310. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  311. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  312. return 0;
  313. }
  314. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  315. struct snd_ctl_elem_value *ucontrol)
  316. {
  317. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  318. struct conexant_spec *spec = codec->spec;
  319. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  320. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  321. spec->capsrc_nids[adc_idx],
  322. &spec->cur_mux[adc_idx]);
  323. }
  324. #ifdef CONFIG_SND_HDA_INPUT_JACK
  325. static void conexant_free_jack_priv(struct snd_jack *jack)
  326. {
  327. struct conexant_jack *jacks = jack->private_data;
  328. jacks->nid = 0;
  329. jacks->jack = NULL;
  330. }
  331. static int conexant_add_jack(struct hda_codec *codec,
  332. hda_nid_t nid, int type)
  333. {
  334. struct conexant_spec *spec;
  335. struct conexant_jack *jack;
  336. const char *name;
  337. int err;
  338. spec = codec->spec;
  339. snd_array_init(&spec->jacks, sizeof(*jack), 32);
  340. jack = snd_array_new(&spec->jacks);
  341. name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
  342. if (!jack)
  343. return -ENOMEM;
  344. jack->nid = nid;
  345. jack->type = type;
  346. err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
  347. if (err < 0)
  348. return err;
  349. jack->jack->private_data = jack;
  350. jack->jack->private_free = conexant_free_jack_priv;
  351. return 0;
  352. }
  353. static void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  354. {
  355. struct conexant_spec *spec = codec->spec;
  356. struct conexant_jack *jacks = spec->jacks.list;
  357. if (jacks) {
  358. int i;
  359. for (i = 0; i < spec->jacks.used; i++) {
  360. if (jacks->nid == nid) {
  361. unsigned int present;
  362. present = snd_hda_jack_detect(codec, nid);
  363. present = (present) ? jacks->type : 0 ;
  364. snd_jack_report(jacks->jack,
  365. present);
  366. }
  367. jacks++;
  368. }
  369. }
  370. }
  371. static int conexant_init_jacks(struct hda_codec *codec)
  372. {
  373. struct conexant_spec *spec = codec->spec;
  374. int i;
  375. for (i = 0; i < spec->num_init_verbs; i++) {
  376. const struct hda_verb *hv;
  377. hv = spec->init_verbs[i];
  378. while (hv->nid) {
  379. int err = 0;
  380. switch (hv->param ^ AC_USRSP_EN) {
  381. case CONEXANT_HP_EVENT:
  382. err = conexant_add_jack(codec, hv->nid,
  383. SND_JACK_HEADPHONE);
  384. conexant_report_jack(codec, hv->nid);
  385. break;
  386. case CXT5051_PORTC_EVENT:
  387. case CONEXANT_MIC_EVENT:
  388. err = conexant_add_jack(codec, hv->nid,
  389. SND_JACK_MICROPHONE);
  390. conexant_report_jack(codec, hv->nid);
  391. break;
  392. }
  393. if (err < 0)
  394. return err;
  395. ++hv;
  396. }
  397. }
  398. return 0;
  399. }
  400. #else
  401. static inline void conexant_report_jack(struct hda_codec *codec, hda_nid_t nid)
  402. {
  403. }
  404. static inline int conexant_init_jacks(struct hda_codec *codec)
  405. {
  406. return 0;
  407. }
  408. #endif
  409. static int conexant_init(struct hda_codec *codec)
  410. {
  411. struct conexant_spec *spec = codec->spec;
  412. int i;
  413. for (i = 0; i < spec->num_init_verbs; i++)
  414. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  415. return 0;
  416. }
  417. static void conexant_free(struct hda_codec *codec)
  418. {
  419. #ifdef CONFIG_SND_HDA_INPUT_JACK
  420. struct conexant_spec *spec = codec->spec;
  421. if (spec->jacks.list) {
  422. struct conexant_jack *jacks = spec->jacks.list;
  423. int i;
  424. for (i = 0; i < spec->jacks.used; i++, jacks++) {
  425. if (jacks->jack)
  426. snd_device_free(codec->bus->card, jacks->jack);
  427. }
  428. snd_array_free(&spec->jacks);
  429. }
  430. #endif
  431. snd_hda_detach_beep_device(codec);
  432. kfree(codec->spec);
  433. }
  434. static struct snd_kcontrol_new cxt_capture_mixers[] = {
  435. {
  436. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  437. .name = "Capture Source",
  438. .info = conexant_mux_enum_info,
  439. .get = conexant_mux_enum_get,
  440. .put = conexant_mux_enum_put
  441. },
  442. {}
  443. };
  444. static const char *slave_vols[] = {
  445. "Headphone Playback Volume",
  446. "Speaker Playback Volume",
  447. NULL
  448. };
  449. static const char *slave_sws[] = {
  450. "Headphone Playback Switch",
  451. "Speaker Playback Switch",
  452. NULL
  453. };
  454. static int conexant_build_controls(struct hda_codec *codec)
  455. {
  456. struct conexant_spec *spec = codec->spec;
  457. unsigned int i;
  458. int err;
  459. for (i = 0; i < spec->num_mixers; i++) {
  460. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  461. if (err < 0)
  462. return err;
  463. }
  464. if (spec->multiout.dig_out_nid) {
  465. err = snd_hda_create_spdif_out_ctls(codec,
  466. spec->multiout.dig_out_nid);
  467. if (err < 0)
  468. return err;
  469. err = snd_hda_create_spdif_share_sw(codec,
  470. &spec->multiout);
  471. if (err < 0)
  472. return err;
  473. spec->multiout.share_spdif = 1;
  474. }
  475. if (spec->dig_in_nid) {
  476. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  477. if (err < 0)
  478. return err;
  479. }
  480. /* if we have no master control, let's create it */
  481. if (spec->vmaster_nid &&
  482. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  483. unsigned int vmaster_tlv[4];
  484. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  485. HDA_OUTPUT, vmaster_tlv);
  486. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  487. vmaster_tlv, slave_vols);
  488. if (err < 0)
  489. return err;
  490. }
  491. if (spec->vmaster_nid &&
  492. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  493. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  494. NULL, slave_sws);
  495. if (err < 0)
  496. return err;
  497. }
  498. if (spec->input_mux) {
  499. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  500. if (err < 0)
  501. return err;
  502. }
  503. return 0;
  504. }
  505. static struct hda_codec_ops conexant_patch_ops = {
  506. .build_controls = conexant_build_controls,
  507. .build_pcms = conexant_build_pcms,
  508. .init = conexant_init,
  509. .free = conexant_free,
  510. };
  511. /*
  512. * EAPD control
  513. * the private value = nid | (invert << 8)
  514. */
  515. #define cxt_eapd_info snd_ctl_boolean_mono_info
  516. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  517. struct snd_ctl_elem_value *ucontrol)
  518. {
  519. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  520. struct conexant_spec *spec = codec->spec;
  521. int invert = (kcontrol->private_value >> 8) & 1;
  522. if (invert)
  523. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  524. else
  525. ucontrol->value.integer.value[0] = spec->cur_eapd;
  526. return 0;
  527. }
  528. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  529. struct snd_ctl_elem_value *ucontrol)
  530. {
  531. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  532. struct conexant_spec *spec = codec->spec;
  533. int invert = (kcontrol->private_value >> 8) & 1;
  534. hda_nid_t nid = kcontrol->private_value & 0xff;
  535. unsigned int eapd;
  536. eapd = !!ucontrol->value.integer.value[0];
  537. if (invert)
  538. eapd = !eapd;
  539. if (eapd == spec->cur_eapd)
  540. return 0;
  541. spec->cur_eapd = eapd;
  542. snd_hda_codec_write_cache(codec, nid,
  543. 0, AC_VERB_SET_EAPD_BTLENABLE,
  544. eapd ? 0x02 : 0x00);
  545. return 1;
  546. }
  547. /* controls for test mode */
  548. #ifdef CONFIG_SND_DEBUG
  549. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  550. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  551. .info = cxt_eapd_info, \
  552. .get = cxt_eapd_get, \
  553. .put = cxt_eapd_put, \
  554. .private_value = nid | (mask<<16) }
  555. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  556. struct snd_ctl_elem_info *uinfo)
  557. {
  558. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  559. struct conexant_spec *spec = codec->spec;
  560. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  561. spec->num_channel_mode);
  562. }
  563. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  564. struct snd_ctl_elem_value *ucontrol)
  565. {
  566. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  567. struct conexant_spec *spec = codec->spec;
  568. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  569. spec->num_channel_mode,
  570. spec->multiout.max_channels);
  571. }
  572. static int conexant_ch_mode_put(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 err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  578. spec->num_channel_mode,
  579. &spec->multiout.max_channels);
  580. if (err >= 0 && spec->need_dac_fix)
  581. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  582. return err;
  583. }
  584. #define CXT_PIN_MODE(xname, nid, dir) \
  585. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  586. .info = conexant_ch_mode_info, \
  587. .get = conexant_ch_mode_get, \
  588. .put = conexant_ch_mode_put, \
  589. .private_value = nid | (dir<<16) }
  590. #endif /* CONFIG_SND_DEBUG */
  591. /* Conexant 5045 specific */
  592. static hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  593. static hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  594. static hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  595. #define CXT5045_SPDIF_OUT 0x18
  596. static struct hda_channel_mode cxt5045_modes[1] = {
  597. { 2, NULL },
  598. };
  599. static struct hda_input_mux cxt5045_capture_source = {
  600. .num_items = 2,
  601. .items = {
  602. { "IntMic", 0x1 },
  603. { "ExtMic", 0x2 },
  604. }
  605. };
  606. static struct hda_input_mux cxt5045_capture_source_benq = {
  607. .num_items = 5,
  608. .items = {
  609. { "IntMic", 0x1 },
  610. { "ExtMic", 0x2 },
  611. { "LineIn", 0x3 },
  612. { "CD", 0x4 },
  613. { "Mixer", 0x0 },
  614. }
  615. };
  616. static struct hda_input_mux cxt5045_capture_source_hp530 = {
  617. .num_items = 2,
  618. .items = {
  619. { "ExtMic", 0x1 },
  620. { "IntMic", 0x2 },
  621. }
  622. };
  623. /* turn on/off EAPD (+ mute HP) as a master switch */
  624. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  625. struct snd_ctl_elem_value *ucontrol)
  626. {
  627. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  628. struct conexant_spec *spec = codec->spec;
  629. unsigned int bits;
  630. if (!cxt_eapd_put(kcontrol, ucontrol))
  631. return 0;
  632. /* toggle internal speakers mute depending of presence of
  633. * the headphone jack
  634. */
  635. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  636. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  637. HDA_AMP_MUTE, bits);
  638. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  639. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  640. HDA_AMP_MUTE, bits);
  641. return 1;
  642. }
  643. /* bind volumes of both NID 0x10 and 0x11 */
  644. static struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  645. .ops = &snd_hda_bind_vol,
  646. .values = {
  647. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  648. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  649. 0
  650. },
  651. };
  652. /* toggle input of built-in and mic jack appropriately */
  653. static void cxt5045_hp_automic(struct hda_codec *codec)
  654. {
  655. static struct hda_verb mic_jack_on[] = {
  656. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  657. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  658. {}
  659. };
  660. static struct hda_verb mic_jack_off[] = {
  661. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  662. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  663. {}
  664. };
  665. unsigned int present;
  666. present = snd_hda_jack_detect(codec, 0x12);
  667. if (present)
  668. snd_hda_sequence_write(codec, mic_jack_on);
  669. else
  670. snd_hda_sequence_write(codec, mic_jack_off);
  671. }
  672. /* mute internal speaker if HP is plugged */
  673. static void cxt5045_hp_automute(struct hda_codec *codec)
  674. {
  675. struct conexant_spec *spec = codec->spec;
  676. unsigned int bits;
  677. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  678. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  679. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  680. HDA_AMP_MUTE, bits);
  681. }
  682. /* unsolicited event for HP jack sensing */
  683. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  684. unsigned int res)
  685. {
  686. res >>= 26;
  687. switch (res) {
  688. case CONEXANT_HP_EVENT:
  689. cxt5045_hp_automute(codec);
  690. break;
  691. case CONEXANT_MIC_EVENT:
  692. cxt5045_hp_automic(codec);
  693. break;
  694. }
  695. }
  696. static struct snd_kcontrol_new cxt5045_mixers[] = {
  697. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  698. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  699. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  700. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  701. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  702. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  703. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  704. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  705. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  706. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  707. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  708. {
  709. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  710. .name = "Master Playback Switch",
  711. .info = cxt_eapd_info,
  712. .get = cxt_eapd_get,
  713. .put = cxt5045_hp_master_sw_put,
  714. .private_value = 0x10,
  715. },
  716. {}
  717. };
  718. static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  719. HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
  720. HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
  721. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
  722. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
  723. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  724. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  725. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  726. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  727. HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
  728. HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
  729. {}
  730. };
  731. static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  732. HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  733. HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  734. HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  735. HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  736. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  737. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  738. HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  739. HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  740. HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  741. HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  742. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  743. {
  744. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  745. .name = "Master Playback Switch",
  746. .info = cxt_eapd_info,
  747. .get = cxt_eapd_get,
  748. .put = cxt5045_hp_master_sw_put,
  749. .private_value = 0x10,
  750. },
  751. {}
  752. };
  753. static struct hda_verb cxt5045_init_verbs[] = {
  754. /* Line in, Mic */
  755. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  756. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  757. /* HP, Amp */
  758. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  759. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  760. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  761. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  762. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  763. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  764. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  765. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  766. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  767. /* Record selector: Int mic */
  768. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  769. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  770. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  771. /* SPDIF route: PCM */
  772. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  773. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  774. /* EAPD */
  775. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  776. { } /* end */
  777. };
  778. static struct hda_verb cxt5045_benq_init_verbs[] = {
  779. /* Int Mic, Mic */
  780. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  781. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  782. /* Line In,HP, Amp */
  783. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  784. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  785. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  786. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  787. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  788. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  789. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  790. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  791. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  792. /* Record selector: Int mic */
  793. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  794. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  795. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  796. /* SPDIF route: PCM */
  797. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  798. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  799. /* EAPD */
  800. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  801. { } /* end */
  802. };
  803. static struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  804. /* pin sensing on HP jack */
  805. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  806. { } /* end */
  807. };
  808. static struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  809. /* pin sensing on HP jack */
  810. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  811. { } /* end */
  812. };
  813. #ifdef CONFIG_SND_DEBUG
  814. /* Test configuration for debugging, modelled after the ALC260 test
  815. * configuration.
  816. */
  817. static struct hda_input_mux cxt5045_test_capture_source = {
  818. .num_items = 5,
  819. .items = {
  820. { "MIXER", 0x0 },
  821. { "MIC1 pin", 0x1 },
  822. { "LINE1 pin", 0x2 },
  823. { "HP-OUT pin", 0x3 },
  824. { "CD pin", 0x4 },
  825. },
  826. };
  827. static struct snd_kcontrol_new cxt5045_test_mixer[] = {
  828. /* Output controls */
  829. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  830. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  831. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  832. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  833. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  834. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  835. /* Modes for retasking pin widgets */
  836. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  837. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  838. /* EAPD Switch Control */
  839. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  840. /* Loopback mixer controls */
  841. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  842. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  843. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  844. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  845. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  846. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  847. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  848. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  849. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  850. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  851. {
  852. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  853. .name = "Input Source",
  854. .info = conexant_mux_enum_info,
  855. .get = conexant_mux_enum_get,
  856. .put = conexant_mux_enum_put,
  857. },
  858. /* Audio input controls */
  859. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  860. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  861. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  862. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  863. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  864. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  865. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  866. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  867. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  868. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  869. { } /* end */
  870. };
  871. static struct hda_verb cxt5045_test_init_verbs[] = {
  872. /* Set connections */
  873. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  874. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  875. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  876. /* Enable retasking pins as output, initially without power amp */
  877. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  878. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  879. /* Disable digital (SPDIF) pins initially, but users can enable
  880. * them via a mixer switch. In the case of SPDIF-out, this initverb
  881. * payload also sets the generation to 0, output to be in "consumer"
  882. * PCM format, copyright asserted, no pre-emphasis and no validity
  883. * control.
  884. */
  885. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  886. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  887. /* Start with output sum widgets muted and their output gains at min */
  888. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  889. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  890. /* Unmute retasking pin widget output buffers since the default
  891. * state appears to be output. As the pin mode is changed by the
  892. * user the pin mode control will take care of enabling the pin's
  893. * input/output buffers as needed.
  894. */
  895. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  896. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  897. /* Mute capture amp left and right */
  898. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  899. /* Set ADC connection select to match default mixer setting (mic1
  900. * pin)
  901. */
  902. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  903. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  904. /* Mute all inputs to mixer widget (even unconnected ones) */
  905. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  906. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  907. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  908. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  909. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  910. { }
  911. };
  912. #endif
  913. /* initialize jack-sensing, too */
  914. static int cxt5045_init(struct hda_codec *codec)
  915. {
  916. conexant_init(codec);
  917. cxt5045_hp_automute(codec);
  918. return 0;
  919. }
  920. enum {
  921. CXT5045_LAPTOP_HPSENSE,
  922. CXT5045_LAPTOP_MICSENSE,
  923. CXT5045_LAPTOP_HPMICSENSE,
  924. CXT5045_BENQ,
  925. CXT5045_LAPTOP_HP530,
  926. #ifdef CONFIG_SND_DEBUG
  927. CXT5045_TEST,
  928. #endif
  929. CXT5045_MODELS
  930. };
  931. static const char *cxt5045_models[CXT5045_MODELS] = {
  932. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  933. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  934. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  935. [CXT5045_BENQ] = "benq",
  936. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  937. #ifdef CONFIG_SND_DEBUG
  938. [CXT5045_TEST] = "test",
  939. #endif
  940. };
  941. static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  942. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  943. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  944. CXT5045_LAPTOP_HPSENSE),
  945. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  946. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  947. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  948. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  949. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  950. CXT5045_LAPTOP_HPMICSENSE),
  951. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  952. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  953. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  954. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  955. CXT5045_LAPTOP_HPMICSENSE),
  956. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  957. {}
  958. };
  959. static int patch_cxt5045(struct hda_codec *codec)
  960. {
  961. struct conexant_spec *spec;
  962. int board_config;
  963. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  964. if (!spec)
  965. return -ENOMEM;
  966. codec->spec = spec;
  967. codec->pin_amp_workaround = 1;
  968. spec->multiout.max_channels = 2;
  969. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  970. spec->multiout.dac_nids = cxt5045_dac_nids;
  971. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  972. spec->num_adc_nids = 1;
  973. spec->adc_nids = cxt5045_adc_nids;
  974. spec->capsrc_nids = cxt5045_capsrc_nids;
  975. spec->input_mux = &cxt5045_capture_source;
  976. spec->num_mixers = 1;
  977. spec->mixers[0] = cxt5045_mixers;
  978. spec->num_init_verbs = 1;
  979. spec->init_verbs[0] = cxt5045_init_verbs;
  980. spec->spdif_route = 0;
  981. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes),
  982. spec->channel_mode = cxt5045_modes,
  983. codec->patch_ops = conexant_patch_ops;
  984. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  985. cxt5045_models,
  986. cxt5045_cfg_tbl);
  987. switch (board_config) {
  988. case CXT5045_LAPTOP_HPSENSE:
  989. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  990. spec->input_mux = &cxt5045_capture_source;
  991. spec->num_init_verbs = 2;
  992. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  993. spec->mixers[0] = cxt5045_mixers;
  994. codec->patch_ops.init = cxt5045_init;
  995. break;
  996. case CXT5045_LAPTOP_MICSENSE:
  997. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  998. spec->input_mux = &cxt5045_capture_source;
  999. spec->num_init_verbs = 2;
  1000. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  1001. spec->mixers[0] = cxt5045_mixers;
  1002. codec->patch_ops.init = cxt5045_init;
  1003. break;
  1004. default:
  1005. case CXT5045_LAPTOP_HPMICSENSE:
  1006. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1007. spec->input_mux = &cxt5045_capture_source;
  1008. spec->num_init_verbs = 3;
  1009. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1010. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  1011. spec->mixers[0] = cxt5045_mixers;
  1012. codec->patch_ops.init = cxt5045_init;
  1013. break;
  1014. case CXT5045_BENQ:
  1015. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1016. spec->input_mux = &cxt5045_capture_source_benq;
  1017. spec->num_init_verbs = 1;
  1018. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  1019. spec->mixers[0] = cxt5045_mixers;
  1020. spec->mixers[1] = cxt5045_benq_mixers;
  1021. spec->num_mixers = 2;
  1022. codec->patch_ops.init = cxt5045_init;
  1023. break;
  1024. case CXT5045_LAPTOP_HP530:
  1025. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1026. spec->input_mux = &cxt5045_capture_source_hp530;
  1027. spec->num_init_verbs = 2;
  1028. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1029. spec->mixers[0] = cxt5045_mixers_hp530;
  1030. codec->patch_ops.init = cxt5045_init;
  1031. break;
  1032. #ifdef CONFIG_SND_DEBUG
  1033. case CXT5045_TEST:
  1034. spec->input_mux = &cxt5045_test_capture_source;
  1035. spec->mixers[0] = cxt5045_test_mixer;
  1036. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1037. break;
  1038. #endif
  1039. }
  1040. switch (codec->subsystem_id >> 16) {
  1041. case 0x103c:
  1042. case 0x1631:
  1043. case 0x1734:
  1044. case 0x17aa:
  1045. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  1046. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  1047. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  1048. */
  1049. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1050. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1051. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1052. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1053. (1 << AC_AMPCAP_MUTE_SHIFT));
  1054. break;
  1055. }
  1056. return 0;
  1057. }
  1058. /* Conexant 5047 specific */
  1059. #define CXT5047_SPDIF_OUT 0x11
  1060. static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1061. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1062. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1063. static struct hda_channel_mode cxt5047_modes[1] = {
  1064. { 2, NULL },
  1065. };
  1066. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  1067. .num_items = 2,
  1068. .items = {
  1069. { "ExtMic", 0x2 },
  1070. { "Line-In", 0x1 },
  1071. }
  1072. };
  1073. /* turn on/off EAPD (+ mute HP) as a master switch */
  1074. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1075. struct snd_ctl_elem_value *ucontrol)
  1076. {
  1077. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1078. struct conexant_spec *spec = codec->spec;
  1079. unsigned int bits;
  1080. if (!cxt_eapd_put(kcontrol, ucontrol))
  1081. return 0;
  1082. /* toggle internal speakers mute depending of presence of
  1083. * the headphone jack
  1084. */
  1085. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1086. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1087. * pin widgets unlike other codecs. In this case, we need to
  1088. * set index 0x01 for the volume from the mixer amp 0x19.
  1089. */
  1090. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1091. HDA_AMP_MUTE, bits);
  1092. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1093. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1094. HDA_AMP_MUTE, bits);
  1095. return 1;
  1096. }
  1097. /* mute internal speaker if HP is plugged */
  1098. static void cxt5047_hp_automute(struct hda_codec *codec)
  1099. {
  1100. struct conexant_spec *spec = codec->spec;
  1101. unsigned int bits;
  1102. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1103. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1104. /* See the note in cxt5047_hp_master_sw_put */
  1105. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1106. HDA_AMP_MUTE, bits);
  1107. }
  1108. /* toggle input of built-in and mic jack appropriately */
  1109. static void cxt5047_hp_automic(struct hda_codec *codec)
  1110. {
  1111. static struct hda_verb mic_jack_on[] = {
  1112. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1113. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1114. {}
  1115. };
  1116. static struct hda_verb mic_jack_off[] = {
  1117. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1118. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1119. {}
  1120. };
  1121. unsigned int present;
  1122. present = snd_hda_jack_detect(codec, 0x15);
  1123. if (present)
  1124. snd_hda_sequence_write(codec, mic_jack_on);
  1125. else
  1126. snd_hda_sequence_write(codec, mic_jack_off);
  1127. }
  1128. /* unsolicited event for HP jack sensing */
  1129. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1130. unsigned int res)
  1131. {
  1132. switch (res >> 26) {
  1133. case CONEXANT_HP_EVENT:
  1134. cxt5047_hp_automute(codec);
  1135. break;
  1136. case CONEXANT_MIC_EVENT:
  1137. cxt5047_hp_automic(codec);
  1138. break;
  1139. }
  1140. }
  1141. static struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1142. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1143. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1144. HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
  1145. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1146. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1147. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1148. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1149. {
  1150. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1151. .name = "Master Playback Switch",
  1152. .info = cxt_eapd_info,
  1153. .get = cxt_eapd_get,
  1154. .put = cxt5047_hp_master_sw_put,
  1155. .private_value = 0x13,
  1156. },
  1157. {}
  1158. };
  1159. static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1160. /* See the note in cxt5047_hp_master_sw_put */
  1161. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1162. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1163. {}
  1164. };
  1165. static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1166. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1167. { } /* end */
  1168. };
  1169. static struct hda_verb cxt5047_init_verbs[] = {
  1170. /* Line in, Mic, Built-in Mic */
  1171. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1172. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1173. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1174. /* HP, Speaker */
  1175. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1176. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1177. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1178. /* Record selector: Mic */
  1179. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1180. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1181. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1182. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1183. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1184. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1185. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1186. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1187. /* SPDIF route: PCM */
  1188. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1189. /* Enable unsolicited events */
  1190. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1191. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1192. { } /* end */
  1193. };
  1194. /* configuration for Toshiba Laptops */
  1195. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1196. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1197. {}
  1198. };
  1199. /* Test configuration for debugging, modelled after the ALC260 test
  1200. * configuration.
  1201. */
  1202. #ifdef CONFIG_SND_DEBUG
  1203. static struct hda_input_mux cxt5047_test_capture_source = {
  1204. .num_items = 4,
  1205. .items = {
  1206. { "LINE1 pin", 0x0 },
  1207. { "MIC1 pin", 0x1 },
  1208. { "MIC2 pin", 0x2 },
  1209. { "CD pin", 0x3 },
  1210. },
  1211. };
  1212. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1213. /* Output only controls */
  1214. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1215. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1216. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1217. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1218. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1219. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1220. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1221. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1222. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1223. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1224. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1225. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1226. /* Modes for retasking pin widgets */
  1227. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1228. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1229. /* EAPD Switch Control */
  1230. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1231. /* Loopback mixer controls */
  1232. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1233. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1234. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1235. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1236. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1237. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1238. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1239. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1240. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1241. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1242. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1243. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1244. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1245. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1246. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1247. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1248. {
  1249. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1250. .name = "Input Source",
  1251. .info = conexant_mux_enum_info,
  1252. .get = conexant_mux_enum_get,
  1253. .put = conexant_mux_enum_put,
  1254. },
  1255. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1256. { } /* end */
  1257. };
  1258. static struct hda_verb cxt5047_test_init_verbs[] = {
  1259. /* Enable retasking pins as output, initially without power amp */
  1260. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1261. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1262. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1263. /* Disable digital (SPDIF) pins initially, but users can enable
  1264. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1265. * payload also sets the generation to 0, output to be in "consumer"
  1266. * PCM format, copyright asserted, no pre-emphasis and no validity
  1267. * control.
  1268. */
  1269. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1270. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1271. * OUT1 sum bus when acting as an output.
  1272. */
  1273. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1274. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1275. /* Start with output sum widgets muted and their output gains at min */
  1276. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1277. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1278. /* Unmute retasking pin widget output buffers since the default
  1279. * state appears to be output. As the pin mode is changed by the
  1280. * user the pin mode control will take care of enabling the pin's
  1281. * input/output buffers as needed.
  1282. */
  1283. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1284. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1285. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1286. /* Mute capture amp left and right */
  1287. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1288. /* Set ADC connection select to match default mixer setting (mic1
  1289. * pin)
  1290. */
  1291. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1292. /* Mute all inputs to mixer widget (even unconnected ones) */
  1293. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1294. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1295. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1296. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1297. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1298. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1299. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1300. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1301. { }
  1302. };
  1303. #endif
  1304. /* initialize jack-sensing, too */
  1305. static int cxt5047_hp_init(struct hda_codec *codec)
  1306. {
  1307. conexant_init(codec);
  1308. cxt5047_hp_automute(codec);
  1309. return 0;
  1310. }
  1311. enum {
  1312. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1313. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1314. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1315. #ifdef CONFIG_SND_DEBUG
  1316. CXT5047_TEST,
  1317. #endif
  1318. CXT5047_MODELS
  1319. };
  1320. static const char *cxt5047_models[CXT5047_MODELS] = {
  1321. [CXT5047_LAPTOP] = "laptop",
  1322. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1323. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1324. #ifdef CONFIG_SND_DEBUG
  1325. [CXT5047_TEST] = "test",
  1326. #endif
  1327. };
  1328. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1329. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1330. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1331. CXT5047_LAPTOP),
  1332. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1333. {}
  1334. };
  1335. static int patch_cxt5047(struct hda_codec *codec)
  1336. {
  1337. struct conexant_spec *spec;
  1338. int board_config;
  1339. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1340. if (!spec)
  1341. return -ENOMEM;
  1342. codec->spec = spec;
  1343. codec->pin_amp_workaround = 1;
  1344. spec->multiout.max_channels = 2;
  1345. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1346. spec->multiout.dac_nids = cxt5047_dac_nids;
  1347. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1348. spec->num_adc_nids = 1;
  1349. spec->adc_nids = cxt5047_adc_nids;
  1350. spec->capsrc_nids = cxt5047_capsrc_nids;
  1351. spec->num_mixers = 1;
  1352. spec->mixers[0] = cxt5047_base_mixers;
  1353. spec->num_init_verbs = 1;
  1354. spec->init_verbs[0] = cxt5047_init_verbs;
  1355. spec->spdif_route = 0;
  1356. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1357. spec->channel_mode = cxt5047_modes,
  1358. codec->patch_ops = conexant_patch_ops;
  1359. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1360. cxt5047_models,
  1361. cxt5047_cfg_tbl);
  1362. switch (board_config) {
  1363. case CXT5047_LAPTOP:
  1364. spec->num_mixers = 2;
  1365. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1366. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1367. break;
  1368. case CXT5047_LAPTOP_HP:
  1369. spec->num_mixers = 2;
  1370. spec->mixers[1] = cxt5047_hp_only_mixers;
  1371. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1372. codec->patch_ops.init = cxt5047_hp_init;
  1373. break;
  1374. case CXT5047_LAPTOP_EAPD:
  1375. spec->input_mux = &cxt5047_toshiba_capture_source;
  1376. spec->num_mixers = 2;
  1377. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1378. spec->num_init_verbs = 2;
  1379. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1380. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1381. break;
  1382. #ifdef CONFIG_SND_DEBUG
  1383. case CXT5047_TEST:
  1384. spec->input_mux = &cxt5047_test_capture_source;
  1385. spec->mixers[0] = cxt5047_test_mixer;
  1386. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1387. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1388. #endif
  1389. }
  1390. spec->vmaster_nid = 0x13;
  1391. switch (codec->subsystem_id >> 16) {
  1392. case 0x103c:
  1393. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1394. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1395. * with 0 dB offset 0x17)
  1396. */
  1397. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1398. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1399. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1400. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1401. (1 << AC_AMPCAP_MUTE_SHIFT));
  1402. break;
  1403. }
  1404. return 0;
  1405. }
  1406. /* Conexant 5051 specific */
  1407. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1408. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1409. static struct hda_channel_mode cxt5051_modes[1] = {
  1410. { 2, NULL },
  1411. };
  1412. static void cxt5051_update_speaker(struct hda_codec *codec)
  1413. {
  1414. struct conexant_spec *spec = codec->spec;
  1415. unsigned int pinctl;
  1416. /* headphone pin */
  1417. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1418. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1419. pinctl);
  1420. /* speaker pin */
  1421. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1422. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1423. pinctl);
  1424. }
  1425. /* turn on/off EAPD (+ mute HP) as a master switch */
  1426. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1427. struct snd_ctl_elem_value *ucontrol)
  1428. {
  1429. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1430. if (!cxt_eapd_put(kcontrol, ucontrol))
  1431. return 0;
  1432. cxt5051_update_speaker(codec);
  1433. return 1;
  1434. }
  1435. /* toggle input of built-in and mic jack appropriately */
  1436. static void cxt5051_portb_automic(struct hda_codec *codec)
  1437. {
  1438. struct conexant_spec *spec = codec->spec;
  1439. unsigned int present;
  1440. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1441. return;
  1442. present = snd_hda_jack_detect(codec, 0x17);
  1443. snd_hda_codec_write(codec, 0x14, 0,
  1444. AC_VERB_SET_CONNECT_SEL,
  1445. present ? 0x01 : 0x00);
  1446. }
  1447. /* switch the current ADC according to the jack state */
  1448. static void cxt5051_portc_automic(struct hda_codec *codec)
  1449. {
  1450. struct conexant_spec *spec = codec->spec;
  1451. unsigned int present;
  1452. hda_nid_t new_adc;
  1453. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1454. return;
  1455. present = snd_hda_jack_detect(codec, 0x18);
  1456. if (present)
  1457. spec->cur_adc_idx = 1;
  1458. else
  1459. spec->cur_adc_idx = 0;
  1460. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1461. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1462. /* stream is running, let's swap the current ADC */
  1463. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1464. spec->cur_adc = new_adc;
  1465. snd_hda_codec_setup_stream(codec, new_adc,
  1466. spec->cur_adc_stream_tag, 0,
  1467. spec->cur_adc_format);
  1468. }
  1469. }
  1470. /* mute internal speaker if HP is plugged */
  1471. static void cxt5051_hp_automute(struct hda_codec *codec)
  1472. {
  1473. struct conexant_spec *spec = codec->spec;
  1474. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1475. cxt5051_update_speaker(codec);
  1476. }
  1477. /* unsolicited event for HP jack sensing */
  1478. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1479. unsigned int res)
  1480. {
  1481. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1482. switch (res >> 26) {
  1483. case CONEXANT_HP_EVENT:
  1484. cxt5051_hp_automute(codec);
  1485. break;
  1486. case CXT5051_PORTB_EVENT:
  1487. cxt5051_portb_automic(codec);
  1488. break;
  1489. case CXT5051_PORTC_EVENT:
  1490. cxt5051_portc_automic(codec);
  1491. break;
  1492. }
  1493. conexant_report_jack(codec, nid);
  1494. }
  1495. static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1496. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1497. {
  1498. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1499. .name = "Master Playback Switch",
  1500. .info = cxt_eapd_info,
  1501. .get = cxt_eapd_get,
  1502. .put = cxt5051_hp_master_sw_put,
  1503. .private_value = 0x1a,
  1504. },
  1505. {}
  1506. };
  1507. static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1508. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1509. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1510. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1511. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1512. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1513. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1514. {}
  1515. };
  1516. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1517. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1518. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1519. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1520. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1521. {}
  1522. };
  1523. static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1524. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1525. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1526. {}
  1527. };
  1528. static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1529. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1530. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1531. {}
  1532. };
  1533. static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1534. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1535. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1536. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1537. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1538. {}
  1539. };
  1540. static struct hda_verb cxt5051_init_verbs[] = {
  1541. /* Line in, Mic */
  1542. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1543. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1544. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1545. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1546. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1547. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1548. /* SPK */
  1549. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1550. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1551. /* HP, Amp */
  1552. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1553. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1554. /* DAC1 */
  1555. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1556. /* Record selector: Int mic */
  1557. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1558. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1559. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1560. /* SPDIF route: PCM */
  1561. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1562. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1563. /* EAPD */
  1564. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1565. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1566. { } /* end */
  1567. };
  1568. static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1569. /* Line in, Mic */
  1570. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1571. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1572. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1573. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1574. /* SPK */
  1575. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1576. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1577. /* HP, Amp */
  1578. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1579. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1580. /* DAC1 */
  1581. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1582. /* Record selector: Int mic */
  1583. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1584. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1585. /* SPDIF route: PCM */
  1586. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1587. /* EAPD */
  1588. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1589. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1590. { } /* end */
  1591. };
  1592. static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1593. /* Line in, Mic */
  1594. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1595. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1596. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1597. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1598. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1599. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1600. /* SPK */
  1601. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1602. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1603. /* HP, Amp */
  1604. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1605. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1606. /* Docking HP */
  1607. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1608. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1609. /* DAC1 */
  1610. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1611. /* Record selector: Int mic */
  1612. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1613. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1614. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1615. /* SPDIF route: PCM */
  1616. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
  1617. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1618. /* EAPD */
  1619. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1620. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1621. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1622. { } /* end */
  1623. };
  1624. static struct hda_verb cxt5051_f700_init_verbs[] = {
  1625. /* Line in, Mic */
  1626. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1627. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1628. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1629. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1630. /* SPK */
  1631. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1632. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1633. /* HP, Amp */
  1634. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1635. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1636. /* DAC1 */
  1637. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1638. /* Record selector: Int mic */
  1639. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1640. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1641. /* SPDIF route: PCM */
  1642. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1643. /* EAPD */
  1644. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1645. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1646. { } /* end */
  1647. };
  1648. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1649. unsigned int event)
  1650. {
  1651. snd_hda_codec_write(codec, nid, 0,
  1652. AC_VERB_SET_UNSOLICITED_ENABLE,
  1653. AC_USRSP_EN | event);
  1654. #ifdef CONFIG_SND_HDA_INPUT_JACK
  1655. conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
  1656. conexant_report_jack(codec, nid);
  1657. #endif
  1658. }
  1659. /* initialize jack-sensing, too */
  1660. static int cxt5051_init(struct hda_codec *codec)
  1661. {
  1662. struct conexant_spec *spec = codec->spec;
  1663. conexant_init(codec);
  1664. conexant_init_jacks(codec);
  1665. if (spec->auto_mic & AUTO_MIC_PORTB)
  1666. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1667. if (spec->auto_mic & AUTO_MIC_PORTC)
  1668. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1669. if (codec->patch_ops.unsol_event) {
  1670. cxt5051_hp_automute(codec);
  1671. cxt5051_portb_automic(codec);
  1672. cxt5051_portc_automic(codec);
  1673. }
  1674. return 0;
  1675. }
  1676. enum {
  1677. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1678. CXT5051_HP, /* no docking */
  1679. CXT5051_HP_DV6736, /* HP without mic switch */
  1680. CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
  1681. CXT5051_F700, /* HP Compaq Presario F700 */
  1682. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1683. CXT5051_MODELS
  1684. };
  1685. static const char *cxt5051_models[CXT5051_MODELS] = {
  1686. [CXT5051_LAPTOP] = "laptop",
  1687. [CXT5051_HP] = "hp",
  1688. [CXT5051_HP_DV6736] = "hp-dv6736",
  1689. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1690. [CXT5051_F700] = "hp-700",
  1691. [CXT5051_TOSHIBA] = "toshiba",
  1692. };
  1693. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1694. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1695. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1696. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1697. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1698. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1699. CXT5051_LAPTOP),
  1700. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1701. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1702. {}
  1703. };
  1704. static int patch_cxt5051(struct hda_codec *codec)
  1705. {
  1706. struct conexant_spec *spec;
  1707. int board_config;
  1708. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1709. if (!spec)
  1710. return -ENOMEM;
  1711. codec->spec = spec;
  1712. codec->pin_amp_workaround = 1;
  1713. codec->patch_ops = conexant_patch_ops;
  1714. codec->patch_ops.init = cxt5051_init;
  1715. spec->multiout.max_channels = 2;
  1716. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1717. spec->multiout.dac_nids = cxt5051_dac_nids;
  1718. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1719. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1720. spec->adc_nids = cxt5051_adc_nids;
  1721. spec->num_mixers = 2;
  1722. spec->mixers[0] = cxt5051_capture_mixers;
  1723. spec->mixers[1] = cxt5051_playback_mixers;
  1724. spec->num_init_verbs = 1;
  1725. spec->init_verbs[0] = cxt5051_init_verbs;
  1726. spec->spdif_route = 0;
  1727. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1728. spec->channel_mode = cxt5051_modes;
  1729. spec->cur_adc = 0;
  1730. spec->cur_adc_idx = 0;
  1731. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1732. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1733. cxt5051_models,
  1734. cxt5051_cfg_tbl);
  1735. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1736. switch (board_config) {
  1737. case CXT5051_HP:
  1738. spec->mixers[0] = cxt5051_hp_mixers;
  1739. break;
  1740. case CXT5051_HP_DV6736:
  1741. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1742. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1743. spec->auto_mic = 0;
  1744. break;
  1745. case CXT5051_LENOVO_X200:
  1746. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1747. break;
  1748. case CXT5051_F700:
  1749. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1750. spec->mixers[0] = cxt5051_f700_mixers;
  1751. spec->auto_mic = 0;
  1752. break;
  1753. case CXT5051_TOSHIBA:
  1754. spec->mixers[0] = cxt5051_toshiba_mixers;
  1755. spec->auto_mic = AUTO_MIC_PORTB;
  1756. break;
  1757. }
  1758. return 0;
  1759. }
  1760. /* Conexant 5066 specific */
  1761. static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1762. static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1763. static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1764. #define CXT5066_SPDIF_OUT 0x21
  1765. /* OLPC's microphone port is DC coupled for use with external sensors,
  1766. * therefore we use a 50% mic bias in order to center the input signal with
  1767. * the DC input range of the codec. */
  1768. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1769. static struct hda_channel_mode cxt5066_modes[1] = {
  1770. { 2, NULL },
  1771. };
  1772. static void cxt5066_update_speaker(struct hda_codec *codec)
  1773. {
  1774. struct conexant_spec *spec = codec->spec;
  1775. unsigned int pinctl;
  1776. snd_printdd("CXT5066: update speaker, hp_present=%d\n",
  1777. spec->hp_present);
  1778. /* Port A (HP) */
  1779. pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
  1780. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1781. pinctl);
  1782. /* Port D (HP/LO) */
  1783. pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
  1784. ? spec->port_d_mode : 0;
  1785. /* Mute if Port A is connected on Thinkpad */
  1786. if (spec->thinkpad && (spec->hp_present & 1))
  1787. pinctl = 0;
  1788. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1789. pinctl);
  1790. /* CLASS_D AMP */
  1791. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1792. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1793. pinctl);
  1794. if (spec->dell_automute) {
  1795. /* DELL AIO Port Rule: PortA > PortD > IntSpk */
  1796. pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
  1797. ? PIN_OUT : 0;
  1798. snd_hda_codec_write(codec, 0x1c, 0,
  1799. AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
  1800. }
  1801. }
  1802. /* turn on/off EAPD (+ mute HP) as a master switch */
  1803. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1804. struct snd_ctl_elem_value *ucontrol)
  1805. {
  1806. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1807. if (!cxt_eapd_put(kcontrol, ucontrol))
  1808. return 0;
  1809. cxt5066_update_speaker(codec);
  1810. return 1;
  1811. }
  1812. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1813. .num_items = 3,
  1814. .items = {
  1815. { "Off", PIN_IN },
  1816. { "50%", PIN_VREF50 },
  1817. { "80%", PIN_VREF80 },
  1818. },
  1819. };
  1820. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1821. {
  1822. struct conexant_spec *spec = codec->spec;
  1823. /* Even though port F is the DC input, the bias is controlled on port B.
  1824. * we also leave that port as an active input (but unselected) in DC mode
  1825. * just in case that is necessary to make the bias setting take effect. */
  1826. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1827. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1828. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1829. }
  1830. /* OLPC defers mic widget control until when capture is started because the
  1831. * microphone LED comes on as soon as these settings are put in place. if we
  1832. * did this before recording, it would give the false indication that recording
  1833. * is happening when it is not. */
  1834. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1835. {
  1836. struct conexant_spec *spec = codec->spec;
  1837. if (!spec->recording)
  1838. return;
  1839. if (spec->dc_enable) {
  1840. /* in DC mode we ignore presence detection and just use the jack
  1841. * through our special DC port */
  1842. const struct hda_verb enable_dc_mode[] = {
  1843. /* disble internal mic, port C */
  1844. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1845. /* enable DC capture, port F */
  1846. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1847. {},
  1848. };
  1849. snd_hda_sequence_write(codec, enable_dc_mode);
  1850. /* port B input disabled (and bias set) through the following call */
  1851. cxt5066_set_olpc_dc_bias(codec);
  1852. return;
  1853. }
  1854. /* disable DC (port F) */
  1855. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1856. /* external mic, port B */
  1857. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1858. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1859. /* internal mic, port C */
  1860. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1861. spec->ext_mic_present ? 0 : PIN_VREF80);
  1862. }
  1863. /* toggle input of built-in and mic jack appropriately */
  1864. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1865. {
  1866. struct conexant_spec *spec = codec->spec;
  1867. unsigned int present;
  1868. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1869. return;
  1870. present = snd_hda_codec_read(codec, 0x1a, 0,
  1871. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1872. if (present)
  1873. snd_printdd("CXT5066: external microphone detected\n");
  1874. else
  1875. snd_printdd("CXT5066: external microphone absent\n");
  1876. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1877. present ? 0 : 1);
  1878. spec->ext_mic_present = !!present;
  1879. cxt5066_olpc_select_mic(codec);
  1880. }
  1881. /* toggle input of built-in digital mic and mic jack appropriately */
  1882. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1883. {
  1884. unsigned int present;
  1885. struct hda_verb ext_mic_present[] = {
  1886. /* enable external mic, port B */
  1887. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1888. /* switch to external mic input */
  1889. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1890. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1891. /* disable internal digital mic */
  1892. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1893. {}
  1894. };
  1895. static struct hda_verb ext_mic_absent[] = {
  1896. /* enable internal mic, port C */
  1897. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1898. /* switch to internal mic input */
  1899. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1900. /* disable external mic, port B */
  1901. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1902. {}
  1903. };
  1904. present = snd_hda_jack_detect(codec, 0x1a);
  1905. if (present) {
  1906. snd_printdd("CXT5066: external microphone detected\n");
  1907. snd_hda_sequence_write(codec, ext_mic_present);
  1908. } else {
  1909. snd_printdd("CXT5066: external microphone absent\n");
  1910. snd_hda_sequence_write(codec, ext_mic_absent);
  1911. }
  1912. }
  1913. /* toggle input of built-in digital mic and mic jack appropriately */
  1914. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1915. {
  1916. unsigned int present;
  1917. struct hda_verb ext_mic_present[] = {
  1918. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1919. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1920. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1921. {}
  1922. };
  1923. static struct hda_verb ext_mic_absent[] = {
  1924. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1925. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1926. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1927. {}
  1928. };
  1929. present = snd_hda_jack_detect(codec, 0x1b);
  1930. if (present) {
  1931. snd_printdd("CXT5066: external microphone detected\n");
  1932. snd_hda_sequence_write(codec, ext_mic_present);
  1933. } else {
  1934. snd_printdd("CXT5066: external microphone absent\n");
  1935. snd_hda_sequence_write(codec, ext_mic_absent);
  1936. }
  1937. }
  1938. /* toggle input of built-in digital mic and mic jack appropriately
  1939. order is: external mic -> dock mic -> interal mic */
  1940. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1941. {
  1942. unsigned int ext_present, dock_present;
  1943. static struct hda_verb ext_mic_present[] = {
  1944. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1945. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1946. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1947. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1948. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1949. {}
  1950. };
  1951. static struct hda_verb dock_mic_present[] = {
  1952. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1953. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1954. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1955. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1956. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1957. {}
  1958. };
  1959. static struct hda_verb ext_mic_absent[] = {
  1960. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1961. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1962. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1963. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1964. {}
  1965. };
  1966. ext_present = snd_hda_jack_detect(codec, 0x1b);
  1967. dock_present = snd_hda_jack_detect(codec, 0x1a);
  1968. if (ext_present) {
  1969. snd_printdd("CXT5066: external microphone detected\n");
  1970. snd_hda_sequence_write(codec, ext_mic_present);
  1971. } else if (dock_present) {
  1972. snd_printdd("CXT5066: dock microphone detected\n");
  1973. snd_hda_sequence_write(codec, dock_mic_present);
  1974. } else {
  1975. snd_printdd("CXT5066: external microphone absent\n");
  1976. snd_hda_sequence_write(codec, ext_mic_absent);
  1977. }
  1978. }
  1979. /* mute internal speaker if HP is plugged */
  1980. static void cxt5066_hp_automute(struct hda_codec *codec)
  1981. {
  1982. struct conexant_spec *spec = codec->spec;
  1983. unsigned int portA, portD;
  1984. /* Port A */
  1985. portA = snd_hda_jack_detect(codec, 0x19);
  1986. /* Port D */
  1987. portD = snd_hda_jack_detect(codec, 0x1c);
  1988. spec->hp_present = !!(portA);
  1989. spec->hp_present |= portD ? 2 : 0;
  1990. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1991. portA, portD, spec->hp_present);
  1992. cxt5066_update_speaker(codec);
  1993. }
  1994. /* unsolicited event for jack sensing */
  1995. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  1996. {
  1997. struct conexant_spec *spec = codec->spec;
  1998. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1999. switch (res >> 26) {
  2000. case CONEXANT_HP_EVENT:
  2001. cxt5066_hp_automute(codec);
  2002. break;
  2003. case CONEXANT_MIC_EVENT:
  2004. /* ignore mic events in DC mode; we're always using the jack */
  2005. if (!spec->dc_enable)
  2006. cxt5066_olpc_automic(codec);
  2007. break;
  2008. }
  2009. }
  2010. /* unsolicited event for jack sensing */
  2011. static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
  2012. {
  2013. snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
  2014. switch (res >> 26) {
  2015. case CONEXANT_HP_EVENT:
  2016. cxt5066_hp_automute(codec);
  2017. break;
  2018. case CONEXANT_MIC_EVENT:
  2019. cxt5066_vostro_automic(codec);
  2020. break;
  2021. }
  2022. }
  2023. /* unsolicited event for jack sensing */
  2024. static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
  2025. {
  2026. snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
  2027. switch (res >> 26) {
  2028. case CONEXANT_HP_EVENT:
  2029. cxt5066_hp_automute(codec);
  2030. break;
  2031. case CONEXANT_MIC_EVENT:
  2032. cxt5066_ideapad_automic(codec);
  2033. break;
  2034. }
  2035. }
  2036. /* unsolicited event for jack sensing */
  2037. static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
  2038. {
  2039. snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
  2040. switch (res >> 26) {
  2041. case CONEXANT_HP_EVENT:
  2042. cxt5066_hp_automute(codec);
  2043. break;
  2044. case CONEXANT_MIC_EVENT:
  2045. cxt5066_thinkpad_automic(codec);
  2046. break;
  2047. }
  2048. }
  2049. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2050. .num_items = 5,
  2051. .items = {
  2052. { "0dB", 0 },
  2053. { "10dB", 1 },
  2054. { "20dB", 2 },
  2055. { "30dB", 3 },
  2056. { "40dB", 4 },
  2057. },
  2058. };
  2059. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2060. {
  2061. struct conexant_spec *spec = codec->spec;
  2062. snd_hda_codec_write_cache(codec, 0x17, 0,
  2063. AC_VERB_SET_AMP_GAIN_MUTE,
  2064. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2065. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2066. if (spec->ideapad || spec->thinkpad) {
  2067. /* adjust the internal mic as well...it is not through 0x17 */
  2068. snd_hda_codec_write_cache(codec, 0x23, 0,
  2069. AC_VERB_SET_AMP_GAIN_MUTE,
  2070. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2071. cxt5066_analog_mic_boost.
  2072. items[spec->mic_boost].index);
  2073. }
  2074. }
  2075. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2076. struct snd_ctl_elem_info *uinfo)
  2077. {
  2078. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2079. }
  2080. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2081. struct snd_ctl_elem_value *ucontrol)
  2082. {
  2083. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2084. struct conexant_spec *spec = codec->spec;
  2085. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2086. return 0;
  2087. }
  2088. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2089. struct snd_ctl_elem_value *ucontrol)
  2090. {
  2091. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2092. struct conexant_spec *spec = codec->spec;
  2093. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2094. unsigned int idx;
  2095. idx = ucontrol->value.enumerated.item[0];
  2096. if (idx >= imux->num_items)
  2097. idx = imux->num_items - 1;
  2098. spec->mic_boost = idx;
  2099. if (!spec->dc_enable)
  2100. cxt5066_set_mic_boost(codec);
  2101. return 1;
  2102. }
  2103. static void cxt5066_enable_dc(struct hda_codec *codec)
  2104. {
  2105. const struct hda_verb enable_dc_mode[] = {
  2106. /* disable gain */
  2107. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2108. /* switch to DC input */
  2109. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2110. {}
  2111. };
  2112. /* configure as input source */
  2113. snd_hda_sequence_write(codec, enable_dc_mode);
  2114. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2115. }
  2116. static void cxt5066_disable_dc(struct hda_codec *codec)
  2117. {
  2118. /* reconfigure input source */
  2119. cxt5066_set_mic_boost(codec);
  2120. /* automic also selects the right mic if we're recording */
  2121. cxt5066_olpc_automic(codec);
  2122. }
  2123. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2124. struct snd_ctl_elem_value *ucontrol)
  2125. {
  2126. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2127. struct conexant_spec *spec = codec->spec;
  2128. ucontrol->value.integer.value[0] = spec->dc_enable;
  2129. return 0;
  2130. }
  2131. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2132. struct snd_ctl_elem_value *ucontrol)
  2133. {
  2134. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2135. struct conexant_spec *spec = codec->spec;
  2136. int dc_enable = !!ucontrol->value.integer.value[0];
  2137. if (dc_enable == spec->dc_enable)
  2138. return 0;
  2139. spec->dc_enable = dc_enable;
  2140. if (dc_enable)
  2141. cxt5066_enable_dc(codec);
  2142. else
  2143. cxt5066_disable_dc(codec);
  2144. return 1;
  2145. }
  2146. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2147. struct snd_ctl_elem_info *uinfo)
  2148. {
  2149. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2150. }
  2151. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2152. struct snd_ctl_elem_value *ucontrol)
  2153. {
  2154. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2155. struct conexant_spec *spec = codec->spec;
  2156. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2157. return 0;
  2158. }
  2159. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2160. struct snd_ctl_elem_value *ucontrol)
  2161. {
  2162. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2163. struct conexant_spec *spec = codec->spec;
  2164. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2165. unsigned int idx;
  2166. idx = ucontrol->value.enumerated.item[0];
  2167. if (idx >= imux->num_items)
  2168. idx = imux->num_items - 1;
  2169. spec->dc_input_bias = idx;
  2170. if (spec->dc_enable)
  2171. cxt5066_set_olpc_dc_bias(codec);
  2172. return 1;
  2173. }
  2174. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2175. {
  2176. struct conexant_spec *spec = codec->spec;
  2177. /* mark as recording and configure the microphone widget so that the
  2178. * recording LED comes on. */
  2179. spec->recording = 1;
  2180. cxt5066_olpc_select_mic(codec);
  2181. }
  2182. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2183. {
  2184. struct conexant_spec *spec = codec->spec;
  2185. const struct hda_verb disable_mics[] = {
  2186. /* disable external mic, port B */
  2187. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2188. /* disble internal mic, port C */
  2189. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2190. /* disable DC capture, port F */
  2191. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2192. {},
  2193. };
  2194. snd_hda_sequence_write(codec, disable_mics);
  2195. spec->recording = 0;
  2196. }
  2197. static struct hda_input_mux cxt5066_capture_source = {
  2198. .num_items = 4,
  2199. .items = {
  2200. { "Mic B", 0 },
  2201. { "Mic C", 1 },
  2202. { "Mic E", 2 },
  2203. { "Mic F", 3 },
  2204. },
  2205. };
  2206. static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2207. .ops = &snd_hda_bind_vol,
  2208. .values = {
  2209. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2210. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2211. 0
  2212. },
  2213. };
  2214. static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2215. .ops = &snd_hda_bind_sw,
  2216. .values = {
  2217. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2218. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2219. 0
  2220. },
  2221. };
  2222. static struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2223. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2224. {}
  2225. };
  2226. static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2227. {
  2228. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2229. .name = "Master Playback Volume",
  2230. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2231. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2232. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2233. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2234. .info = snd_hda_mixer_amp_volume_info,
  2235. .get = snd_hda_mixer_amp_volume_get,
  2236. .put = snd_hda_mixer_amp_volume_put,
  2237. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2238. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2239. .private_value =
  2240. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2241. },
  2242. {}
  2243. };
  2244. static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2245. {
  2246. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2247. .name = "DC Mode Enable Switch",
  2248. .info = snd_ctl_boolean_mono_info,
  2249. .get = cxt5066_olpc_dc_get,
  2250. .put = cxt5066_olpc_dc_put,
  2251. },
  2252. {
  2253. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2254. .name = "DC Input Bias Enum",
  2255. .info = cxt5066_olpc_dc_bias_enum_info,
  2256. .get = cxt5066_olpc_dc_bias_enum_get,
  2257. .put = cxt5066_olpc_dc_bias_enum_put,
  2258. },
  2259. {}
  2260. };
  2261. static struct snd_kcontrol_new cxt5066_mixers[] = {
  2262. {
  2263. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2264. .name = "Master Playback Switch",
  2265. .info = cxt_eapd_info,
  2266. .get = cxt_eapd_get,
  2267. .put = cxt5066_hp_master_sw_put,
  2268. .private_value = 0x1d,
  2269. },
  2270. {
  2271. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2272. .name = "Analog Mic Boost Capture Enum",
  2273. .info = cxt5066_mic_boost_mux_enum_info,
  2274. .get = cxt5066_mic_boost_mux_enum_get,
  2275. .put = cxt5066_mic_boost_mux_enum_put,
  2276. },
  2277. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2278. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2279. {}
  2280. };
  2281. static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2282. {
  2283. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2284. .name = "Int Mic Boost Capture Enum",
  2285. .info = cxt5066_mic_boost_mux_enum_info,
  2286. .get = cxt5066_mic_boost_mux_enum_get,
  2287. .put = cxt5066_mic_boost_mux_enum_put,
  2288. .private_value = 0x23 | 0x100,
  2289. },
  2290. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  2291. {}
  2292. };
  2293. static struct hda_verb cxt5066_init_verbs[] = {
  2294. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2295. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2296. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2297. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2298. /* Speakers */
  2299. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2300. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2301. /* HP, Amp */
  2302. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2303. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2304. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2305. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2306. /* DAC1 */
  2307. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2308. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2309. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2310. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2311. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2312. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2313. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2314. /* no digital microphone support yet */
  2315. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2316. /* Audio input selector */
  2317. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2318. /* SPDIF route: PCM */
  2319. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2320. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2321. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2322. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2323. /* EAPD */
  2324. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2325. /* not handling these yet */
  2326. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2327. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2328. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2329. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2330. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2331. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2332. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2333. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2334. { } /* end */
  2335. };
  2336. static struct hda_verb cxt5066_init_verbs_olpc[] = {
  2337. /* Port A: headphones */
  2338. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2339. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2340. /* Port B: external microphone */
  2341. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2342. /* Port C: internal microphone */
  2343. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2344. /* Port D: unused */
  2345. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2346. /* Port E: unused, but has primary EAPD */
  2347. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2348. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2349. /* Port F: external DC input through microphone port */
  2350. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2351. /* Port G: internal speakers */
  2352. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2353. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2354. /* DAC1 */
  2355. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2356. /* DAC2: unused */
  2357. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2358. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2359. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2360. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2361. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2362. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2363. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2364. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2365. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2366. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2367. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2368. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2369. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2370. /* Disable digital microphone port */
  2371. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2372. /* Audio input selectors */
  2373. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2374. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2375. /* Disable SPDIF */
  2376. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2377. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2378. /* enable unsolicited events for Port A and B */
  2379. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2380. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2381. { } /* end */
  2382. };
  2383. static struct hda_verb cxt5066_init_verbs_vostro[] = {
  2384. /* Port A: headphones */
  2385. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2386. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2387. /* Port B: external microphone */
  2388. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2389. /* Port C: unused */
  2390. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2391. /* Port D: unused */
  2392. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2393. /* Port E: unused, but has primary EAPD */
  2394. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2395. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2396. /* Port F: unused */
  2397. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2398. /* Port G: internal speakers */
  2399. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2400. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2401. /* DAC1 */
  2402. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2403. /* DAC2: unused */
  2404. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2405. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2406. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2407. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2408. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2409. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2410. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2411. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2412. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2413. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2414. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2415. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2416. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2417. /* Digital microphone port */
  2418. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2419. /* Audio input selectors */
  2420. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2421. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2422. /* Disable SPDIF */
  2423. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2424. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2425. /* enable unsolicited events for Port A and B */
  2426. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2427. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2428. { } /* end */
  2429. };
  2430. static struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2431. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2432. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2433. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2434. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2435. /* Speakers */
  2436. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2437. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2438. /* HP, Amp */
  2439. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2440. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2441. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2442. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2443. /* DAC1 */
  2444. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2445. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2446. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2447. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2448. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2449. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2450. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2451. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2452. /* Audio input selector */
  2453. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2454. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2455. /* SPDIF route: PCM */
  2456. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2457. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2458. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2459. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2460. /* internal microphone */
  2461. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
  2462. /* EAPD */
  2463. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2464. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2465. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2466. { } /* end */
  2467. };
  2468. static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2469. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2470. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2471. /* Port G: internal speakers */
  2472. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2473. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2474. /* Port A: HP, Amp */
  2475. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2476. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2477. /* Port B: Mic Dock */
  2478. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2479. /* Port C: Mic */
  2480. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2481. /* Port D: HP Dock, Amp */
  2482. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2483. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2484. /* DAC1 */
  2485. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2486. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2487. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2488. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2489. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2490. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2491. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2492. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2493. /* Audio input selector */
  2494. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2495. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2496. /* SPDIF route: PCM */
  2497. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2498. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2499. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2500. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2501. /* internal microphone */
  2502. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
  2503. /* EAPD */
  2504. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2505. /* enable unsolicited events for Port A, B, C and D */
  2506. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2507. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2508. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2509. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2510. { } /* end */
  2511. };
  2512. static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2513. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2514. { } /* end */
  2515. };
  2516. /* initialize jack-sensing, too */
  2517. static int cxt5066_init(struct hda_codec *codec)
  2518. {
  2519. struct conexant_spec *spec = codec->spec;
  2520. snd_printdd("CXT5066: init\n");
  2521. conexant_init(codec);
  2522. if (codec->patch_ops.unsol_event) {
  2523. cxt5066_hp_automute(codec);
  2524. if (spec->dell_vostro)
  2525. cxt5066_vostro_automic(codec);
  2526. else if (spec->ideapad)
  2527. cxt5066_ideapad_automic(codec);
  2528. else if (spec->thinkpad)
  2529. cxt5066_thinkpad_automic(codec);
  2530. }
  2531. cxt5066_set_mic_boost(codec);
  2532. return 0;
  2533. }
  2534. static int cxt5066_olpc_init(struct hda_codec *codec)
  2535. {
  2536. struct conexant_spec *spec = codec->spec;
  2537. snd_printdd("CXT5066: init\n");
  2538. conexant_init(codec);
  2539. cxt5066_hp_automute(codec);
  2540. if (!spec->dc_enable) {
  2541. cxt5066_set_mic_boost(codec);
  2542. cxt5066_olpc_automic(codec);
  2543. } else {
  2544. cxt5066_enable_dc(codec);
  2545. }
  2546. return 0;
  2547. }
  2548. enum {
  2549. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2550. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2551. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2552. CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
  2553. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2554. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2555. CXT5066_MODELS
  2556. };
  2557. static const char *cxt5066_models[CXT5066_MODELS] = {
  2558. [CXT5066_LAPTOP] = "laptop",
  2559. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2560. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2561. [CXT5066_DELL_VOSTO] = "dell-vostro",
  2562. [CXT5066_IDEAPAD] = "ideapad",
  2563. [CXT5066_THINKPAD] = "thinkpad",
  2564. };
  2565. static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2566. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2567. CXT5066_LAPTOP),
  2568. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
  2569. CXT5066_DELL_LAPTOP),
  2570. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2571. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
  2572. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2573. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2574. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2575. SND_PCI_QUIRK(0x17aa, 0x21b2, "Thinkpad X100e", CXT5066_IDEAPAD),
  2576. SND_PCI_QUIRK(0x17aa, 0x21b3, "Thinkpad Edge 13 (197)", CXT5066_IDEAPAD),
  2577. SND_PCI_QUIRK(0x17aa, 0x21b4, "Thinkpad Edge", CXT5066_IDEAPAD),
  2578. SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
  2579. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2580. {}
  2581. };
  2582. static int patch_cxt5066(struct hda_codec *codec)
  2583. {
  2584. struct conexant_spec *spec;
  2585. int board_config;
  2586. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2587. if (!spec)
  2588. return -ENOMEM;
  2589. codec->spec = spec;
  2590. codec->patch_ops = conexant_patch_ops;
  2591. codec->patch_ops.init = conexant_init;
  2592. spec->dell_automute = 0;
  2593. spec->multiout.max_channels = 2;
  2594. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2595. spec->multiout.dac_nids = cxt5066_dac_nids;
  2596. spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
  2597. spec->num_adc_nids = 1;
  2598. spec->adc_nids = cxt5066_adc_nids;
  2599. spec->capsrc_nids = cxt5066_capsrc_nids;
  2600. spec->input_mux = &cxt5066_capture_source;
  2601. spec->port_d_mode = PIN_HP;
  2602. spec->num_init_verbs = 1;
  2603. spec->init_verbs[0] = cxt5066_init_verbs;
  2604. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2605. spec->channel_mode = cxt5066_modes;
  2606. spec->cur_adc = 0;
  2607. spec->cur_adc_idx = 0;
  2608. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2609. cxt5066_models, cxt5066_cfg_tbl);
  2610. switch (board_config) {
  2611. default:
  2612. case CXT5066_LAPTOP:
  2613. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2614. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2615. break;
  2616. case CXT5066_DELL_LAPTOP:
  2617. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2618. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2619. spec->port_d_mode = PIN_OUT;
  2620. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2621. spec->num_init_verbs++;
  2622. spec->dell_automute = 1;
  2623. break;
  2624. case CXT5066_OLPC_XO_1_5:
  2625. codec->patch_ops.init = cxt5066_olpc_init;
  2626. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2627. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2628. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2629. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2630. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2631. spec->port_d_mode = 0;
  2632. spec->mic_boost = 3; /* default 30dB gain */
  2633. /* no S/PDIF out */
  2634. spec->multiout.dig_out_nid = 0;
  2635. /* input source automatically selected */
  2636. spec->input_mux = NULL;
  2637. /* our capture hooks which allow us to turn on the microphone LED
  2638. * at the right time */
  2639. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2640. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2641. break;
  2642. case CXT5066_DELL_VOSTO:
  2643. codec->patch_ops.init = cxt5066_init;
  2644. codec->patch_ops.unsol_event = cxt5066_vostro_event;
  2645. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2646. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2647. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2648. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2649. spec->port_d_mode = 0;
  2650. spec->dell_vostro = 1;
  2651. spec->mic_boost = 3; /* default 30dB gain */
  2652. snd_hda_attach_beep_device(codec, 0x13);
  2653. /* no S/PDIF out */
  2654. spec->multiout.dig_out_nid = 0;
  2655. /* input source automatically selected */
  2656. spec->input_mux = NULL;
  2657. break;
  2658. case CXT5066_IDEAPAD:
  2659. codec->patch_ops.init = cxt5066_init;
  2660. codec->patch_ops.unsol_event = cxt5066_ideapad_event;
  2661. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2662. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2663. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2664. spec->port_d_mode = 0;
  2665. spec->ideapad = 1;
  2666. spec->mic_boost = 2; /* default 20dB gain */
  2667. /* no S/PDIF out */
  2668. spec->multiout.dig_out_nid = 0;
  2669. /* input source automatically selected */
  2670. spec->input_mux = NULL;
  2671. break;
  2672. case CXT5066_THINKPAD:
  2673. codec->patch_ops.init = cxt5066_init;
  2674. codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
  2675. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2676. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2677. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2678. spec->thinkpad = 1;
  2679. spec->port_d_mode = PIN_OUT;
  2680. spec->mic_boost = 2; /* default 20dB gain */
  2681. /* no S/PDIF out */
  2682. spec->multiout.dig_out_nid = 0;
  2683. /* input source automatically selected */
  2684. spec->input_mux = NULL;
  2685. break;
  2686. }
  2687. return 0;
  2688. }
  2689. /*
  2690. */
  2691. static struct hda_codec_preset snd_hda_preset_conexant[] = {
  2692. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  2693. .patch = patch_cxt5045 },
  2694. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  2695. .patch = patch_cxt5047 },
  2696. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  2697. .patch = patch_cxt5051 },
  2698. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  2699. .patch = patch_cxt5066 },
  2700. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  2701. .patch = patch_cxt5066 },
  2702. { .id = 0x14f15069, .name = "CX20585",
  2703. .patch = patch_cxt5066 },
  2704. {} /* terminator */
  2705. };
  2706. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  2707. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  2708. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  2709. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  2710. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  2711. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  2712. MODULE_LICENSE("GPL");
  2713. MODULE_DESCRIPTION("Conexant HD-audio codec");
  2714. static struct hda_codec_preset_list conexant_list = {
  2715. .preset = snd_hda_preset_conexant,
  2716. .owner = THIS_MODULE,
  2717. };
  2718. static int __init patch_conexant_init(void)
  2719. {
  2720. return snd_hda_add_codec_preset(&conexant_list);
  2721. }
  2722. static void __exit patch_conexant_exit(void)
  2723. {
  2724. snd_hda_delete_codec_preset(&conexant_list);
  2725. }
  2726. module_init(patch_conexant_init)
  2727. module_exit(patch_conexant_exit)