patch_conexant.c 133 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495
  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_lenovo_x200_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_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1648. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1649. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1650. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1651. /* SPK */
  1652. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1653. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1654. /* HP, Amp */
  1655. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1656. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1657. /* Docking HP */
  1658. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1659. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1660. /* DAC1 */
  1661. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1662. /* Record selector: Internal mic */
  1663. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1664. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1665. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1666. /* SPDIF route: PCM */
  1667. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
  1668. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1669. /* EAPD */
  1670. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1671. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1672. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1673. { } /* end */
  1674. };
  1675. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1676. /* Line in, Mic */
  1677. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1678. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1679. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1680. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1681. /* SPK */
  1682. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1683. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1684. /* HP, Amp */
  1685. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1686. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1687. /* DAC1 */
  1688. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1689. /* Record selector: Internal mic */
  1690. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1691. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1692. /* SPDIF route: PCM */
  1693. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1694. /* EAPD */
  1695. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1696. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1697. { } /* end */
  1698. };
  1699. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1700. unsigned int event)
  1701. {
  1702. snd_hda_codec_write(codec, nid, 0,
  1703. AC_VERB_SET_UNSOLICITED_ENABLE,
  1704. AC_USRSP_EN | event);
  1705. snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
  1706. snd_hda_input_jack_report(codec, nid);
  1707. }
  1708. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1709. /* Subwoofer */
  1710. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1711. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1712. { } /* end */
  1713. };
  1714. /* initialize jack-sensing, too */
  1715. static int cxt5051_init(struct hda_codec *codec)
  1716. {
  1717. struct conexant_spec *spec = codec->spec;
  1718. conexant_init(codec);
  1719. conexant_init_jacks(codec);
  1720. if (spec->auto_mic & AUTO_MIC_PORTB)
  1721. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1722. if (spec->auto_mic & AUTO_MIC_PORTC)
  1723. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1724. if (codec->patch_ops.unsol_event) {
  1725. cxt5051_hp_automute(codec);
  1726. cxt5051_portb_automic(codec);
  1727. cxt5051_portc_automic(codec);
  1728. }
  1729. return 0;
  1730. }
  1731. enum {
  1732. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1733. CXT5051_HP, /* no docking */
  1734. CXT5051_HP_DV6736, /* HP without mic switch */
  1735. CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
  1736. CXT5051_F700, /* HP Compaq Presario F700 */
  1737. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1738. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1739. CXT5051_AUTO, /* auto-parser */
  1740. CXT5051_MODELS
  1741. };
  1742. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1743. [CXT5051_LAPTOP] = "laptop",
  1744. [CXT5051_HP] = "hp",
  1745. [CXT5051_HP_DV6736] = "hp-dv6736",
  1746. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1747. [CXT5051_F700] = "hp-700",
  1748. [CXT5051_TOSHIBA] = "toshiba",
  1749. [CXT5051_IDEAPAD] = "ideapad",
  1750. [CXT5051_AUTO] = "auto",
  1751. };
  1752. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1753. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1754. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1755. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1756. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1757. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1758. CXT5051_LAPTOP),
  1759. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1760. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1761. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1762. {}
  1763. };
  1764. static int patch_cxt5051(struct hda_codec *codec)
  1765. {
  1766. struct conexant_spec *spec;
  1767. int board_config;
  1768. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1769. cxt5051_models,
  1770. cxt5051_cfg_tbl);
  1771. if (board_config < 0)
  1772. board_config = CXT5051_AUTO; /* model=auto as default */
  1773. if (board_config == CXT5051_AUTO)
  1774. return patch_conexant_auto(codec);
  1775. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1776. if (!spec)
  1777. return -ENOMEM;
  1778. codec->spec = spec;
  1779. codec->pin_amp_workaround = 1;
  1780. codec->patch_ops = conexant_patch_ops;
  1781. codec->patch_ops.init = cxt5051_init;
  1782. spec->multiout.max_channels = 2;
  1783. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1784. spec->multiout.dac_nids = cxt5051_dac_nids;
  1785. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1786. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1787. spec->adc_nids = cxt5051_adc_nids;
  1788. spec->num_mixers = 2;
  1789. spec->mixers[0] = cxt5051_capture_mixers;
  1790. spec->mixers[1] = cxt5051_playback_mixers;
  1791. spec->num_init_verbs = 1;
  1792. spec->init_verbs[0] = cxt5051_init_verbs;
  1793. spec->spdif_route = 0;
  1794. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1795. spec->channel_mode = cxt5051_modes;
  1796. spec->cur_adc = 0;
  1797. spec->cur_adc_idx = 0;
  1798. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1799. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1800. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1801. switch (board_config) {
  1802. case CXT5051_HP:
  1803. spec->mixers[0] = cxt5051_hp_mixers;
  1804. break;
  1805. case CXT5051_HP_DV6736:
  1806. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1807. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1808. spec->auto_mic = 0;
  1809. break;
  1810. case CXT5051_LENOVO_X200:
  1811. spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
  1812. /* Thinkpad X301 does not have S/PDIF wired and no ability
  1813. to use a docking station. */
  1814. if (codec->subsystem_id == 0x17aa211f)
  1815. spec->multiout.dig_out_nid = 0;
  1816. break;
  1817. case CXT5051_F700:
  1818. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1819. spec->mixers[0] = cxt5051_f700_mixers;
  1820. spec->auto_mic = 0;
  1821. break;
  1822. case CXT5051_TOSHIBA:
  1823. spec->mixers[0] = cxt5051_toshiba_mixers;
  1824. spec->auto_mic = AUTO_MIC_PORTB;
  1825. break;
  1826. case CXT5051_IDEAPAD:
  1827. spec->init_verbs[spec->num_init_verbs++] =
  1828. cxt5051_ideapad_init_verbs;
  1829. spec->ideapad = 1;
  1830. break;
  1831. }
  1832. if (spec->beep_amp)
  1833. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1834. return 0;
  1835. }
  1836. /* Conexant 5066 specific */
  1837. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1838. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1839. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1840. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1841. /* OLPC's microphone port is DC coupled for use with external sensors,
  1842. * therefore we use a 50% mic bias in order to center the input signal with
  1843. * the DC input range of the codec. */
  1844. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1845. static const struct hda_channel_mode cxt5066_modes[1] = {
  1846. { 2, NULL },
  1847. };
  1848. #define HP_PRESENT_PORT_A (1 << 0)
  1849. #define HP_PRESENT_PORT_D (1 << 1)
  1850. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1851. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1852. static void cxt5066_update_speaker(struct hda_codec *codec)
  1853. {
  1854. struct conexant_spec *spec = codec->spec;
  1855. unsigned int pinctl;
  1856. snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1857. spec->hp_present, spec->cur_eapd);
  1858. /* Port A (HP) */
  1859. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1860. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1861. pinctl);
  1862. /* Port D (HP/LO) */
  1863. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1864. if (spec->dell_automute || spec->thinkpad) {
  1865. /* Mute if Port A is connected */
  1866. if (hp_port_a_present(spec))
  1867. pinctl = 0;
  1868. } else {
  1869. /* Thinkpad/Dell doesn't give pin-D status */
  1870. if (!hp_port_d_present(spec))
  1871. pinctl = 0;
  1872. }
  1873. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1874. pinctl);
  1875. /* CLASS_D AMP */
  1876. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1877. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1878. pinctl);
  1879. }
  1880. /* turn on/off EAPD (+ mute HP) as a master switch */
  1881. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1882. struct snd_ctl_elem_value *ucontrol)
  1883. {
  1884. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1885. if (!cxt_eapd_put(kcontrol, ucontrol))
  1886. return 0;
  1887. cxt5066_update_speaker(codec);
  1888. return 1;
  1889. }
  1890. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1891. .num_items = 3,
  1892. .items = {
  1893. { "Off", PIN_IN },
  1894. { "50%", PIN_VREF50 },
  1895. { "80%", PIN_VREF80 },
  1896. },
  1897. };
  1898. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1899. {
  1900. struct conexant_spec *spec = codec->spec;
  1901. /* Even though port F is the DC input, the bias is controlled on port B.
  1902. * we also leave that port as an active input (but unselected) in DC mode
  1903. * just in case that is necessary to make the bias setting take effect. */
  1904. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1905. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1906. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1907. }
  1908. /* OLPC defers mic widget control until when capture is started because the
  1909. * microphone LED comes on as soon as these settings are put in place. if we
  1910. * did this before recording, it would give the false indication that recording
  1911. * is happening when it is not. */
  1912. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1913. {
  1914. struct conexant_spec *spec = codec->spec;
  1915. if (!spec->recording)
  1916. return;
  1917. if (spec->dc_enable) {
  1918. /* in DC mode we ignore presence detection and just use the jack
  1919. * through our special DC port */
  1920. const struct hda_verb enable_dc_mode[] = {
  1921. /* disble internal mic, port C */
  1922. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1923. /* enable DC capture, port F */
  1924. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1925. {},
  1926. };
  1927. snd_hda_sequence_write(codec, enable_dc_mode);
  1928. /* port B input disabled (and bias set) through the following call */
  1929. cxt5066_set_olpc_dc_bias(codec);
  1930. return;
  1931. }
  1932. /* disable DC (port F) */
  1933. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1934. /* external mic, port B */
  1935. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1936. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1937. /* internal mic, port C */
  1938. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1939. spec->ext_mic_present ? 0 : PIN_VREF80);
  1940. }
  1941. /* toggle input of built-in and mic jack appropriately */
  1942. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1943. {
  1944. struct conexant_spec *spec = codec->spec;
  1945. unsigned int present;
  1946. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1947. return;
  1948. present = snd_hda_codec_read(codec, 0x1a, 0,
  1949. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1950. if (present)
  1951. snd_printdd("CXT5066: external microphone detected\n");
  1952. else
  1953. snd_printdd("CXT5066: external microphone absent\n");
  1954. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1955. present ? 0 : 1);
  1956. spec->ext_mic_present = !!present;
  1957. cxt5066_olpc_select_mic(codec);
  1958. }
  1959. /* toggle input of built-in digital mic and mic jack appropriately */
  1960. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1961. {
  1962. unsigned int present;
  1963. struct hda_verb ext_mic_present[] = {
  1964. /* enable external mic, port B */
  1965. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1966. /* switch to external mic input */
  1967. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1968. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1969. /* disable internal digital mic */
  1970. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1971. {}
  1972. };
  1973. static const struct hda_verb ext_mic_absent[] = {
  1974. /* enable internal mic, port C */
  1975. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1976. /* switch to internal mic input */
  1977. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1978. /* disable external mic, port B */
  1979. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1980. {}
  1981. };
  1982. present = snd_hda_jack_detect(codec, 0x1a);
  1983. if (present) {
  1984. snd_printdd("CXT5066: external microphone detected\n");
  1985. snd_hda_sequence_write(codec, ext_mic_present);
  1986. } else {
  1987. snd_printdd("CXT5066: external microphone absent\n");
  1988. snd_hda_sequence_write(codec, ext_mic_absent);
  1989. }
  1990. }
  1991. /* toggle input of built-in digital mic and mic jack appropriately */
  1992. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1993. {
  1994. unsigned int present;
  1995. struct hda_verb ext_mic_present[] = {
  1996. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1997. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1998. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1999. {}
  2000. };
  2001. static const struct hda_verb ext_mic_absent[] = {
  2002. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  2003. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2004. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2005. {}
  2006. };
  2007. present = snd_hda_jack_detect(codec, 0x1b);
  2008. if (present) {
  2009. snd_printdd("CXT5066: external microphone detected\n");
  2010. snd_hda_sequence_write(codec, ext_mic_present);
  2011. } else {
  2012. snd_printdd("CXT5066: external microphone absent\n");
  2013. snd_hda_sequence_write(codec, ext_mic_absent);
  2014. }
  2015. }
  2016. /* toggle input of built-in digital mic and mic jack appropriately */
  2017. static void cxt5066_asus_automic(struct hda_codec *codec)
  2018. {
  2019. unsigned int present;
  2020. present = snd_hda_jack_detect(codec, 0x1b);
  2021. snd_printdd("CXT5066: external microphone present=%d\n", present);
  2022. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  2023. present ? 1 : 0);
  2024. }
  2025. /* toggle input of built-in digital mic and mic jack appropriately */
  2026. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  2027. {
  2028. unsigned int present;
  2029. present = snd_hda_jack_detect(codec, 0x1b);
  2030. snd_printdd("CXT5066: external microphone present=%d\n", present);
  2031. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  2032. present ? 1 : 3);
  2033. }
  2034. /* toggle input of built-in digital mic and mic jack appropriately
  2035. order is: external mic -> dock mic -> interal mic */
  2036. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  2037. {
  2038. unsigned int ext_present, dock_present;
  2039. static const struct hda_verb ext_mic_present[] = {
  2040. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2041. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  2042. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2043. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2044. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2045. {}
  2046. };
  2047. static const struct hda_verb dock_mic_present[] = {
  2048. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2049. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  2050. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2051. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2052. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2053. {}
  2054. };
  2055. static const struct hda_verb ext_mic_absent[] = {
  2056. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  2057. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2058. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2059. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2060. {}
  2061. };
  2062. ext_present = snd_hda_jack_detect(codec, 0x1b);
  2063. dock_present = snd_hda_jack_detect(codec, 0x1a);
  2064. if (ext_present) {
  2065. snd_printdd("CXT5066: external microphone detected\n");
  2066. snd_hda_sequence_write(codec, ext_mic_present);
  2067. } else if (dock_present) {
  2068. snd_printdd("CXT5066: dock microphone detected\n");
  2069. snd_hda_sequence_write(codec, dock_mic_present);
  2070. } else {
  2071. snd_printdd("CXT5066: external microphone absent\n");
  2072. snd_hda_sequence_write(codec, ext_mic_absent);
  2073. }
  2074. }
  2075. /* mute internal speaker if HP is plugged */
  2076. static void cxt5066_hp_automute(struct hda_codec *codec)
  2077. {
  2078. struct conexant_spec *spec = codec->spec;
  2079. unsigned int portA, portD;
  2080. /* Port A */
  2081. portA = snd_hda_jack_detect(codec, 0x19);
  2082. /* Port D */
  2083. portD = snd_hda_jack_detect(codec, 0x1c);
  2084. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  2085. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  2086. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  2087. portA, portD, spec->hp_present);
  2088. cxt5066_update_speaker(codec);
  2089. }
  2090. /* Dispatch the right mic autoswitch function */
  2091. static void cxt5066_automic(struct hda_codec *codec)
  2092. {
  2093. struct conexant_spec *spec = codec->spec;
  2094. if (spec->dell_vostro)
  2095. cxt5066_vostro_automic(codec);
  2096. else if (spec->ideapad)
  2097. cxt5066_ideapad_automic(codec);
  2098. else if (spec->thinkpad)
  2099. cxt5066_thinkpad_automic(codec);
  2100. else if (spec->hp_laptop)
  2101. cxt5066_hp_laptop_automic(codec);
  2102. else if (spec->asus)
  2103. cxt5066_asus_automic(codec);
  2104. }
  2105. /* unsolicited event for jack sensing */
  2106. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  2107. {
  2108. struct conexant_spec *spec = codec->spec;
  2109. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2110. switch (res >> 26) {
  2111. case CONEXANT_HP_EVENT:
  2112. cxt5066_hp_automute(codec);
  2113. break;
  2114. case CONEXANT_MIC_EVENT:
  2115. /* ignore mic events in DC mode; we're always using the jack */
  2116. if (!spec->dc_enable)
  2117. cxt5066_olpc_automic(codec);
  2118. break;
  2119. }
  2120. }
  2121. /* unsolicited event for jack sensing */
  2122. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  2123. {
  2124. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2125. switch (res >> 26) {
  2126. case CONEXANT_HP_EVENT:
  2127. cxt5066_hp_automute(codec);
  2128. break;
  2129. case CONEXANT_MIC_EVENT:
  2130. cxt5066_automic(codec);
  2131. break;
  2132. }
  2133. }
  2134. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2135. .num_items = 5,
  2136. .items = {
  2137. { "0dB", 0 },
  2138. { "10dB", 1 },
  2139. { "20dB", 2 },
  2140. { "30dB", 3 },
  2141. { "40dB", 4 },
  2142. },
  2143. };
  2144. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2145. {
  2146. struct conexant_spec *spec = codec->spec;
  2147. snd_hda_codec_write_cache(codec, 0x17, 0,
  2148. AC_VERB_SET_AMP_GAIN_MUTE,
  2149. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2150. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2151. if (spec->ideapad || spec->thinkpad) {
  2152. /* adjust the internal mic as well...it is not through 0x17 */
  2153. snd_hda_codec_write_cache(codec, 0x23, 0,
  2154. AC_VERB_SET_AMP_GAIN_MUTE,
  2155. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2156. cxt5066_analog_mic_boost.
  2157. items[spec->mic_boost].index);
  2158. }
  2159. }
  2160. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2161. struct snd_ctl_elem_info *uinfo)
  2162. {
  2163. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2164. }
  2165. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2166. struct snd_ctl_elem_value *ucontrol)
  2167. {
  2168. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2169. struct conexant_spec *spec = codec->spec;
  2170. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2171. return 0;
  2172. }
  2173. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2174. struct snd_ctl_elem_value *ucontrol)
  2175. {
  2176. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2177. struct conexant_spec *spec = codec->spec;
  2178. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2179. unsigned int idx;
  2180. idx = ucontrol->value.enumerated.item[0];
  2181. if (idx >= imux->num_items)
  2182. idx = imux->num_items - 1;
  2183. spec->mic_boost = idx;
  2184. if (!spec->dc_enable)
  2185. cxt5066_set_mic_boost(codec);
  2186. return 1;
  2187. }
  2188. static void cxt5066_enable_dc(struct hda_codec *codec)
  2189. {
  2190. const struct hda_verb enable_dc_mode[] = {
  2191. /* disable gain */
  2192. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2193. /* switch to DC input */
  2194. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2195. {}
  2196. };
  2197. /* configure as input source */
  2198. snd_hda_sequence_write(codec, enable_dc_mode);
  2199. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2200. }
  2201. static void cxt5066_disable_dc(struct hda_codec *codec)
  2202. {
  2203. /* reconfigure input source */
  2204. cxt5066_set_mic_boost(codec);
  2205. /* automic also selects the right mic if we're recording */
  2206. cxt5066_olpc_automic(codec);
  2207. }
  2208. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2209. struct snd_ctl_elem_value *ucontrol)
  2210. {
  2211. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2212. struct conexant_spec *spec = codec->spec;
  2213. ucontrol->value.integer.value[0] = spec->dc_enable;
  2214. return 0;
  2215. }
  2216. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2217. struct snd_ctl_elem_value *ucontrol)
  2218. {
  2219. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2220. struct conexant_spec *spec = codec->spec;
  2221. int dc_enable = !!ucontrol->value.integer.value[0];
  2222. if (dc_enable == spec->dc_enable)
  2223. return 0;
  2224. spec->dc_enable = dc_enable;
  2225. if (dc_enable)
  2226. cxt5066_enable_dc(codec);
  2227. else
  2228. cxt5066_disable_dc(codec);
  2229. return 1;
  2230. }
  2231. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2232. struct snd_ctl_elem_info *uinfo)
  2233. {
  2234. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2235. }
  2236. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2237. struct snd_ctl_elem_value *ucontrol)
  2238. {
  2239. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2240. struct conexant_spec *spec = codec->spec;
  2241. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2242. return 0;
  2243. }
  2244. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2245. struct snd_ctl_elem_value *ucontrol)
  2246. {
  2247. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2248. struct conexant_spec *spec = codec->spec;
  2249. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2250. unsigned int idx;
  2251. idx = ucontrol->value.enumerated.item[0];
  2252. if (idx >= imux->num_items)
  2253. idx = imux->num_items - 1;
  2254. spec->dc_input_bias = idx;
  2255. if (spec->dc_enable)
  2256. cxt5066_set_olpc_dc_bias(codec);
  2257. return 1;
  2258. }
  2259. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2260. {
  2261. struct conexant_spec *spec = codec->spec;
  2262. /* mark as recording and configure the microphone widget so that the
  2263. * recording LED comes on. */
  2264. spec->recording = 1;
  2265. cxt5066_olpc_select_mic(codec);
  2266. }
  2267. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2268. {
  2269. struct conexant_spec *spec = codec->spec;
  2270. const struct hda_verb disable_mics[] = {
  2271. /* disable external mic, port B */
  2272. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2273. /* disble internal mic, port C */
  2274. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2275. /* disable DC capture, port F */
  2276. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2277. {},
  2278. };
  2279. snd_hda_sequence_write(codec, disable_mics);
  2280. spec->recording = 0;
  2281. }
  2282. static void conexant_check_dig_outs(struct hda_codec *codec,
  2283. const hda_nid_t *dig_pins,
  2284. int num_pins)
  2285. {
  2286. struct conexant_spec *spec = codec->spec;
  2287. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  2288. int i;
  2289. for (i = 0; i < num_pins; i++, dig_pins++) {
  2290. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  2291. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  2292. continue;
  2293. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  2294. continue;
  2295. if (spec->slave_dig_outs[0])
  2296. nid_loc++;
  2297. else
  2298. nid_loc = spec->slave_dig_outs;
  2299. }
  2300. }
  2301. static const struct hda_input_mux cxt5066_capture_source = {
  2302. .num_items = 4,
  2303. .items = {
  2304. { "Mic B", 0 },
  2305. { "Mic C", 1 },
  2306. { "Mic E", 2 },
  2307. { "Mic F", 3 },
  2308. },
  2309. };
  2310. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2311. .ops = &snd_hda_bind_vol,
  2312. .values = {
  2313. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2314. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2315. 0
  2316. },
  2317. };
  2318. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2319. .ops = &snd_hda_bind_sw,
  2320. .values = {
  2321. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2322. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2323. 0
  2324. },
  2325. };
  2326. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2327. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2328. {}
  2329. };
  2330. static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2331. {
  2332. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2333. .name = "Master Playback Volume",
  2334. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2335. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2336. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2337. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2338. .info = snd_hda_mixer_amp_volume_info,
  2339. .get = snd_hda_mixer_amp_volume_get,
  2340. .put = snd_hda_mixer_amp_volume_put,
  2341. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2342. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2343. .private_value =
  2344. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2345. },
  2346. {}
  2347. };
  2348. static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2349. {
  2350. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2351. .name = "DC Mode Enable Switch",
  2352. .info = snd_ctl_boolean_mono_info,
  2353. .get = cxt5066_olpc_dc_get,
  2354. .put = cxt5066_olpc_dc_put,
  2355. },
  2356. {
  2357. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2358. .name = "DC Input Bias Enum",
  2359. .info = cxt5066_olpc_dc_bias_enum_info,
  2360. .get = cxt5066_olpc_dc_bias_enum_get,
  2361. .put = cxt5066_olpc_dc_bias_enum_put,
  2362. },
  2363. {}
  2364. };
  2365. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  2366. {
  2367. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2368. .name = "Master Playback Switch",
  2369. .info = cxt_eapd_info,
  2370. .get = cxt_eapd_get,
  2371. .put = cxt5066_hp_master_sw_put,
  2372. .private_value = 0x1d,
  2373. },
  2374. {
  2375. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2376. .name = "Analog Mic Boost Capture Enum",
  2377. .info = cxt5066_mic_boost_mux_enum_info,
  2378. .get = cxt5066_mic_boost_mux_enum_get,
  2379. .put = cxt5066_mic_boost_mux_enum_put,
  2380. },
  2381. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2382. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2383. {}
  2384. };
  2385. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2386. {
  2387. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2388. .name = "Internal Mic Boost Capture Enum",
  2389. .info = cxt5066_mic_boost_mux_enum_info,
  2390. .get = cxt5066_mic_boost_mux_enum_get,
  2391. .put = cxt5066_mic_boost_mux_enum_put,
  2392. .private_value = 0x23 | 0x100,
  2393. },
  2394. {}
  2395. };
  2396. static const struct hda_verb cxt5066_init_verbs[] = {
  2397. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2398. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2399. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2400. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2401. /* Speakers */
  2402. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2403. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2404. /* HP, Amp */
  2405. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2406. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2407. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2408. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2409. /* DAC1 */
  2410. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2411. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2412. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2413. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2414. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2415. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2416. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2417. /* no digital microphone support yet */
  2418. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2419. /* Audio input selector */
  2420. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2421. /* SPDIF route: PCM */
  2422. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2423. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2424. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2425. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2426. /* EAPD */
  2427. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2428. /* not handling these yet */
  2429. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2430. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2431. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2432. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2433. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2434. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2435. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2436. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2437. { } /* end */
  2438. };
  2439. static const struct hda_verb cxt5066_init_verbs_olpc[] = {
  2440. /* Port A: headphones */
  2441. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2442. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2443. /* Port B: external microphone */
  2444. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2445. /* Port C: internal microphone */
  2446. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2447. /* Port D: unused */
  2448. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2449. /* Port E: unused, but has primary EAPD */
  2450. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2451. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2452. /* Port F: external DC input through microphone port */
  2453. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2454. /* Port G: internal speakers */
  2455. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2456. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2457. /* DAC1 */
  2458. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2459. /* DAC2: unused */
  2460. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2461. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2462. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2463. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2464. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2465. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2466. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2467. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2468. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2469. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2470. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2471. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2472. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2473. /* Disable digital microphone port */
  2474. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2475. /* Audio input selectors */
  2476. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2477. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2478. /* Disable SPDIF */
  2479. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2480. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2481. /* enable unsolicited events for Port A and B */
  2482. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2483. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2484. { } /* end */
  2485. };
  2486. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2487. /* Port A: headphones */
  2488. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2489. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2490. /* Port B: external microphone */
  2491. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2492. /* Port C: unused */
  2493. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2494. /* Port D: unused */
  2495. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2496. /* Port E: unused, but has primary EAPD */
  2497. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2498. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2499. /* Port F: unused */
  2500. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2501. /* Port G: internal speakers */
  2502. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2503. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2504. /* DAC1 */
  2505. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2506. /* DAC2: unused */
  2507. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2508. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2509. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2510. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2511. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2512. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2513. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2514. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2515. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2516. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2517. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2518. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2519. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2520. /* Digital microphone port */
  2521. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2522. /* Audio input selectors */
  2523. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2524. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2525. /* Disable SPDIF */
  2526. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2527. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2528. /* enable unsolicited events for Port A and B */
  2529. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2530. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2531. { } /* end */
  2532. };
  2533. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2534. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2535. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2536. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2537. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2538. /* Speakers */
  2539. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2540. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2541. /* HP, Amp */
  2542. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2543. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2544. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2545. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2546. /* DAC1 */
  2547. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2548. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2549. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2550. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2551. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2552. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2553. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2554. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2555. /* Audio input selector */
  2556. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2557. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2558. /* SPDIF route: PCM */
  2559. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2560. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2561. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2562. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2563. /* internal microphone */
  2564. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2565. /* EAPD */
  2566. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2567. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2568. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2569. { } /* end */
  2570. };
  2571. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2572. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2573. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2574. /* Port G: internal speakers */
  2575. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2576. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2577. /* Port A: HP, Amp */
  2578. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2579. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2580. /* Port B: Mic Dock */
  2581. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2582. /* Port C: Mic */
  2583. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2584. /* Port D: HP Dock, Amp */
  2585. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2586. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2587. /* DAC1 */
  2588. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2589. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2590. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2591. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2592. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2593. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2594. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2595. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2596. /* Audio input selector */
  2597. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2598. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2599. /* SPDIF route: PCM */
  2600. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2601. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2602. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2603. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2604. /* internal microphone */
  2605. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2606. /* EAPD */
  2607. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2608. /* enable unsolicited events for Port A, B, C and D */
  2609. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2610. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2611. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2612. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2613. { } /* end */
  2614. };
  2615. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2616. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2617. { } /* end */
  2618. };
  2619. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2620. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2621. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2622. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2623. { } /* end */
  2624. };
  2625. /* initialize jack-sensing, too */
  2626. static int cxt5066_init(struct hda_codec *codec)
  2627. {
  2628. snd_printdd("CXT5066: init\n");
  2629. conexant_init(codec);
  2630. if (codec->patch_ops.unsol_event) {
  2631. cxt5066_hp_automute(codec);
  2632. cxt5066_automic(codec);
  2633. }
  2634. cxt5066_set_mic_boost(codec);
  2635. return 0;
  2636. }
  2637. static int cxt5066_olpc_init(struct hda_codec *codec)
  2638. {
  2639. struct conexant_spec *spec = codec->spec;
  2640. snd_printdd("CXT5066: init\n");
  2641. conexant_init(codec);
  2642. cxt5066_hp_automute(codec);
  2643. if (!spec->dc_enable) {
  2644. cxt5066_set_mic_boost(codec);
  2645. cxt5066_olpc_automic(codec);
  2646. } else {
  2647. cxt5066_enable_dc(codec);
  2648. }
  2649. return 0;
  2650. }
  2651. enum {
  2652. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2653. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2654. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2655. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2656. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2657. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2658. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2659. CXT5066_HP_LAPTOP, /* HP Laptop */
  2660. CXT5066_AUTO, /* BIOS auto-parser */
  2661. CXT5066_MODELS
  2662. };
  2663. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2664. [CXT5066_LAPTOP] = "laptop",
  2665. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2666. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2667. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2668. [CXT5066_IDEAPAD] = "ideapad",
  2669. [CXT5066_THINKPAD] = "thinkpad",
  2670. [CXT5066_ASUS] = "asus",
  2671. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2672. [CXT5066_AUTO] = "auto",
  2673. };
  2674. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2675. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
  2676. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2677. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2678. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2679. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2680. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2681. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2682. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2683. SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
  2684. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2685. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2686. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2687. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2688. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2689. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2690. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2691. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2692. CXT5066_LAPTOP),
  2693. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2694. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2695. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2696. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2697. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2698. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
  2699. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
  2700. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
  2701. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2702. SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
  2703. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
  2704. SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
  2705. {}
  2706. };
  2707. static int patch_cxt5066(struct hda_codec *codec)
  2708. {
  2709. struct conexant_spec *spec;
  2710. int board_config;
  2711. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2712. cxt5066_models, cxt5066_cfg_tbl);
  2713. if (board_config < 0)
  2714. board_config = CXT5066_AUTO; /* model=auto as default */
  2715. if (board_config == CXT5066_AUTO)
  2716. return patch_conexant_auto(codec);
  2717. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2718. if (!spec)
  2719. return -ENOMEM;
  2720. codec->spec = spec;
  2721. codec->patch_ops = conexant_patch_ops;
  2722. codec->patch_ops.init = conexant_init;
  2723. spec->dell_automute = 0;
  2724. spec->multiout.max_channels = 2;
  2725. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2726. spec->multiout.dac_nids = cxt5066_dac_nids;
  2727. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2728. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2729. spec->num_adc_nids = 1;
  2730. spec->adc_nids = cxt5066_adc_nids;
  2731. spec->capsrc_nids = cxt5066_capsrc_nids;
  2732. spec->input_mux = &cxt5066_capture_source;
  2733. spec->port_d_mode = PIN_HP;
  2734. spec->num_init_verbs = 1;
  2735. spec->init_verbs[0] = cxt5066_init_verbs;
  2736. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2737. spec->channel_mode = cxt5066_modes;
  2738. spec->cur_adc = 0;
  2739. spec->cur_adc_idx = 0;
  2740. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2741. switch (board_config) {
  2742. default:
  2743. case CXT5066_LAPTOP:
  2744. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2745. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2746. break;
  2747. case CXT5066_DELL_LAPTOP:
  2748. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2749. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2750. spec->port_d_mode = PIN_OUT;
  2751. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2752. spec->num_init_verbs++;
  2753. spec->dell_automute = 1;
  2754. break;
  2755. case CXT5066_ASUS:
  2756. case CXT5066_HP_LAPTOP:
  2757. codec->patch_ops.init = cxt5066_init;
  2758. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2759. spec->init_verbs[spec->num_init_verbs] =
  2760. cxt5066_init_verbs_hp_laptop;
  2761. spec->num_init_verbs++;
  2762. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2763. spec->asus = board_config == CXT5066_ASUS;
  2764. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2765. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2766. /* no S/PDIF out */
  2767. if (board_config == CXT5066_HP_LAPTOP)
  2768. spec->multiout.dig_out_nid = 0;
  2769. /* input source automatically selected */
  2770. spec->input_mux = NULL;
  2771. spec->port_d_mode = 0;
  2772. spec->mic_boost = 3; /* default 30dB gain */
  2773. break;
  2774. case CXT5066_OLPC_XO_1_5:
  2775. codec->patch_ops.init = cxt5066_olpc_init;
  2776. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2777. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2778. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2779. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2780. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2781. spec->port_d_mode = 0;
  2782. spec->mic_boost = 3; /* default 30dB gain */
  2783. /* no S/PDIF out */
  2784. spec->multiout.dig_out_nid = 0;
  2785. /* input source automatically selected */
  2786. spec->input_mux = NULL;
  2787. /* our capture hooks which allow us to turn on the microphone LED
  2788. * at the right time */
  2789. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2790. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2791. break;
  2792. case CXT5066_DELL_VOSTRO:
  2793. codec->patch_ops.init = cxt5066_init;
  2794. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2795. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2796. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2797. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2798. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2799. spec->port_d_mode = 0;
  2800. spec->dell_vostro = 1;
  2801. spec->mic_boost = 3; /* default 30dB gain */
  2802. /* no S/PDIF out */
  2803. spec->multiout.dig_out_nid = 0;
  2804. /* input source automatically selected */
  2805. spec->input_mux = NULL;
  2806. break;
  2807. case CXT5066_IDEAPAD:
  2808. codec->patch_ops.init = cxt5066_init;
  2809. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2810. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2811. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2812. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2813. spec->port_d_mode = 0;
  2814. spec->ideapad = 1;
  2815. spec->mic_boost = 2; /* default 20dB gain */
  2816. /* no S/PDIF out */
  2817. spec->multiout.dig_out_nid = 0;
  2818. /* input source automatically selected */
  2819. spec->input_mux = NULL;
  2820. break;
  2821. case CXT5066_THINKPAD:
  2822. codec->patch_ops.init = cxt5066_init;
  2823. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2824. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2825. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2826. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2827. spec->thinkpad = 1;
  2828. spec->port_d_mode = PIN_OUT;
  2829. spec->mic_boost = 2; /* default 20dB gain */
  2830. /* no S/PDIF out */
  2831. spec->multiout.dig_out_nid = 0;
  2832. /* input source automatically selected */
  2833. spec->input_mux = NULL;
  2834. break;
  2835. }
  2836. if (spec->beep_amp)
  2837. snd_hda_attach_beep_device(codec, spec->beep_amp);
  2838. return 0;
  2839. }
  2840. /*
  2841. * Automatic parser for CX20641 & co
  2842. */
  2843. static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2844. struct hda_codec *codec,
  2845. unsigned int stream_tag,
  2846. unsigned int format,
  2847. struct snd_pcm_substream *substream)
  2848. {
  2849. struct conexant_spec *spec = codec->spec;
  2850. hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
  2851. if (spec->adc_switching) {
  2852. spec->cur_adc = adc;
  2853. spec->cur_adc_stream_tag = stream_tag;
  2854. spec->cur_adc_format = format;
  2855. }
  2856. snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
  2857. return 0;
  2858. }
  2859. static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2860. struct hda_codec *codec,
  2861. struct snd_pcm_substream *substream)
  2862. {
  2863. struct conexant_spec *spec = codec->spec;
  2864. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  2865. spec->cur_adc = 0;
  2866. return 0;
  2867. }
  2868. static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
  2869. .substreams = 1,
  2870. .channels_min = 2,
  2871. .channels_max = 2,
  2872. .nid = 0, /* fill later */
  2873. .ops = {
  2874. .prepare = cx_auto_capture_pcm_prepare,
  2875. .cleanup = cx_auto_capture_pcm_cleanup
  2876. },
  2877. };
  2878. static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
  2879. #define get_connection_index(codec, mux, nid)\
  2880. snd_hda_get_conn_index(codec, mux, nid, 0)
  2881. /* get an unassigned DAC from the given list.
  2882. * Return the nid if found and reduce the DAC list, or return zero if
  2883. * not found
  2884. */
  2885. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
  2886. hda_nid_t *dacs, int *num_dacs)
  2887. {
  2888. int i, nums = *num_dacs;
  2889. hda_nid_t ret = 0;
  2890. for (i = 0; i < nums; i++) {
  2891. if (get_connection_index(codec, pin, dacs[i]) >= 0) {
  2892. ret = dacs[i];
  2893. break;
  2894. }
  2895. }
  2896. if (!ret)
  2897. return 0;
  2898. if (--nums > 0)
  2899. memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
  2900. *num_dacs = nums;
  2901. return ret;
  2902. }
  2903. #define MAX_AUTO_DACS 5
  2904. #define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
  2905. /* fill analog DAC list from the widget tree */
  2906. static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  2907. {
  2908. hda_nid_t nid, end_nid;
  2909. int nums = 0;
  2910. end_nid = codec->start_nid + codec->num_nodes;
  2911. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2912. unsigned int wcaps = get_wcaps(codec, nid);
  2913. unsigned int type = get_wcaps_type(wcaps);
  2914. if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
  2915. dacs[nums++] = nid;
  2916. if (nums >= MAX_AUTO_DACS)
  2917. break;
  2918. }
  2919. }
  2920. return nums;
  2921. }
  2922. /* fill pin_dac_pair list from the pin and dac list */
  2923. static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  2924. int num_pins, hda_nid_t *dacs, int *rest,
  2925. struct pin_dac_pair *filled, int type)
  2926. {
  2927. int i, nums;
  2928. nums = 0;
  2929. for (i = 0; i < num_pins; i++) {
  2930. filled[nums].pin = pins[i];
  2931. filled[nums].type = type;
  2932. filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
  2933. if (!filled[nums].dac && i > 0 && filled[0].dac)
  2934. filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
  2935. nums++;
  2936. }
  2937. return nums;
  2938. }
  2939. /* parse analog output paths */
  2940. static void cx_auto_parse_output(struct hda_codec *codec)
  2941. {
  2942. struct conexant_spec *spec = codec->spec;
  2943. struct auto_pin_cfg *cfg = &spec->autocfg;
  2944. hda_nid_t dacs[MAX_AUTO_DACS];
  2945. int i, j, nums, rest;
  2946. rest = fill_cx_auto_dacs(codec, dacs);
  2947. /* parse all analog output pins */
  2948. nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
  2949. dacs, &rest, spec->dac_info,
  2950. AUTO_PIN_LINE_OUT);
  2951. nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
  2952. dacs, &rest, spec->dac_info + nums,
  2953. AUTO_PIN_HP_OUT);
  2954. nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
  2955. dacs, &rest, spec->dac_info + nums,
  2956. AUTO_PIN_SPEAKER_OUT);
  2957. spec->dac_info_filled = nums;
  2958. /* fill multiout struct */
  2959. for (i = 0; i < nums; i++) {
  2960. hda_nid_t dac = spec->dac_info[i].dac;
  2961. if (!dac || (dac & DAC_SLAVE_FLAG))
  2962. continue;
  2963. switch (spec->dac_info[i].type) {
  2964. case AUTO_PIN_LINE_OUT:
  2965. spec->private_dac_nids[spec->multiout.num_dacs] = dac;
  2966. spec->multiout.num_dacs++;
  2967. break;
  2968. case AUTO_PIN_HP_OUT:
  2969. case AUTO_PIN_SPEAKER_OUT:
  2970. if (!spec->multiout.hp_nid) {
  2971. spec->multiout.hp_nid = dac;
  2972. break;
  2973. }
  2974. for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
  2975. if (!spec->multiout.extra_out_nid[j]) {
  2976. spec->multiout.extra_out_nid[j] = dac;
  2977. break;
  2978. }
  2979. break;
  2980. }
  2981. }
  2982. spec->multiout.dac_nids = spec->private_dac_nids;
  2983. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2984. for (i = 0; i < cfg->hp_outs; i++) {
  2985. if (is_jack_detectable(codec, cfg->hp_pins[i])) {
  2986. spec->auto_mute = 1;
  2987. break;
  2988. }
  2989. }
  2990. if (spec->auto_mute &&
  2991. cfg->line_out_pins[0] &&
  2992. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
  2993. cfg->line_out_pins[0] != cfg->hp_pins[0] &&
  2994. cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
  2995. for (i = 0; i < cfg->line_outs; i++) {
  2996. if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
  2997. spec->detect_line = 1;
  2998. break;
  2999. }
  3000. }
  3001. spec->automute_lines = spec->detect_line;
  3002. }
  3003. spec->vmaster_nid = spec->private_dac_nids[0];
  3004. }
  3005. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  3006. hda_nid_t *pins, bool on);
  3007. static void do_automute(struct hda_codec *codec, int num_pins,
  3008. hda_nid_t *pins, bool on)
  3009. {
  3010. int i;
  3011. for (i = 0; i < num_pins; i++)
  3012. snd_hda_codec_write(codec, pins[i], 0,
  3013. AC_VERB_SET_PIN_WIDGET_CONTROL,
  3014. on ? PIN_OUT : 0);
  3015. cx_auto_turn_eapd(codec, num_pins, pins, on);
  3016. }
  3017. static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  3018. {
  3019. int i, present = 0;
  3020. for (i = 0; i < num_pins; i++) {
  3021. hda_nid_t nid = pins[i];
  3022. if (!nid || !is_jack_detectable(codec, nid))
  3023. break;
  3024. snd_hda_input_jack_report(codec, nid);
  3025. present |= snd_hda_jack_detect(codec, nid);
  3026. }
  3027. return present;
  3028. }
  3029. /* auto-mute/unmute speaker and line outs according to headphone jack */
  3030. static void cx_auto_update_speakers(struct hda_codec *codec)
  3031. {
  3032. struct conexant_spec *spec = codec->spec;
  3033. struct auto_pin_cfg *cfg = &spec->autocfg;
  3034. int on = 1;
  3035. /* turn on HP EAPD when HP jacks are present */
  3036. if (spec->auto_mute)
  3037. on = spec->hp_present;
  3038. cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
  3039. /* mute speakers in auto-mode if HP or LO jacks are plugged */
  3040. if (spec->auto_mute)
  3041. on = !(spec->hp_present ||
  3042. (spec->detect_line && spec->line_present));
  3043. do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
  3044. /* toggle line-out mutes if needed, too */
  3045. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  3046. if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
  3047. cfg->line_out_pins[0] == cfg->speaker_pins[0])
  3048. return;
  3049. if (spec->auto_mute) {
  3050. /* mute LO in auto-mode when HP jack is present */
  3051. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
  3052. spec->automute_lines)
  3053. on = !spec->hp_present;
  3054. else
  3055. on = 1;
  3056. }
  3057. do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
  3058. }
  3059. static void cx_auto_hp_automute(struct hda_codec *codec)
  3060. {
  3061. struct conexant_spec *spec = codec->spec;
  3062. struct auto_pin_cfg *cfg = &spec->autocfg;
  3063. if (!spec->auto_mute)
  3064. return;
  3065. spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
  3066. cx_auto_update_speakers(codec);
  3067. }
  3068. static void cx_auto_line_automute(struct hda_codec *codec)
  3069. {
  3070. struct conexant_spec *spec = codec->spec;
  3071. struct auto_pin_cfg *cfg = &spec->autocfg;
  3072. if (!spec->auto_mute || !spec->detect_line)
  3073. return;
  3074. spec->line_present = detect_jacks(codec, cfg->line_outs,
  3075. cfg->line_out_pins);
  3076. cx_auto_update_speakers(codec);
  3077. }
  3078. static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
  3079. struct snd_ctl_elem_info *uinfo)
  3080. {
  3081. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3082. struct conexant_spec *spec = codec->spec;
  3083. static const char * const texts2[] = {
  3084. "Disabled", "Enabled"
  3085. };
  3086. static const char * const texts3[] = {
  3087. "Disabled", "Speaker Only", "Line-Out+Speaker"
  3088. };
  3089. const char * const *texts;
  3090. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  3091. uinfo->count = 1;
  3092. if (spec->automute_hp_lo) {
  3093. uinfo->value.enumerated.items = 3;
  3094. texts = texts3;
  3095. } else {
  3096. uinfo->value.enumerated.items = 2;
  3097. texts = texts2;
  3098. }
  3099. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  3100. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  3101. strcpy(uinfo->value.enumerated.name,
  3102. texts[uinfo->value.enumerated.item]);
  3103. return 0;
  3104. }
  3105. static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
  3106. struct snd_ctl_elem_value *ucontrol)
  3107. {
  3108. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3109. struct conexant_spec *spec = codec->spec;
  3110. unsigned int val;
  3111. if (!spec->auto_mute)
  3112. val = 0;
  3113. else if (!spec->automute_lines)
  3114. val = 1;
  3115. else
  3116. val = 2;
  3117. ucontrol->value.enumerated.item[0] = val;
  3118. return 0;
  3119. }
  3120. static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
  3121. struct snd_ctl_elem_value *ucontrol)
  3122. {
  3123. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3124. struct conexant_spec *spec = codec->spec;
  3125. switch (ucontrol->value.enumerated.item[0]) {
  3126. case 0:
  3127. if (!spec->auto_mute)
  3128. return 0;
  3129. spec->auto_mute = 0;
  3130. break;
  3131. case 1:
  3132. if (spec->auto_mute && !spec->automute_lines)
  3133. return 0;
  3134. spec->auto_mute = 1;
  3135. spec->automute_lines = 0;
  3136. break;
  3137. case 2:
  3138. if (!spec->automute_hp_lo)
  3139. return -EINVAL;
  3140. if (spec->auto_mute && spec->automute_lines)
  3141. return 0;
  3142. spec->auto_mute = 1;
  3143. spec->automute_lines = 1;
  3144. break;
  3145. default:
  3146. return -EINVAL;
  3147. }
  3148. cx_auto_update_speakers(codec);
  3149. return 1;
  3150. }
  3151. static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
  3152. {
  3153. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3154. .name = "Auto-Mute Mode",
  3155. .info = cx_automute_mode_info,
  3156. .get = cx_automute_mode_get,
  3157. .put = cx_automute_mode_put,
  3158. },
  3159. { }
  3160. };
  3161. static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
  3162. struct snd_ctl_elem_info *uinfo)
  3163. {
  3164. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3165. struct conexant_spec *spec = codec->spec;
  3166. return snd_hda_input_mux_info(&spec->private_imux, uinfo);
  3167. }
  3168. static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
  3169. struct snd_ctl_elem_value *ucontrol)
  3170. {
  3171. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3172. struct conexant_spec *spec = codec->spec;
  3173. ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
  3174. return 0;
  3175. }
  3176. /* look for the route the given pin from mux and return the index;
  3177. * if do_select is set, actually select the route.
  3178. */
  3179. static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3180. hda_nid_t pin, hda_nid_t *srcp,
  3181. bool do_select, int depth)
  3182. {
  3183. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  3184. int i, nums;
  3185. switch (get_wcaps_type(get_wcaps(codec, mux))) {
  3186. case AC_WID_AUD_IN:
  3187. case AC_WID_AUD_SEL:
  3188. case AC_WID_AUD_MIX:
  3189. break;
  3190. default:
  3191. return -1;
  3192. }
  3193. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  3194. for (i = 0; i < nums; i++)
  3195. if (conn[i] == pin) {
  3196. if (do_select)
  3197. snd_hda_codec_write(codec, mux, 0,
  3198. AC_VERB_SET_CONNECT_SEL, i);
  3199. if (srcp)
  3200. *srcp = mux;
  3201. return i;
  3202. }
  3203. depth++;
  3204. if (depth == 2)
  3205. return -1;
  3206. for (i = 0; i < nums; i++) {
  3207. int ret = __select_input_connection(codec, conn[i], pin, srcp,
  3208. do_select, depth);
  3209. if (ret >= 0) {
  3210. if (do_select)
  3211. snd_hda_codec_write(codec, mux, 0,
  3212. AC_VERB_SET_CONNECT_SEL, i);
  3213. return i;
  3214. }
  3215. }
  3216. return -1;
  3217. }
  3218. static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3219. hda_nid_t pin)
  3220. {
  3221. __select_input_connection(codec, mux, pin, NULL, true, 0);
  3222. }
  3223. static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3224. hda_nid_t pin)
  3225. {
  3226. return __select_input_connection(codec, mux, pin, NULL, false, 0);
  3227. }
  3228. static int cx_auto_mux_enum_update(struct hda_codec *codec,
  3229. const struct hda_input_mux *imux,
  3230. unsigned int idx)
  3231. {
  3232. struct conexant_spec *spec = codec->spec;
  3233. hda_nid_t adc;
  3234. int changed = 1;
  3235. if (!imux->num_items)
  3236. return 0;
  3237. if (idx >= imux->num_items)
  3238. idx = imux->num_items - 1;
  3239. if (spec->cur_mux[0] == idx)
  3240. changed = 0;
  3241. adc = spec->imux_info[idx].adc;
  3242. select_input_connection(codec, spec->imux_info[idx].adc,
  3243. spec->imux_info[idx].pin);
  3244. if (spec->cur_adc && spec->cur_adc != adc) {
  3245. /* stream is running, let's swap the current ADC */
  3246. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  3247. spec->cur_adc = adc;
  3248. snd_hda_codec_setup_stream(codec, adc,
  3249. spec->cur_adc_stream_tag, 0,
  3250. spec->cur_adc_format);
  3251. }
  3252. spec->cur_mux[0] = idx;
  3253. return changed;
  3254. }
  3255. static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
  3256. struct snd_ctl_elem_value *ucontrol)
  3257. {
  3258. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3259. struct conexant_spec *spec = codec->spec;
  3260. return cx_auto_mux_enum_update(codec, &spec->private_imux,
  3261. ucontrol->value.enumerated.item[0]);
  3262. }
  3263. static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
  3264. {
  3265. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3266. .name = "Capture Source",
  3267. .info = cx_auto_mux_enum_info,
  3268. .get = cx_auto_mux_enum_get,
  3269. .put = cx_auto_mux_enum_put
  3270. },
  3271. {}
  3272. };
  3273. static bool select_automic(struct hda_codec *codec, int idx, bool detect)
  3274. {
  3275. struct conexant_spec *spec = codec->spec;
  3276. if (idx < 0)
  3277. return false;
  3278. if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
  3279. return false;
  3280. cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
  3281. return true;
  3282. }
  3283. /* automatic switch internal and external mic */
  3284. static void cx_auto_automic(struct hda_codec *codec)
  3285. {
  3286. struct conexant_spec *spec = codec->spec;
  3287. if (!spec->auto_mic)
  3288. return;
  3289. if (!select_automic(codec, spec->auto_mic_ext, true))
  3290. if (!select_automic(codec, spec->auto_mic_dock, true))
  3291. select_automic(codec, spec->auto_mic_int, false);
  3292. }
  3293. static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
  3294. {
  3295. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  3296. switch (res >> 26) {
  3297. case CONEXANT_HP_EVENT:
  3298. cx_auto_hp_automute(codec);
  3299. break;
  3300. case CONEXANT_LINE_EVENT:
  3301. cx_auto_line_automute(codec);
  3302. break;
  3303. case CONEXANT_MIC_EVENT:
  3304. cx_auto_automic(codec);
  3305. snd_hda_input_jack_report(codec, nid);
  3306. break;
  3307. }
  3308. }
  3309. /* check whether the pin config is suitable for auto-mic switching;
  3310. * auto-mic is enabled only when one int-mic and one ext- and/or
  3311. * one dock-mic exist
  3312. */
  3313. static void cx_auto_check_auto_mic(struct hda_codec *codec)
  3314. {
  3315. struct conexant_spec *spec = codec->spec;
  3316. int pset[INPUT_PIN_ATTR_NORMAL + 1];
  3317. int i;
  3318. for (i = 0; i < ARRAY_SIZE(pset); i++)
  3319. pset[i] = -1;
  3320. for (i = 0; i < spec->private_imux.num_items; i++) {
  3321. hda_nid_t pin = spec->imux_info[i].pin;
  3322. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
  3323. int type, attr;
  3324. attr = snd_hda_get_input_pin_attr(def_conf);
  3325. if (attr == INPUT_PIN_ATTR_UNUSED)
  3326. return; /* invalid entry */
  3327. if (attr > INPUT_PIN_ATTR_NORMAL)
  3328. attr = INPUT_PIN_ATTR_NORMAL;
  3329. if (attr != INPUT_PIN_ATTR_INT &&
  3330. !is_jack_detectable(codec, pin))
  3331. return; /* non-detectable pin */
  3332. type = get_defcfg_device(def_conf);
  3333. if (type != AC_JACK_MIC_IN &&
  3334. (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
  3335. return; /* no valid input type */
  3336. if (pset[attr] >= 0)
  3337. return; /* already occupied */
  3338. pset[attr] = i;
  3339. }
  3340. if (pset[INPUT_PIN_ATTR_INT] < 0 ||
  3341. (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
  3342. return; /* no input to switch*/
  3343. spec->auto_mic = 1;
  3344. spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
  3345. spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
  3346. spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
  3347. }
  3348. static void cx_auto_parse_input(struct hda_codec *codec)
  3349. {
  3350. struct conexant_spec *spec = codec->spec;
  3351. struct auto_pin_cfg *cfg = &spec->autocfg;
  3352. struct hda_input_mux *imux;
  3353. int i, j;
  3354. imux = &spec->private_imux;
  3355. for (i = 0; i < cfg->num_inputs; i++) {
  3356. for (j = 0; j < spec->num_adc_nids; j++) {
  3357. hda_nid_t adc = spec->adc_nids[j];
  3358. int idx = get_input_connection(codec, adc,
  3359. cfg->inputs[i].pin);
  3360. if (idx >= 0) {
  3361. const char *label;
  3362. label = hda_get_autocfg_input_label(codec, cfg, i);
  3363. spec->imux_info[imux->num_items].index = i;
  3364. spec->imux_info[imux->num_items].boost = 0;
  3365. spec->imux_info[imux->num_items].adc = adc;
  3366. spec->imux_info[imux->num_items].pin =
  3367. cfg->inputs[i].pin;
  3368. snd_hda_add_imux_item(imux, label, idx, NULL);
  3369. break;
  3370. }
  3371. }
  3372. }
  3373. if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
  3374. cx_auto_check_auto_mic(codec);
  3375. if (imux->num_items > 1 && !spec->auto_mic) {
  3376. for (i = 1; i < imux->num_items; i++) {
  3377. if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
  3378. spec->adc_switching = 1;
  3379. break;
  3380. }
  3381. }
  3382. }
  3383. }
  3384. /* get digital-input audio widget corresponding to the given pin */
  3385. static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
  3386. {
  3387. hda_nid_t nid, end_nid;
  3388. end_nid = codec->start_nid + codec->num_nodes;
  3389. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3390. unsigned int wcaps = get_wcaps(codec, nid);
  3391. unsigned int type = get_wcaps_type(wcaps);
  3392. if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
  3393. if (get_connection_index(codec, nid, pin) >= 0)
  3394. return nid;
  3395. }
  3396. }
  3397. return 0;
  3398. }
  3399. static void cx_auto_parse_digital(struct hda_codec *codec)
  3400. {
  3401. struct conexant_spec *spec = codec->spec;
  3402. struct auto_pin_cfg *cfg = &spec->autocfg;
  3403. hda_nid_t nid;
  3404. if (cfg->dig_outs &&
  3405. snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
  3406. spec->multiout.dig_out_nid = nid;
  3407. if (cfg->dig_in_pin)
  3408. spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
  3409. }
  3410. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3411. static void cx_auto_parse_beep(struct hda_codec *codec)
  3412. {
  3413. struct conexant_spec *spec = codec->spec;
  3414. hda_nid_t nid, end_nid;
  3415. end_nid = codec->start_nid + codec->num_nodes;
  3416. for (nid = codec->start_nid; nid < end_nid; nid++)
  3417. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  3418. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  3419. break;
  3420. }
  3421. }
  3422. #else
  3423. #define cx_auto_parse_beep(codec)
  3424. #endif
  3425. static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  3426. {
  3427. int i;
  3428. for (i = 0; i < nums; i++)
  3429. if (list[i] == nid)
  3430. return true;
  3431. return false;
  3432. }
  3433. /* parse extra-EAPD that aren't assigned to any pins */
  3434. static void cx_auto_parse_eapd(struct hda_codec *codec)
  3435. {
  3436. struct conexant_spec *spec = codec->spec;
  3437. struct auto_pin_cfg *cfg = &spec->autocfg;
  3438. hda_nid_t nid, end_nid;
  3439. end_nid = codec->start_nid + codec->num_nodes;
  3440. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3441. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  3442. continue;
  3443. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
  3444. continue;
  3445. if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
  3446. found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
  3447. found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs))
  3448. continue;
  3449. spec->eapds[spec->num_eapds++] = nid;
  3450. if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
  3451. break;
  3452. }
  3453. }
  3454. static int cx_auto_parse_auto_config(struct hda_codec *codec)
  3455. {
  3456. struct conexant_spec *spec = codec->spec;
  3457. int err;
  3458. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3459. if (err < 0)
  3460. return err;
  3461. cx_auto_parse_output(codec);
  3462. cx_auto_parse_input(codec);
  3463. cx_auto_parse_digital(codec);
  3464. cx_auto_parse_beep(codec);
  3465. cx_auto_parse_eapd(codec);
  3466. return 0;
  3467. }
  3468. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  3469. hda_nid_t *pins, bool on)
  3470. {
  3471. int i;
  3472. for (i = 0; i < num_pins; i++) {
  3473. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  3474. snd_hda_codec_write(codec, pins[i], 0,
  3475. AC_VERB_SET_EAPD_BTLENABLE,
  3476. on ? 0x02 : 0);
  3477. }
  3478. }
  3479. static void select_connection(struct hda_codec *codec, hda_nid_t pin,
  3480. hda_nid_t src)
  3481. {
  3482. int idx = get_connection_index(codec, pin, src);
  3483. if (idx >= 0)
  3484. snd_hda_codec_write(codec, pin, 0,
  3485. AC_VERB_SET_CONNECT_SEL, idx);
  3486. }
  3487. static void mute_outputs(struct hda_codec *codec, int num_nids,
  3488. const hda_nid_t *nids)
  3489. {
  3490. int i, val;
  3491. for (i = 0; i < num_nids; i++) {
  3492. hda_nid_t nid = nids[i];
  3493. if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
  3494. continue;
  3495. if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
  3496. val = AMP_OUT_MUTE;
  3497. else
  3498. val = AMP_OUT_ZERO;
  3499. snd_hda_codec_write(codec, nid, 0,
  3500. AC_VERB_SET_AMP_GAIN_MUTE, val);
  3501. }
  3502. }
  3503. static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
  3504. hda_nid_t *pins, unsigned int tag)
  3505. {
  3506. int i;
  3507. for (i = 0; i < num_pins; i++)
  3508. snd_hda_codec_write(codec, pins[i], 0,
  3509. AC_VERB_SET_UNSOLICITED_ENABLE,
  3510. AC_USRSP_EN | tag);
  3511. }
  3512. static void cx_auto_init_output(struct hda_codec *codec)
  3513. {
  3514. struct conexant_spec *spec = codec->spec;
  3515. struct auto_pin_cfg *cfg = &spec->autocfg;
  3516. hda_nid_t nid;
  3517. int i;
  3518. mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
  3519. for (i = 0; i < cfg->hp_outs; i++)
  3520. snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
  3521. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
  3522. mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
  3523. mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
  3524. mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
  3525. for (i = 0; i < spec->dac_info_filled; i++) {
  3526. nid = spec->dac_info[i].dac;
  3527. if (!nid)
  3528. nid = spec->multiout.dac_nids[0];
  3529. else if (nid & DAC_SLAVE_FLAG)
  3530. nid &= ~DAC_SLAVE_FLAG;
  3531. select_connection(codec, spec->dac_info[i].pin, nid);
  3532. }
  3533. if (spec->auto_mute) {
  3534. enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
  3535. CONEXANT_HP_EVENT);
  3536. spec->hp_present = detect_jacks(codec, cfg->hp_outs,
  3537. cfg->hp_pins);
  3538. if (spec->detect_line) {
  3539. enable_unsol_pins(codec, cfg->line_outs,
  3540. cfg->line_out_pins,
  3541. CONEXANT_LINE_EVENT);
  3542. spec->line_present =
  3543. detect_jacks(codec, cfg->line_outs,
  3544. cfg->line_out_pins);
  3545. }
  3546. }
  3547. cx_auto_update_speakers(codec);
  3548. /* turn on/off extra EAPDs, too */
  3549. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
  3550. }
  3551. static void cx_auto_init_input(struct hda_codec *codec)
  3552. {
  3553. struct conexant_spec *spec = codec->spec;
  3554. struct auto_pin_cfg *cfg = &spec->autocfg;
  3555. int i, val;
  3556. for (i = 0; i < spec->num_adc_nids; i++) {
  3557. hda_nid_t nid = spec->adc_nids[i];
  3558. if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
  3559. continue;
  3560. if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
  3561. val = AMP_IN_MUTE(0);
  3562. else
  3563. val = AMP_IN_UNMUTE(0);
  3564. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3565. val);
  3566. }
  3567. for (i = 0; i < cfg->num_inputs; i++) {
  3568. unsigned int type;
  3569. if (cfg->inputs[i].type == AUTO_PIN_MIC)
  3570. type = PIN_VREF80;
  3571. else
  3572. type = PIN_IN;
  3573. snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
  3574. AC_VERB_SET_PIN_WIDGET_CONTROL, type);
  3575. }
  3576. if (spec->auto_mic) {
  3577. if (spec->auto_mic_ext >= 0) {
  3578. snd_hda_codec_write(codec,
  3579. cfg->inputs[spec->auto_mic_ext].pin, 0,
  3580. AC_VERB_SET_UNSOLICITED_ENABLE,
  3581. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3582. }
  3583. if (spec->auto_mic_dock >= 0) {
  3584. snd_hda_codec_write(codec,
  3585. cfg->inputs[spec->auto_mic_dock].pin, 0,
  3586. AC_VERB_SET_UNSOLICITED_ENABLE,
  3587. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3588. }
  3589. cx_auto_automic(codec);
  3590. } else {
  3591. select_input_connection(codec, spec->imux_info[0].adc,
  3592. spec->imux_info[0].pin);
  3593. }
  3594. }
  3595. static void cx_auto_init_digital(struct hda_codec *codec)
  3596. {
  3597. struct conexant_spec *spec = codec->spec;
  3598. struct auto_pin_cfg *cfg = &spec->autocfg;
  3599. if (spec->multiout.dig_out_nid)
  3600. snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
  3601. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3602. if (spec->dig_in_nid)
  3603. snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
  3604. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  3605. }
  3606. static int cx_auto_init(struct hda_codec *codec)
  3607. {
  3608. /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
  3609. cx_auto_init_output(codec);
  3610. cx_auto_init_input(codec);
  3611. cx_auto_init_digital(codec);
  3612. return 0;
  3613. }
  3614. static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
  3615. const char *dir, int cidx,
  3616. hda_nid_t nid, int hda_dir, int amp_idx)
  3617. {
  3618. static char name[32];
  3619. static struct snd_kcontrol_new knew[] = {
  3620. HDA_CODEC_VOLUME(name, 0, 0, 0),
  3621. HDA_CODEC_MUTE(name, 0, 0, 0),
  3622. };
  3623. static const char * const sfx[2] = { "Volume", "Switch" };
  3624. int i, err;
  3625. for (i = 0; i < 2; i++) {
  3626. struct snd_kcontrol *kctl;
  3627. knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
  3628. hda_dir);
  3629. knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
  3630. knew[i].index = cidx;
  3631. snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
  3632. kctl = snd_ctl_new1(&knew[i], codec);
  3633. if (!kctl)
  3634. return -ENOMEM;
  3635. err = snd_hda_ctl_add(codec, nid, kctl);
  3636. if (err < 0)
  3637. return err;
  3638. if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
  3639. break;
  3640. }
  3641. return 0;
  3642. }
  3643. #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
  3644. cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
  3645. #define cx_auto_add_pb_volume(codec, nid, str, idx) \
  3646. cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
  3647. static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
  3648. hda_nid_t pin, const char *name, int idx)
  3649. {
  3650. unsigned int caps;
  3651. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  3652. if (caps & AC_AMPCAP_NUM_STEPS)
  3653. return cx_auto_add_pb_volume(codec, dac, name, idx);
  3654. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  3655. if (caps & AC_AMPCAP_NUM_STEPS)
  3656. return cx_auto_add_pb_volume(codec, pin, name, idx);
  3657. return 0;
  3658. }
  3659. static int cx_auto_build_output_controls(struct hda_codec *codec)
  3660. {
  3661. struct conexant_spec *spec = codec->spec;
  3662. int i, err;
  3663. int num_line = 0, num_hp = 0, num_spk = 0;
  3664. static const char * const texts[3] = { "Front", "Surround", "CLFE" };
  3665. if (spec->dac_info_filled == 1)
  3666. return try_add_pb_volume(codec, spec->dac_info[0].dac,
  3667. spec->dac_info[0].pin,
  3668. "Master", 0);
  3669. for (i = 0; i < spec->dac_info_filled; i++) {
  3670. const char *label;
  3671. int idx, type;
  3672. hda_nid_t dac = spec->dac_info[i].dac;
  3673. if (!dac || (dac & DAC_SLAVE_FLAG))
  3674. continue;
  3675. type = spec->dac_info[i].type;
  3676. if (type == AUTO_PIN_LINE_OUT)
  3677. type = spec->autocfg.line_out_type;
  3678. switch (type) {
  3679. case AUTO_PIN_LINE_OUT:
  3680. default:
  3681. label = texts[num_line++];
  3682. idx = 0;
  3683. break;
  3684. case AUTO_PIN_HP_OUT:
  3685. label = "Headphone";
  3686. idx = num_hp++;
  3687. break;
  3688. case AUTO_PIN_SPEAKER_OUT:
  3689. label = "Speaker";
  3690. idx = num_spk++;
  3691. break;
  3692. }
  3693. err = try_add_pb_volume(codec, dac,
  3694. spec->dac_info[i].pin,
  3695. label, idx);
  3696. if (err < 0)
  3697. return err;
  3698. }
  3699. if (spec->auto_mute) {
  3700. err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
  3701. if (err < 0)
  3702. return err;
  3703. }
  3704. return 0;
  3705. }
  3706. static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
  3707. const char *label, const char *pfx,
  3708. int cidx)
  3709. {
  3710. struct conexant_spec *spec = codec->spec;
  3711. int i;
  3712. for (i = 0; i < spec->num_adc_nids; i++) {
  3713. hda_nid_t adc_nid = spec->adc_nids[i];
  3714. int idx = get_input_connection(codec, adc_nid, nid);
  3715. if (idx < 0)
  3716. continue;
  3717. return cx_auto_add_volume_idx(codec, label, pfx,
  3718. cidx, adc_nid, HDA_INPUT, idx);
  3719. }
  3720. return 0;
  3721. }
  3722. static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
  3723. const char *label, int cidx)
  3724. {
  3725. struct conexant_spec *spec = codec->spec;
  3726. hda_nid_t mux, nid;
  3727. int i, con;
  3728. nid = spec->imux_info[idx].pin;
  3729. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
  3730. return cx_auto_add_volume(codec, label, " Boost", cidx,
  3731. nid, HDA_INPUT);
  3732. con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
  3733. &mux, false, 0);
  3734. if (con < 0)
  3735. return 0;
  3736. for (i = 0; i < idx; i++) {
  3737. if (spec->imux_info[i].boost == mux)
  3738. return 0; /* already present */
  3739. }
  3740. if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
  3741. spec->imux_info[idx].boost = mux;
  3742. return cx_auto_add_volume(codec, label, " Boost", 0,
  3743. mux, HDA_OUTPUT);
  3744. }
  3745. return 0;
  3746. }
  3747. static int cx_auto_build_input_controls(struct hda_codec *codec)
  3748. {
  3749. struct conexant_spec *spec = codec->spec;
  3750. struct hda_input_mux *imux = &spec->private_imux;
  3751. const char *prev_label;
  3752. int input_conn[HDA_MAX_NUM_INPUTS];
  3753. int i, err, cidx;
  3754. int multi_connection;
  3755. multi_connection = 0;
  3756. for (i = 0; i < imux->num_items; i++) {
  3757. cidx = get_input_connection(codec, spec->imux_info[i].adc,
  3758. spec->imux_info[i].pin);
  3759. input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
  3760. if (i > 0 && input_conn[i] != input_conn[0])
  3761. multi_connection = 1;
  3762. }
  3763. prev_label = NULL;
  3764. cidx = 0;
  3765. for (i = 0; i < imux->num_items; i++) {
  3766. hda_nid_t nid = spec->imux_info[i].pin;
  3767. const char *label;
  3768. label = hda_get_autocfg_input_label(codec, &spec->autocfg,
  3769. spec->imux_info[i].index);
  3770. if (label == prev_label)
  3771. cidx++;
  3772. else
  3773. cidx = 0;
  3774. prev_label = label;
  3775. err = cx_auto_add_boost_volume(codec, i, label, cidx);
  3776. if (err < 0)
  3777. return err;
  3778. if (!multi_connection) {
  3779. if (i > 0)
  3780. continue;
  3781. err = cx_auto_add_capture_volume(codec, nid,
  3782. "Capture", "", cidx);
  3783. } else {
  3784. err = cx_auto_add_capture_volume(codec, nid,
  3785. label, " Capture", cidx);
  3786. }
  3787. if (err < 0)
  3788. return err;
  3789. }
  3790. if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
  3791. err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
  3792. if (err < 0)
  3793. return err;
  3794. }
  3795. return 0;
  3796. }
  3797. static int cx_auto_build_controls(struct hda_codec *codec)
  3798. {
  3799. int err;
  3800. err = cx_auto_build_output_controls(codec);
  3801. if (err < 0)
  3802. return err;
  3803. err = cx_auto_build_input_controls(codec);
  3804. if (err < 0)
  3805. return err;
  3806. return conexant_build_controls(codec);
  3807. }
  3808. static int cx_auto_search_adcs(struct hda_codec *codec)
  3809. {
  3810. struct conexant_spec *spec = codec->spec;
  3811. hda_nid_t nid, end_nid;
  3812. end_nid = codec->start_nid + codec->num_nodes;
  3813. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3814. unsigned int caps = get_wcaps(codec, nid);
  3815. if (get_wcaps_type(caps) != AC_WID_AUD_IN)
  3816. continue;
  3817. if (caps & AC_WCAP_DIGITAL)
  3818. continue;
  3819. if (snd_BUG_ON(spec->num_adc_nids >=
  3820. ARRAY_SIZE(spec->private_adc_nids)))
  3821. break;
  3822. spec->private_adc_nids[spec->num_adc_nids++] = nid;
  3823. }
  3824. spec->adc_nids = spec->private_adc_nids;
  3825. return 0;
  3826. }
  3827. static const struct hda_codec_ops cx_auto_patch_ops = {
  3828. .build_controls = cx_auto_build_controls,
  3829. .build_pcms = conexant_build_pcms,
  3830. .init = cx_auto_init,
  3831. .free = conexant_free,
  3832. .unsol_event = cx_auto_unsol_event,
  3833. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3834. .suspend = conexant_suspend,
  3835. #endif
  3836. .reboot_notify = snd_hda_shutup_pins,
  3837. };
  3838. static int patch_conexant_auto(struct hda_codec *codec)
  3839. {
  3840. struct conexant_spec *spec;
  3841. int err;
  3842. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3843. codec->chip_name);
  3844. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3845. if (!spec)
  3846. return -ENOMEM;
  3847. codec->spec = spec;
  3848. codec->pin_amp_workaround = 1;
  3849. err = cx_auto_search_adcs(codec);
  3850. if (err < 0)
  3851. return err;
  3852. err = cx_auto_parse_auto_config(codec);
  3853. if (err < 0) {
  3854. kfree(codec->spec);
  3855. codec->spec = NULL;
  3856. return err;
  3857. }
  3858. spec->capture_stream = &cx_auto_pcm_analog_capture;
  3859. codec->patch_ops = cx_auto_patch_ops;
  3860. if (spec->beep_amp)
  3861. snd_hda_attach_beep_device(codec, spec->beep_amp);
  3862. return 0;
  3863. }
  3864. /*
  3865. */
  3866. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3867. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3868. .patch = patch_cxt5045 },
  3869. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  3870. .patch = patch_cxt5047 },
  3871. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  3872. .patch = patch_cxt5051 },
  3873. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  3874. .patch = patch_cxt5066 },
  3875. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  3876. .patch = patch_cxt5066 },
  3877. { .id = 0x14f15068, .name = "CX20584",
  3878. .patch = patch_cxt5066 },
  3879. { .id = 0x14f15069, .name = "CX20585",
  3880. .patch = patch_cxt5066 },
  3881. { .id = 0x14f1506c, .name = "CX20588",
  3882. .patch = patch_cxt5066 },
  3883. { .id = 0x14f1506e, .name = "CX20590",
  3884. .patch = patch_cxt5066 },
  3885. { .id = 0x14f15097, .name = "CX20631",
  3886. .patch = patch_conexant_auto },
  3887. { .id = 0x14f15098, .name = "CX20632",
  3888. .patch = patch_conexant_auto },
  3889. { .id = 0x14f150a1, .name = "CX20641",
  3890. .patch = patch_conexant_auto },
  3891. { .id = 0x14f150a2, .name = "CX20642",
  3892. .patch = patch_conexant_auto },
  3893. { .id = 0x14f150ab, .name = "CX20651",
  3894. .patch = patch_conexant_auto },
  3895. { .id = 0x14f150ac, .name = "CX20652",
  3896. .patch = patch_conexant_auto },
  3897. { .id = 0x14f150b8, .name = "CX20664",
  3898. .patch = patch_conexant_auto },
  3899. { .id = 0x14f150b9, .name = "CX20665",
  3900. .patch = patch_conexant_auto },
  3901. {} /* terminator */
  3902. };
  3903. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  3904. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  3905. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  3906. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  3907. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  3908. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  3909. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  3910. MODULE_ALIAS("snd-hda-codec-id:14f1506c");
  3911. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  3912. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  3913. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  3914. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  3915. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  3916. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  3917. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  3918. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  3919. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  3920. MODULE_LICENSE("GPL");
  3921. MODULE_DESCRIPTION("Conexant HD-audio codec");
  3922. static struct hda_codec_preset_list conexant_list = {
  3923. .preset = snd_hda_preset_conexant,
  3924. .owner = THIS_MODULE,
  3925. };
  3926. static int __init patch_conexant_init(void)
  3927. {
  3928. return snd_hda_add_codec_preset(&conexant_list);
  3929. }
  3930. static void __exit patch_conexant_exit(void)
  3931. {
  3932. snd_hda_delete_codec_preset(&conexant_list);
  3933. }
  3934. module_init(patch_conexant_init)
  3935. module_exit(patch_conexant_exit)