patch_conexant.c 133 KB

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