patch_conexant.c 132 KB

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