patch_conexant.c 132 KB

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