patch_conexant.c 136 KB

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