patch_conexant.c 137 KB

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