patch_conexant.c 94 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149
  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. /* HP, Packard Bell, & Fujitsu-Siemens laptops have really bad
  1045. * sound over 0dB on NID 0x17. Fix max PCM level to 0 dB
  1046. * (originally it has 0x2b steps with 0dB offset 0x14)
  1047. */
  1048. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1049. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1050. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1051. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1052. (1 << AC_AMPCAP_MUTE_SHIFT));
  1053. break;
  1054. }
  1055. return 0;
  1056. }
  1057. /* Conexant 5047 specific */
  1058. #define CXT5047_SPDIF_OUT 0x11
  1059. static hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1060. static hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1061. static hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1062. static struct hda_channel_mode cxt5047_modes[1] = {
  1063. { 2, NULL },
  1064. };
  1065. static struct hda_input_mux cxt5047_toshiba_capture_source = {
  1066. .num_items = 2,
  1067. .items = {
  1068. { "ExtMic", 0x2 },
  1069. { "Line-In", 0x1 },
  1070. }
  1071. };
  1072. /* turn on/off EAPD (+ mute HP) as a master switch */
  1073. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1074. struct snd_ctl_elem_value *ucontrol)
  1075. {
  1076. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1077. struct conexant_spec *spec = codec->spec;
  1078. unsigned int bits;
  1079. if (!cxt_eapd_put(kcontrol, ucontrol))
  1080. return 0;
  1081. /* toggle internal speakers mute depending of presence of
  1082. * the headphone jack
  1083. */
  1084. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1085. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1086. * pin widgets unlike other codecs. In this case, we need to
  1087. * set index 0x01 for the volume from the mixer amp 0x19.
  1088. */
  1089. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1090. HDA_AMP_MUTE, bits);
  1091. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1092. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1093. HDA_AMP_MUTE, bits);
  1094. return 1;
  1095. }
  1096. /* mute internal speaker if HP is plugged */
  1097. static void cxt5047_hp_automute(struct hda_codec *codec)
  1098. {
  1099. struct conexant_spec *spec = codec->spec;
  1100. unsigned int bits;
  1101. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1102. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1103. /* See the note in cxt5047_hp_master_sw_put */
  1104. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1105. HDA_AMP_MUTE, bits);
  1106. }
  1107. /* toggle input of built-in and mic jack appropriately */
  1108. static void cxt5047_hp_automic(struct hda_codec *codec)
  1109. {
  1110. static struct hda_verb mic_jack_on[] = {
  1111. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1112. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1113. {}
  1114. };
  1115. static struct hda_verb mic_jack_off[] = {
  1116. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1117. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1118. {}
  1119. };
  1120. unsigned int present;
  1121. present = snd_hda_jack_detect(codec, 0x15);
  1122. if (present)
  1123. snd_hda_sequence_write(codec, mic_jack_on);
  1124. else
  1125. snd_hda_sequence_write(codec, mic_jack_off);
  1126. }
  1127. /* unsolicited event for HP jack sensing */
  1128. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1129. unsigned int res)
  1130. {
  1131. switch (res >> 26) {
  1132. case CONEXANT_HP_EVENT:
  1133. cxt5047_hp_automute(codec);
  1134. break;
  1135. case CONEXANT_MIC_EVENT:
  1136. cxt5047_hp_automic(codec);
  1137. break;
  1138. }
  1139. }
  1140. static struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1141. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1142. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1143. HDA_CODEC_VOLUME("Mic Boost", 0x1a, 0x0, HDA_OUTPUT),
  1144. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1145. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1146. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1147. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1148. {
  1149. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1150. .name = "Master Playback Switch",
  1151. .info = cxt_eapd_info,
  1152. .get = cxt_eapd_get,
  1153. .put = cxt5047_hp_master_sw_put,
  1154. .private_value = 0x13,
  1155. },
  1156. {}
  1157. };
  1158. static struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1159. /* See the note in cxt5047_hp_master_sw_put */
  1160. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1161. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1162. {}
  1163. };
  1164. static struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1165. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1166. { } /* end */
  1167. };
  1168. static struct hda_verb cxt5047_init_verbs[] = {
  1169. /* Line in, Mic, Built-in Mic */
  1170. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1171. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1172. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1173. /* HP, Speaker */
  1174. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1175. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1176. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1177. /* Record selector: Mic */
  1178. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1179. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1180. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1181. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1182. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1183. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1184. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1185. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1186. /* SPDIF route: PCM */
  1187. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1188. /* Enable unsolicited events */
  1189. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1190. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1191. { } /* end */
  1192. };
  1193. /* configuration for Toshiba Laptops */
  1194. static struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1195. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1196. {}
  1197. };
  1198. /* Test configuration for debugging, modelled after the ALC260 test
  1199. * configuration.
  1200. */
  1201. #ifdef CONFIG_SND_DEBUG
  1202. static struct hda_input_mux cxt5047_test_capture_source = {
  1203. .num_items = 4,
  1204. .items = {
  1205. { "LINE1 pin", 0x0 },
  1206. { "MIC1 pin", 0x1 },
  1207. { "MIC2 pin", 0x2 },
  1208. { "CD pin", 0x3 },
  1209. },
  1210. };
  1211. static struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1212. /* Output only controls */
  1213. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1214. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1215. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1216. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1217. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1218. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1219. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1220. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1221. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1222. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1223. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1224. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1225. /* Modes for retasking pin widgets */
  1226. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1227. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1228. /* EAPD Switch Control */
  1229. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1230. /* Loopback mixer controls */
  1231. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1232. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1233. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1234. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1235. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1236. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1237. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1238. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1239. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1240. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1241. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1242. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1243. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1244. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1245. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1246. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1247. {
  1248. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1249. .name = "Input Source",
  1250. .info = conexant_mux_enum_info,
  1251. .get = conexant_mux_enum_get,
  1252. .put = conexant_mux_enum_put,
  1253. },
  1254. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1255. { } /* end */
  1256. };
  1257. static struct hda_verb cxt5047_test_init_verbs[] = {
  1258. /* Enable retasking pins as output, initially without power amp */
  1259. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1260. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1261. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1262. /* Disable digital (SPDIF) pins initially, but users can enable
  1263. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1264. * payload also sets the generation to 0, output to be in "consumer"
  1265. * PCM format, copyright asserted, no pre-emphasis and no validity
  1266. * control.
  1267. */
  1268. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1269. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1270. * OUT1 sum bus when acting as an output.
  1271. */
  1272. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1273. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1274. /* Start with output sum widgets muted and their output gains at min */
  1275. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1276. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1277. /* Unmute retasking pin widget output buffers since the default
  1278. * state appears to be output. As the pin mode is changed by the
  1279. * user the pin mode control will take care of enabling the pin's
  1280. * input/output buffers as needed.
  1281. */
  1282. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1283. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1284. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1285. /* Mute capture amp left and right */
  1286. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1287. /* Set ADC connection select to match default mixer setting (mic1
  1288. * pin)
  1289. */
  1290. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1291. /* Mute all inputs to mixer widget (even unconnected ones) */
  1292. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1293. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1294. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1295. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1296. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1297. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1298. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1299. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1300. { }
  1301. };
  1302. #endif
  1303. /* initialize jack-sensing, too */
  1304. static int cxt5047_hp_init(struct hda_codec *codec)
  1305. {
  1306. conexant_init(codec);
  1307. cxt5047_hp_automute(codec);
  1308. return 0;
  1309. }
  1310. enum {
  1311. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1312. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1313. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1314. #ifdef CONFIG_SND_DEBUG
  1315. CXT5047_TEST,
  1316. #endif
  1317. CXT5047_MODELS
  1318. };
  1319. static const char *cxt5047_models[CXT5047_MODELS] = {
  1320. [CXT5047_LAPTOP] = "laptop",
  1321. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1322. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1323. #ifdef CONFIG_SND_DEBUG
  1324. [CXT5047_TEST] = "test",
  1325. #endif
  1326. };
  1327. static struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1328. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1329. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1330. CXT5047_LAPTOP),
  1331. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1332. {}
  1333. };
  1334. static int patch_cxt5047(struct hda_codec *codec)
  1335. {
  1336. struct conexant_spec *spec;
  1337. int board_config;
  1338. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1339. if (!spec)
  1340. return -ENOMEM;
  1341. codec->spec = spec;
  1342. codec->pin_amp_workaround = 1;
  1343. spec->multiout.max_channels = 2;
  1344. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1345. spec->multiout.dac_nids = cxt5047_dac_nids;
  1346. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1347. spec->num_adc_nids = 1;
  1348. spec->adc_nids = cxt5047_adc_nids;
  1349. spec->capsrc_nids = cxt5047_capsrc_nids;
  1350. spec->num_mixers = 1;
  1351. spec->mixers[0] = cxt5047_base_mixers;
  1352. spec->num_init_verbs = 1;
  1353. spec->init_verbs[0] = cxt5047_init_verbs;
  1354. spec->spdif_route = 0;
  1355. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1356. spec->channel_mode = cxt5047_modes,
  1357. codec->patch_ops = conexant_patch_ops;
  1358. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1359. cxt5047_models,
  1360. cxt5047_cfg_tbl);
  1361. switch (board_config) {
  1362. case CXT5047_LAPTOP:
  1363. spec->num_mixers = 2;
  1364. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1365. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1366. break;
  1367. case CXT5047_LAPTOP_HP:
  1368. spec->num_mixers = 2;
  1369. spec->mixers[1] = cxt5047_hp_only_mixers;
  1370. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1371. codec->patch_ops.init = cxt5047_hp_init;
  1372. break;
  1373. case CXT5047_LAPTOP_EAPD:
  1374. spec->input_mux = &cxt5047_toshiba_capture_source;
  1375. spec->num_mixers = 2;
  1376. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1377. spec->num_init_verbs = 2;
  1378. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1379. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1380. break;
  1381. #ifdef CONFIG_SND_DEBUG
  1382. case CXT5047_TEST:
  1383. spec->input_mux = &cxt5047_test_capture_source;
  1384. spec->mixers[0] = cxt5047_test_mixer;
  1385. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1386. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1387. #endif
  1388. }
  1389. spec->vmaster_nid = 0x13;
  1390. switch (codec->subsystem_id >> 16) {
  1391. case 0x103c:
  1392. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1393. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1394. * with 0 dB offset 0x17)
  1395. */
  1396. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1397. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1398. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1399. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1400. (1 << AC_AMPCAP_MUTE_SHIFT));
  1401. break;
  1402. }
  1403. return 0;
  1404. }
  1405. /* Conexant 5051 specific */
  1406. static hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1407. static hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1408. static struct hda_channel_mode cxt5051_modes[1] = {
  1409. { 2, NULL },
  1410. };
  1411. static void cxt5051_update_speaker(struct hda_codec *codec)
  1412. {
  1413. struct conexant_spec *spec = codec->spec;
  1414. unsigned int pinctl;
  1415. /* headphone pin */
  1416. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1417. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1418. pinctl);
  1419. /* speaker pin */
  1420. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1421. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1422. pinctl);
  1423. }
  1424. /* turn on/off EAPD (+ mute HP) as a master switch */
  1425. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1426. struct snd_ctl_elem_value *ucontrol)
  1427. {
  1428. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1429. if (!cxt_eapd_put(kcontrol, ucontrol))
  1430. return 0;
  1431. cxt5051_update_speaker(codec);
  1432. return 1;
  1433. }
  1434. /* toggle input of built-in and mic jack appropriately */
  1435. static void cxt5051_portb_automic(struct hda_codec *codec)
  1436. {
  1437. struct conexant_spec *spec = codec->spec;
  1438. unsigned int present;
  1439. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1440. return;
  1441. present = snd_hda_jack_detect(codec, 0x17);
  1442. snd_hda_codec_write(codec, 0x14, 0,
  1443. AC_VERB_SET_CONNECT_SEL,
  1444. present ? 0x01 : 0x00);
  1445. }
  1446. /* switch the current ADC according to the jack state */
  1447. static void cxt5051_portc_automic(struct hda_codec *codec)
  1448. {
  1449. struct conexant_spec *spec = codec->spec;
  1450. unsigned int present;
  1451. hda_nid_t new_adc;
  1452. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1453. return;
  1454. present = snd_hda_jack_detect(codec, 0x18);
  1455. if (present)
  1456. spec->cur_adc_idx = 1;
  1457. else
  1458. spec->cur_adc_idx = 0;
  1459. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1460. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1461. /* stream is running, let's swap the current ADC */
  1462. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  1463. spec->cur_adc = new_adc;
  1464. snd_hda_codec_setup_stream(codec, new_adc,
  1465. spec->cur_adc_stream_tag, 0,
  1466. spec->cur_adc_format);
  1467. }
  1468. }
  1469. /* mute internal speaker if HP is plugged */
  1470. static void cxt5051_hp_automute(struct hda_codec *codec)
  1471. {
  1472. struct conexant_spec *spec = codec->spec;
  1473. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1474. cxt5051_update_speaker(codec);
  1475. }
  1476. /* unsolicited event for HP jack sensing */
  1477. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1478. unsigned int res)
  1479. {
  1480. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1481. switch (res >> 26) {
  1482. case CONEXANT_HP_EVENT:
  1483. cxt5051_hp_automute(codec);
  1484. break;
  1485. case CXT5051_PORTB_EVENT:
  1486. cxt5051_portb_automic(codec);
  1487. break;
  1488. case CXT5051_PORTC_EVENT:
  1489. cxt5051_portc_automic(codec);
  1490. break;
  1491. }
  1492. conexant_report_jack(codec, nid);
  1493. }
  1494. static struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1495. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1496. {
  1497. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1498. .name = "Master Playback Switch",
  1499. .info = cxt_eapd_info,
  1500. .get = cxt_eapd_get,
  1501. .put = cxt5051_hp_master_sw_put,
  1502. .private_value = 0x1a,
  1503. },
  1504. {}
  1505. };
  1506. static struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1507. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1508. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1509. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1510. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1511. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1512. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1513. {}
  1514. };
  1515. static struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1516. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1517. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1518. HDA_CODEC_VOLUME("External Mic Volume", 0x15, 0x00, HDA_INPUT),
  1519. HDA_CODEC_MUTE("External Mic Switch", 0x15, 0x00, HDA_INPUT),
  1520. {}
  1521. };
  1522. static struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1523. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1524. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1525. {}
  1526. };
  1527. static struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1528. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1529. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1530. {}
  1531. };
  1532. static struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1533. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1534. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1535. HDA_CODEC_VOLUME("External Mic Volume", 0x14, 0x01, HDA_INPUT),
  1536. HDA_CODEC_MUTE("External Mic Switch", 0x14, 0x01, HDA_INPUT),
  1537. {}
  1538. };
  1539. static struct hda_verb cxt5051_init_verbs[] = {
  1540. /* Line in, Mic */
  1541. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1542. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1543. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1544. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1545. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1546. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1547. /* SPK */
  1548. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1549. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1550. /* HP, Amp */
  1551. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1552. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1553. /* DAC1 */
  1554. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1555. /* Record selector: Int mic */
  1556. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1557. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1558. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1559. /* SPDIF route: PCM */
  1560. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1561. /* EAPD */
  1562. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1563. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1564. { } /* end */
  1565. };
  1566. static struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1567. /* Line in, Mic */
  1568. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1569. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1570. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1571. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1572. /* SPK */
  1573. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1574. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1575. /* HP, Amp */
  1576. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1577. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1578. /* DAC1 */
  1579. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1580. /* Record selector: Int mic */
  1581. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1582. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1583. /* SPDIF route: PCM */
  1584. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1585. /* EAPD */
  1586. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1587. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1588. { } /* end */
  1589. };
  1590. static struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1591. /* Line in, Mic */
  1592. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1593. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1594. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1595. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1596. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1597. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1598. /* SPK */
  1599. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1600. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1601. /* HP, Amp */
  1602. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1603. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1604. /* Docking HP */
  1605. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1606. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1607. /* DAC1 */
  1608. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1609. /* Record selector: Int mic */
  1610. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1611. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1612. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1613. /* SPDIF route: PCM */
  1614. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1615. /* EAPD */
  1616. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1617. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1618. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1619. { } /* end */
  1620. };
  1621. static struct hda_verb cxt5051_f700_init_verbs[] = {
  1622. /* Line in, Mic */
  1623. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1624. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1625. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1626. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1627. /* SPK */
  1628. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1629. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1630. /* HP, Amp */
  1631. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1632. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1633. /* DAC1 */
  1634. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1635. /* Record selector: Int mic */
  1636. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1637. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1638. /* SPDIF route: PCM */
  1639. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1640. /* EAPD */
  1641. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1642. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1643. { } /* end */
  1644. };
  1645. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1646. unsigned int event)
  1647. {
  1648. snd_hda_codec_write(codec, nid, 0,
  1649. AC_VERB_SET_UNSOLICITED_ENABLE,
  1650. AC_USRSP_EN | event);
  1651. #ifdef CONFIG_SND_HDA_INPUT_JACK
  1652. conexant_add_jack(codec, nid, SND_JACK_MICROPHONE);
  1653. conexant_report_jack(codec, nid);
  1654. #endif
  1655. }
  1656. /* initialize jack-sensing, too */
  1657. static int cxt5051_init(struct hda_codec *codec)
  1658. {
  1659. struct conexant_spec *spec = codec->spec;
  1660. conexant_init(codec);
  1661. conexant_init_jacks(codec);
  1662. if (spec->auto_mic & AUTO_MIC_PORTB)
  1663. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1664. if (spec->auto_mic & AUTO_MIC_PORTC)
  1665. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1666. if (codec->patch_ops.unsol_event) {
  1667. cxt5051_hp_automute(codec);
  1668. cxt5051_portb_automic(codec);
  1669. cxt5051_portc_automic(codec);
  1670. }
  1671. return 0;
  1672. }
  1673. enum {
  1674. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1675. CXT5051_HP, /* no docking */
  1676. CXT5051_HP_DV6736, /* HP without mic switch */
  1677. CXT5051_LENOVO_X200, /* Lenovo X200 laptop */
  1678. CXT5051_F700, /* HP Compaq Presario F700 */
  1679. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1680. CXT5051_MODELS
  1681. };
  1682. static const char *cxt5051_models[CXT5051_MODELS] = {
  1683. [CXT5051_LAPTOP] = "laptop",
  1684. [CXT5051_HP] = "hp",
  1685. [CXT5051_HP_DV6736] = "hp-dv6736",
  1686. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1687. [CXT5051_F700] = "hp-700",
  1688. [CXT5051_TOSHIBA] = "toshiba",
  1689. };
  1690. static struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1691. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1692. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1693. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1694. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1695. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1696. CXT5051_LAPTOP),
  1697. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1698. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1699. {}
  1700. };
  1701. static int patch_cxt5051(struct hda_codec *codec)
  1702. {
  1703. struct conexant_spec *spec;
  1704. int board_config;
  1705. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1706. if (!spec)
  1707. return -ENOMEM;
  1708. codec->spec = spec;
  1709. codec->pin_amp_workaround = 1;
  1710. codec->patch_ops = conexant_patch_ops;
  1711. codec->patch_ops.init = cxt5051_init;
  1712. spec->multiout.max_channels = 2;
  1713. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1714. spec->multiout.dac_nids = cxt5051_dac_nids;
  1715. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1716. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1717. spec->adc_nids = cxt5051_adc_nids;
  1718. spec->num_mixers = 2;
  1719. spec->mixers[0] = cxt5051_capture_mixers;
  1720. spec->mixers[1] = cxt5051_playback_mixers;
  1721. spec->num_init_verbs = 1;
  1722. spec->init_verbs[0] = cxt5051_init_verbs;
  1723. spec->spdif_route = 0;
  1724. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1725. spec->channel_mode = cxt5051_modes;
  1726. spec->cur_adc = 0;
  1727. spec->cur_adc_idx = 0;
  1728. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1729. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1730. cxt5051_models,
  1731. cxt5051_cfg_tbl);
  1732. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1733. switch (board_config) {
  1734. case CXT5051_HP:
  1735. spec->mixers[0] = cxt5051_hp_mixers;
  1736. break;
  1737. case CXT5051_HP_DV6736:
  1738. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1739. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1740. spec->auto_mic = 0;
  1741. break;
  1742. case CXT5051_LENOVO_X200:
  1743. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1744. break;
  1745. case CXT5051_F700:
  1746. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1747. spec->mixers[0] = cxt5051_f700_mixers;
  1748. spec->auto_mic = 0;
  1749. break;
  1750. case CXT5051_TOSHIBA:
  1751. spec->mixers[0] = cxt5051_toshiba_mixers;
  1752. spec->auto_mic = AUTO_MIC_PORTB;
  1753. break;
  1754. }
  1755. return 0;
  1756. }
  1757. /* Conexant 5066 specific */
  1758. static hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1759. static hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1760. static hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1761. #define CXT5066_SPDIF_OUT 0x21
  1762. /* OLPC's microphone port is DC coupled for use with external sensors,
  1763. * therefore we use a 50% mic bias in order to center the input signal with
  1764. * the DC input range of the codec. */
  1765. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1766. static struct hda_channel_mode cxt5066_modes[1] = {
  1767. { 2, NULL },
  1768. };
  1769. static void cxt5066_update_speaker(struct hda_codec *codec)
  1770. {
  1771. struct conexant_spec *spec = codec->spec;
  1772. unsigned int pinctl;
  1773. snd_printdd("CXT5066: update speaker, hp_present=%d\n",
  1774. spec->hp_present);
  1775. /* Port A (HP) */
  1776. pinctl = ((spec->hp_present & 1) && spec->cur_eapd) ? PIN_HP : 0;
  1777. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1778. pinctl);
  1779. /* Port D (HP/LO) */
  1780. pinctl = ((spec->hp_present & 2) && spec->cur_eapd)
  1781. ? spec->port_d_mode : 0;
  1782. /* Mute if Port A is connected on Thinkpad */
  1783. if (spec->thinkpad && (spec->hp_present & 1))
  1784. pinctl = 0;
  1785. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1786. pinctl);
  1787. /* CLASS_D AMP */
  1788. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1789. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1790. pinctl);
  1791. if (spec->dell_automute) {
  1792. /* DELL AIO Port Rule: PortA > PortD > IntSpk */
  1793. pinctl = (!(spec->hp_present & 1) && spec->cur_eapd)
  1794. ? PIN_OUT : 0;
  1795. snd_hda_codec_write(codec, 0x1c, 0,
  1796. AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
  1797. }
  1798. }
  1799. /* turn on/off EAPD (+ mute HP) as a master switch */
  1800. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1801. struct snd_ctl_elem_value *ucontrol)
  1802. {
  1803. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1804. if (!cxt_eapd_put(kcontrol, ucontrol))
  1805. return 0;
  1806. cxt5066_update_speaker(codec);
  1807. return 1;
  1808. }
  1809. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1810. .num_items = 3,
  1811. .items = {
  1812. { "Off", PIN_IN },
  1813. { "50%", PIN_VREF50 },
  1814. { "80%", PIN_VREF80 },
  1815. },
  1816. };
  1817. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1818. {
  1819. struct conexant_spec *spec = codec->spec;
  1820. /* Even though port F is the DC input, the bias is controlled on port B.
  1821. * we also leave that port as an active input (but unselected) in DC mode
  1822. * just in case that is necessary to make the bias setting take effect. */
  1823. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1824. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1825. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1826. }
  1827. /* OLPC defers mic widget control until when capture is started because the
  1828. * microphone LED comes on as soon as these settings are put in place. if we
  1829. * did this before recording, it would give the false indication that recording
  1830. * is happening when it is not. */
  1831. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1832. {
  1833. struct conexant_spec *spec = codec->spec;
  1834. if (!spec->recording)
  1835. return;
  1836. if (spec->dc_enable) {
  1837. /* in DC mode we ignore presence detection and just use the jack
  1838. * through our special DC port */
  1839. const struct hda_verb enable_dc_mode[] = {
  1840. /* disble internal mic, port C */
  1841. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1842. /* enable DC capture, port F */
  1843. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1844. {},
  1845. };
  1846. snd_hda_sequence_write(codec, enable_dc_mode);
  1847. /* port B input disabled (and bias set) through the following call */
  1848. cxt5066_set_olpc_dc_bias(codec);
  1849. return;
  1850. }
  1851. /* disable DC (port F) */
  1852. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1853. /* external mic, port B */
  1854. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1855. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1856. /* internal mic, port C */
  1857. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1858. spec->ext_mic_present ? 0 : PIN_VREF80);
  1859. }
  1860. /* toggle input of built-in and mic jack appropriately */
  1861. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1862. {
  1863. struct conexant_spec *spec = codec->spec;
  1864. unsigned int present;
  1865. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1866. return;
  1867. present = snd_hda_codec_read(codec, 0x1a, 0,
  1868. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1869. if (present)
  1870. snd_printdd("CXT5066: external microphone detected\n");
  1871. else
  1872. snd_printdd("CXT5066: external microphone absent\n");
  1873. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1874. present ? 0 : 1);
  1875. spec->ext_mic_present = !!present;
  1876. cxt5066_olpc_select_mic(codec);
  1877. }
  1878. /* toggle input of built-in digital mic and mic jack appropriately */
  1879. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1880. {
  1881. unsigned int present;
  1882. struct hda_verb ext_mic_present[] = {
  1883. /* enable external mic, port B */
  1884. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1885. /* switch to external mic input */
  1886. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1887. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1888. /* disable internal digital mic */
  1889. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1890. {}
  1891. };
  1892. static struct hda_verb ext_mic_absent[] = {
  1893. /* enable internal mic, port C */
  1894. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1895. /* switch to internal mic input */
  1896. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1897. /* disable external mic, port B */
  1898. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1899. {}
  1900. };
  1901. present = snd_hda_jack_detect(codec, 0x1a);
  1902. if (present) {
  1903. snd_printdd("CXT5066: external microphone detected\n");
  1904. snd_hda_sequence_write(codec, ext_mic_present);
  1905. } else {
  1906. snd_printdd("CXT5066: external microphone absent\n");
  1907. snd_hda_sequence_write(codec, ext_mic_absent);
  1908. }
  1909. }
  1910. /* toggle input of built-in digital mic and mic jack appropriately */
  1911. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1912. {
  1913. unsigned int present;
  1914. struct hda_verb ext_mic_present[] = {
  1915. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1916. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1917. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1918. {}
  1919. };
  1920. static struct hda_verb ext_mic_absent[] = {
  1921. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1922. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1923. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1924. {}
  1925. };
  1926. present = snd_hda_jack_detect(codec, 0x1b);
  1927. if (present) {
  1928. snd_printdd("CXT5066: external microphone detected\n");
  1929. snd_hda_sequence_write(codec, ext_mic_present);
  1930. } else {
  1931. snd_printdd("CXT5066: external microphone absent\n");
  1932. snd_hda_sequence_write(codec, ext_mic_absent);
  1933. }
  1934. }
  1935. /* toggle input of built-in digital mic and mic jack appropriately
  1936. order is: external mic -> dock mic -> interal mic */
  1937. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1938. {
  1939. unsigned int ext_present, dock_present;
  1940. static struct hda_verb ext_mic_present[] = {
  1941. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1942. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  1943. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1944. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1945. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1946. {}
  1947. };
  1948. static struct hda_verb dock_mic_present[] = {
  1949. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1950. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1951. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1952. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1953. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1954. {}
  1955. };
  1956. static struct hda_verb ext_mic_absent[] = {
  1957. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1958. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1959. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1960. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1961. {}
  1962. };
  1963. ext_present = snd_hda_jack_detect(codec, 0x1b);
  1964. dock_present = snd_hda_jack_detect(codec, 0x1a);
  1965. if (ext_present) {
  1966. snd_printdd("CXT5066: external microphone detected\n");
  1967. snd_hda_sequence_write(codec, ext_mic_present);
  1968. } else if (dock_present) {
  1969. snd_printdd("CXT5066: dock microphone detected\n");
  1970. snd_hda_sequence_write(codec, dock_mic_present);
  1971. } else {
  1972. snd_printdd("CXT5066: external microphone absent\n");
  1973. snd_hda_sequence_write(codec, ext_mic_absent);
  1974. }
  1975. }
  1976. /* mute internal speaker if HP is plugged */
  1977. static void cxt5066_hp_automute(struct hda_codec *codec)
  1978. {
  1979. struct conexant_spec *spec = codec->spec;
  1980. unsigned int portA, portD;
  1981. /* Port A */
  1982. portA = snd_hda_jack_detect(codec, 0x19);
  1983. /* Port D */
  1984. portD = snd_hda_jack_detect(codec, 0x1c);
  1985. spec->hp_present = !!(portA);
  1986. spec->hp_present |= portD ? 2 : 0;
  1987. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  1988. portA, portD, spec->hp_present);
  1989. cxt5066_update_speaker(codec);
  1990. }
  1991. /* unsolicited event for jack sensing */
  1992. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  1993. {
  1994. struct conexant_spec *spec = codec->spec;
  1995. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  1996. switch (res >> 26) {
  1997. case CONEXANT_HP_EVENT:
  1998. cxt5066_hp_automute(codec);
  1999. break;
  2000. case CONEXANT_MIC_EVENT:
  2001. /* ignore mic events in DC mode; we're always using the jack */
  2002. if (!spec->dc_enable)
  2003. cxt5066_olpc_automic(codec);
  2004. break;
  2005. }
  2006. }
  2007. /* unsolicited event for jack sensing */
  2008. static void cxt5066_vostro_event(struct hda_codec *codec, unsigned int res)
  2009. {
  2010. snd_printdd("CXT5066_vostro: unsol event %x (%x)\n", res, res >> 26);
  2011. switch (res >> 26) {
  2012. case CONEXANT_HP_EVENT:
  2013. cxt5066_hp_automute(codec);
  2014. break;
  2015. case CONEXANT_MIC_EVENT:
  2016. cxt5066_vostro_automic(codec);
  2017. break;
  2018. }
  2019. }
  2020. /* unsolicited event for jack sensing */
  2021. static void cxt5066_ideapad_event(struct hda_codec *codec, unsigned int res)
  2022. {
  2023. snd_printdd("CXT5066_ideapad: unsol event %x (%x)\n", res, res >> 26);
  2024. switch (res >> 26) {
  2025. case CONEXANT_HP_EVENT:
  2026. cxt5066_hp_automute(codec);
  2027. break;
  2028. case CONEXANT_MIC_EVENT:
  2029. cxt5066_ideapad_automic(codec);
  2030. break;
  2031. }
  2032. }
  2033. /* unsolicited event for jack sensing */
  2034. static void cxt5066_thinkpad_event(struct hda_codec *codec, unsigned int res)
  2035. {
  2036. snd_printdd("CXT5066_thinkpad: unsol event %x (%x)\n", res, res >> 26);
  2037. switch (res >> 26) {
  2038. case CONEXANT_HP_EVENT:
  2039. cxt5066_hp_automute(codec);
  2040. break;
  2041. case CONEXANT_MIC_EVENT:
  2042. cxt5066_thinkpad_automic(codec);
  2043. break;
  2044. }
  2045. }
  2046. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2047. .num_items = 5,
  2048. .items = {
  2049. { "0dB", 0 },
  2050. { "10dB", 1 },
  2051. { "20dB", 2 },
  2052. { "30dB", 3 },
  2053. { "40dB", 4 },
  2054. },
  2055. };
  2056. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2057. {
  2058. struct conexant_spec *spec = codec->spec;
  2059. snd_hda_codec_write_cache(codec, 0x17, 0,
  2060. AC_VERB_SET_AMP_GAIN_MUTE,
  2061. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2062. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2063. if (spec->ideapad || spec->thinkpad) {
  2064. /* adjust the internal mic as well...it is not through 0x17 */
  2065. snd_hda_codec_write_cache(codec, 0x23, 0,
  2066. AC_VERB_SET_AMP_GAIN_MUTE,
  2067. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2068. cxt5066_analog_mic_boost.
  2069. items[spec->mic_boost].index);
  2070. }
  2071. }
  2072. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2073. struct snd_ctl_elem_info *uinfo)
  2074. {
  2075. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2076. }
  2077. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2078. struct snd_ctl_elem_value *ucontrol)
  2079. {
  2080. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2081. struct conexant_spec *spec = codec->spec;
  2082. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2083. return 0;
  2084. }
  2085. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2086. struct snd_ctl_elem_value *ucontrol)
  2087. {
  2088. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2089. struct conexant_spec *spec = codec->spec;
  2090. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2091. unsigned int idx;
  2092. idx = ucontrol->value.enumerated.item[0];
  2093. if (idx >= imux->num_items)
  2094. idx = imux->num_items - 1;
  2095. spec->mic_boost = idx;
  2096. if (!spec->dc_enable)
  2097. cxt5066_set_mic_boost(codec);
  2098. return 1;
  2099. }
  2100. static void cxt5066_enable_dc(struct hda_codec *codec)
  2101. {
  2102. const struct hda_verb enable_dc_mode[] = {
  2103. /* disable gain */
  2104. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2105. /* switch to DC input */
  2106. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2107. {}
  2108. };
  2109. /* configure as input source */
  2110. snd_hda_sequence_write(codec, enable_dc_mode);
  2111. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2112. }
  2113. static void cxt5066_disable_dc(struct hda_codec *codec)
  2114. {
  2115. /* reconfigure input source */
  2116. cxt5066_set_mic_boost(codec);
  2117. /* automic also selects the right mic if we're recording */
  2118. cxt5066_olpc_automic(codec);
  2119. }
  2120. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2121. struct snd_ctl_elem_value *ucontrol)
  2122. {
  2123. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2124. struct conexant_spec *spec = codec->spec;
  2125. ucontrol->value.integer.value[0] = spec->dc_enable;
  2126. return 0;
  2127. }
  2128. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2129. struct snd_ctl_elem_value *ucontrol)
  2130. {
  2131. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2132. struct conexant_spec *spec = codec->spec;
  2133. int dc_enable = !!ucontrol->value.integer.value[0];
  2134. if (dc_enable == spec->dc_enable)
  2135. return 0;
  2136. spec->dc_enable = dc_enable;
  2137. if (dc_enable)
  2138. cxt5066_enable_dc(codec);
  2139. else
  2140. cxt5066_disable_dc(codec);
  2141. return 1;
  2142. }
  2143. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2144. struct snd_ctl_elem_info *uinfo)
  2145. {
  2146. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2147. }
  2148. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2149. struct snd_ctl_elem_value *ucontrol)
  2150. {
  2151. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2152. struct conexant_spec *spec = codec->spec;
  2153. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2154. return 0;
  2155. }
  2156. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2157. struct snd_ctl_elem_value *ucontrol)
  2158. {
  2159. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2160. struct conexant_spec *spec = codec->spec;
  2161. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2162. unsigned int idx;
  2163. idx = ucontrol->value.enumerated.item[0];
  2164. if (idx >= imux->num_items)
  2165. idx = imux->num_items - 1;
  2166. spec->dc_input_bias = idx;
  2167. if (spec->dc_enable)
  2168. cxt5066_set_olpc_dc_bias(codec);
  2169. return 1;
  2170. }
  2171. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2172. {
  2173. struct conexant_spec *spec = codec->spec;
  2174. /* mark as recording and configure the microphone widget so that the
  2175. * recording LED comes on. */
  2176. spec->recording = 1;
  2177. cxt5066_olpc_select_mic(codec);
  2178. }
  2179. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2180. {
  2181. struct conexant_spec *spec = codec->spec;
  2182. const struct hda_verb disable_mics[] = {
  2183. /* disable external mic, port B */
  2184. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2185. /* disble internal mic, port C */
  2186. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2187. /* disable DC capture, port F */
  2188. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2189. {},
  2190. };
  2191. snd_hda_sequence_write(codec, disable_mics);
  2192. spec->recording = 0;
  2193. }
  2194. static struct hda_input_mux cxt5066_capture_source = {
  2195. .num_items = 4,
  2196. .items = {
  2197. { "Mic B", 0 },
  2198. { "Mic C", 1 },
  2199. { "Mic E", 2 },
  2200. { "Mic F", 3 },
  2201. },
  2202. };
  2203. static struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2204. .ops = &snd_hda_bind_vol,
  2205. .values = {
  2206. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2207. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2208. 0
  2209. },
  2210. };
  2211. static struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2212. .ops = &snd_hda_bind_sw,
  2213. .values = {
  2214. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2215. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2216. 0
  2217. },
  2218. };
  2219. static struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2220. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2221. {}
  2222. };
  2223. static struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2224. {
  2225. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2226. .name = "Master Playback Volume",
  2227. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2228. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2229. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2230. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2231. .info = snd_hda_mixer_amp_volume_info,
  2232. .get = snd_hda_mixer_amp_volume_get,
  2233. .put = snd_hda_mixer_amp_volume_put,
  2234. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2235. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2236. .private_value =
  2237. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2238. },
  2239. {}
  2240. };
  2241. static struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2242. {
  2243. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2244. .name = "DC Mode Enable Switch",
  2245. .info = snd_ctl_boolean_mono_info,
  2246. .get = cxt5066_olpc_dc_get,
  2247. .put = cxt5066_olpc_dc_put,
  2248. },
  2249. {
  2250. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2251. .name = "DC Input Bias Enum",
  2252. .info = cxt5066_olpc_dc_bias_enum_info,
  2253. .get = cxt5066_olpc_dc_bias_enum_get,
  2254. .put = cxt5066_olpc_dc_bias_enum_put,
  2255. },
  2256. {}
  2257. };
  2258. static struct snd_kcontrol_new cxt5066_mixers[] = {
  2259. {
  2260. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2261. .name = "Master Playback Switch",
  2262. .info = cxt_eapd_info,
  2263. .get = cxt_eapd_get,
  2264. .put = cxt5066_hp_master_sw_put,
  2265. .private_value = 0x1d,
  2266. },
  2267. {
  2268. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2269. .name = "Analog Mic Boost Capture Enum",
  2270. .info = cxt5066_mic_boost_mux_enum_info,
  2271. .get = cxt5066_mic_boost_mux_enum_get,
  2272. .put = cxt5066_mic_boost_mux_enum_put,
  2273. },
  2274. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2275. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2276. {}
  2277. };
  2278. static struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2279. {
  2280. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2281. .name = "Int Mic Boost Capture Enum",
  2282. .info = cxt5066_mic_boost_mux_enum_info,
  2283. .get = cxt5066_mic_boost_mux_enum_get,
  2284. .put = cxt5066_mic_boost_mux_enum_put,
  2285. .private_value = 0x23 | 0x100,
  2286. },
  2287. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
  2288. {}
  2289. };
  2290. static struct hda_verb cxt5066_init_verbs[] = {
  2291. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2292. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2293. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2294. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2295. /* Speakers */
  2296. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2297. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2298. /* HP, Amp */
  2299. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2300. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2301. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2302. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2303. /* DAC1 */
  2304. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2305. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2306. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2307. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2308. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2309. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2310. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2311. /* no digital microphone support yet */
  2312. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2313. /* Audio input selector */
  2314. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2315. /* SPDIF route: PCM */
  2316. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2317. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2318. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2319. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2320. /* EAPD */
  2321. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2322. /* not handling these yet */
  2323. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2324. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2325. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2326. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2327. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2328. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2329. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2330. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2331. { } /* end */
  2332. };
  2333. static struct hda_verb cxt5066_init_verbs_olpc[] = {
  2334. /* Port A: headphones */
  2335. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2336. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2337. /* Port B: external microphone */
  2338. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2339. /* Port C: internal microphone */
  2340. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2341. /* Port D: unused */
  2342. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2343. /* Port E: unused, but has primary EAPD */
  2344. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2345. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2346. /* Port F: external DC input through microphone port */
  2347. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2348. /* Port G: internal speakers */
  2349. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2350. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2351. /* DAC1 */
  2352. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2353. /* DAC2: unused */
  2354. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2355. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2356. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2357. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2358. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2359. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2360. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2361. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2362. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2363. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2364. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2365. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2366. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2367. /* Disable digital microphone port */
  2368. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2369. /* Audio input selectors */
  2370. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2371. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2372. /* Disable SPDIF */
  2373. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2374. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2375. /* enable unsolicited events for Port A and B */
  2376. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2377. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2378. { } /* end */
  2379. };
  2380. static struct hda_verb cxt5066_init_verbs_vostro[] = {
  2381. /* Port A: headphones */
  2382. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2383. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2384. /* Port B: external microphone */
  2385. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2386. /* Port C: unused */
  2387. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2388. /* Port D: unused */
  2389. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2390. /* Port E: unused, but has primary EAPD */
  2391. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2392. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2393. /* Port F: unused */
  2394. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2395. /* Port G: internal speakers */
  2396. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2397. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2398. /* DAC1 */
  2399. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2400. /* DAC2: unused */
  2401. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2402. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2403. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2404. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2405. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2406. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2407. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2408. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2409. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2410. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2411. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2412. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2413. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2414. /* Digital microphone port */
  2415. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2416. /* Audio input selectors */
  2417. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2418. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2419. /* Disable SPDIF */
  2420. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2421. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2422. /* enable unsolicited events for Port A and B */
  2423. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2424. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2425. { } /* end */
  2426. };
  2427. static struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2428. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2429. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2430. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2431. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2432. /* Speakers */
  2433. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2434. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2435. /* HP, Amp */
  2436. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2437. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2438. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2439. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2440. /* DAC1 */
  2441. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2442. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2443. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2444. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2445. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2446. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2447. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2448. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2449. /* Audio input selector */
  2450. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2451. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2452. /* SPDIF route: PCM */
  2453. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2454. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2455. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2456. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2457. /* internal microphone */
  2458. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
  2459. /* EAPD */
  2460. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2461. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2462. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2463. { } /* end */
  2464. };
  2465. static struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2466. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2467. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2468. /* Port G: internal speakers */
  2469. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2470. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2471. /* Port A: HP, Amp */
  2472. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2473. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2474. /* Port B: Mic Dock */
  2475. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2476. /* Port C: Mic */
  2477. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2478. /* Port D: HP Dock, Amp */
  2479. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2480. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2481. /* DAC1 */
  2482. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2483. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2484. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2485. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2486. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2487. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2488. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2489. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2490. /* Audio input selector */
  2491. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2492. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2493. /* SPDIF route: PCM */
  2494. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2495. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2496. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2497. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2498. /* internal microphone */
  2499. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable int mic */
  2500. /* EAPD */
  2501. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2502. /* enable unsolicited events for Port A, B, C and D */
  2503. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2504. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2505. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2506. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2507. { } /* end */
  2508. };
  2509. static struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2510. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2511. { } /* end */
  2512. };
  2513. /* initialize jack-sensing, too */
  2514. static int cxt5066_init(struct hda_codec *codec)
  2515. {
  2516. struct conexant_spec *spec = codec->spec;
  2517. snd_printdd("CXT5066: init\n");
  2518. conexant_init(codec);
  2519. if (codec->patch_ops.unsol_event) {
  2520. cxt5066_hp_automute(codec);
  2521. if (spec->dell_vostro)
  2522. cxt5066_vostro_automic(codec);
  2523. else if (spec->ideapad)
  2524. cxt5066_ideapad_automic(codec);
  2525. else if (spec->thinkpad)
  2526. cxt5066_thinkpad_automic(codec);
  2527. }
  2528. cxt5066_set_mic_boost(codec);
  2529. return 0;
  2530. }
  2531. static int cxt5066_olpc_init(struct hda_codec *codec)
  2532. {
  2533. struct conexant_spec *spec = codec->spec;
  2534. snd_printdd("CXT5066: init\n");
  2535. conexant_init(codec);
  2536. cxt5066_hp_automute(codec);
  2537. if (!spec->dc_enable) {
  2538. cxt5066_set_mic_boost(codec);
  2539. cxt5066_olpc_automic(codec);
  2540. } else {
  2541. cxt5066_enable_dc(codec);
  2542. }
  2543. return 0;
  2544. }
  2545. enum {
  2546. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2547. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2548. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2549. CXT5066_DELL_VOSTO, /* Dell Vostro 1015i */
  2550. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2551. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2552. CXT5066_MODELS
  2553. };
  2554. static const char *cxt5066_models[CXT5066_MODELS] = {
  2555. [CXT5066_LAPTOP] = "laptop",
  2556. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2557. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2558. [CXT5066_DELL_VOSTO] = "dell-vostro",
  2559. [CXT5066_IDEAPAD] = "ideapad",
  2560. [CXT5066_THINKPAD] = "thinkpad",
  2561. };
  2562. static struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2563. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2564. CXT5066_LAPTOP),
  2565. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell",
  2566. CXT5066_DELL_LAPTOP),
  2567. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2568. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTO),
  2569. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2570. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2571. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2572. SND_PCI_QUIRK(0x17aa, 0x3a0d, "ideapad", CXT5066_IDEAPAD),
  2573. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2574. {}
  2575. };
  2576. static int patch_cxt5066(struct hda_codec *codec)
  2577. {
  2578. struct conexant_spec *spec;
  2579. int board_config;
  2580. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2581. if (!spec)
  2582. return -ENOMEM;
  2583. codec->spec = spec;
  2584. codec->patch_ops = conexant_patch_ops;
  2585. codec->patch_ops.init = conexant_init;
  2586. spec->dell_automute = 0;
  2587. spec->multiout.max_channels = 2;
  2588. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2589. spec->multiout.dac_nids = cxt5066_dac_nids;
  2590. spec->multiout.dig_out_nid = CXT5066_SPDIF_OUT;
  2591. spec->num_adc_nids = 1;
  2592. spec->adc_nids = cxt5066_adc_nids;
  2593. spec->capsrc_nids = cxt5066_capsrc_nids;
  2594. spec->input_mux = &cxt5066_capture_source;
  2595. spec->port_d_mode = PIN_HP;
  2596. spec->num_init_verbs = 1;
  2597. spec->init_verbs[0] = cxt5066_init_verbs;
  2598. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2599. spec->channel_mode = cxt5066_modes;
  2600. spec->cur_adc = 0;
  2601. spec->cur_adc_idx = 0;
  2602. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2603. cxt5066_models, cxt5066_cfg_tbl);
  2604. switch (board_config) {
  2605. default:
  2606. case CXT5066_LAPTOP:
  2607. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2608. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2609. break;
  2610. case CXT5066_DELL_LAPTOP:
  2611. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2612. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2613. spec->port_d_mode = PIN_OUT;
  2614. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2615. spec->num_init_verbs++;
  2616. spec->dell_automute = 1;
  2617. break;
  2618. case CXT5066_OLPC_XO_1_5:
  2619. codec->patch_ops.init = cxt5066_olpc_init;
  2620. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2621. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2622. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2623. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2624. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2625. spec->port_d_mode = 0;
  2626. spec->mic_boost = 3; /* default 30dB gain */
  2627. /* no S/PDIF out */
  2628. spec->multiout.dig_out_nid = 0;
  2629. /* input source automatically selected */
  2630. spec->input_mux = NULL;
  2631. /* our capture hooks which allow us to turn on the microphone LED
  2632. * at the right time */
  2633. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2634. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2635. break;
  2636. case CXT5066_DELL_VOSTO:
  2637. codec->patch_ops.init = cxt5066_init;
  2638. codec->patch_ops.unsol_event = cxt5066_vostro_event;
  2639. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2640. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2641. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2642. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2643. spec->port_d_mode = 0;
  2644. spec->dell_vostro = 1;
  2645. spec->mic_boost = 3; /* default 30dB gain */
  2646. snd_hda_attach_beep_device(codec, 0x13);
  2647. /* no S/PDIF out */
  2648. spec->multiout.dig_out_nid = 0;
  2649. /* input source automatically selected */
  2650. spec->input_mux = NULL;
  2651. break;
  2652. case CXT5066_IDEAPAD:
  2653. codec->patch_ops.init = cxt5066_init;
  2654. codec->patch_ops.unsol_event = cxt5066_ideapad_event;
  2655. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2656. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2657. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2658. spec->port_d_mode = 0;
  2659. spec->ideapad = 1;
  2660. spec->mic_boost = 2; /* default 20dB gain */
  2661. /* no S/PDIF out */
  2662. spec->multiout.dig_out_nid = 0;
  2663. /* input source automatically selected */
  2664. spec->input_mux = NULL;
  2665. break;
  2666. case CXT5066_THINKPAD:
  2667. codec->patch_ops.init = cxt5066_init;
  2668. codec->patch_ops.unsol_event = cxt5066_thinkpad_event;
  2669. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2670. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2671. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2672. spec->thinkpad = 1;
  2673. spec->port_d_mode = PIN_OUT;
  2674. spec->mic_boost = 2; /* default 20dB gain */
  2675. /* no S/PDIF out */
  2676. spec->multiout.dig_out_nid = 0;
  2677. /* input source automatically selected */
  2678. spec->input_mux = NULL;
  2679. break;
  2680. }
  2681. return 0;
  2682. }
  2683. /*
  2684. */
  2685. static struct hda_codec_preset snd_hda_preset_conexant[] = {
  2686. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  2687. .patch = patch_cxt5045 },
  2688. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  2689. .patch = patch_cxt5047 },
  2690. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  2691. .patch = patch_cxt5051 },
  2692. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  2693. .patch = patch_cxt5066 },
  2694. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  2695. .patch = patch_cxt5066 },
  2696. { .id = 0x14f15069, .name = "CX20585",
  2697. .patch = patch_cxt5066 },
  2698. {} /* terminator */
  2699. };
  2700. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  2701. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  2702. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  2703. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  2704. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  2705. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  2706. MODULE_LICENSE("GPL");
  2707. MODULE_DESCRIPTION("Conexant HD-audio codec");
  2708. static struct hda_codec_preset_list conexant_list = {
  2709. .preset = snd_hda_preset_conexant,
  2710. .owner = THIS_MODULE,
  2711. };
  2712. static int __init patch_conexant_init(void)
  2713. {
  2714. return snd_hda_add_codec_preset(&conexant_list);
  2715. }
  2716. static void __exit patch_conexant_exit(void)
  2717. {
  2718. snd_hda_delete_codec_preset(&conexant_list);
  2719. }
  2720. module_init(patch_conexant_init)
  2721. module_exit(patch_conexant_exit)