patch_conexant.c 133 KB

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