patch_conexant.c 131 KB

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