patch_conexant.c 124 KB

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