patch_conexant.c 130 KB

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