patch_conexant.c 136 KB

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