patch_conexant.c 126 KB

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