patch_conexant.c 132 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474
  1. /*
  2. * HD audio interface patch for Conexant HDA audio codec
  3. *
  4. * Copyright (c) 2006 Pototskiy Akex <alex.pototskiy@gmail.com>
  5. * Takashi Iwai <tiwai@suse.de>
  6. * Tobin Davis <tdavis@dsl-only.net>
  7. *
  8. * This driver is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This driver is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/init.h>
  23. #include <linux/delay.h>
  24. #include <linux/slab.h>
  25. #include <linux/pci.h>
  26. #include <sound/core.h>
  27. #include <sound/jack.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #include "hda_beep.h"
  31. #define CXT_PIN_DIR_IN 0x00
  32. #define CXT_PIN_DIR_OUT 0x01
  33. #define CXT_PIN_DIR_INOUT 0x02
  34. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  35. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  36. #define CONEXANT_HP_EVENT 0x37
  37. #define CONEXANT_MIC_EVENT 0x38
  38. #define CONEXANT_LINE_EVENT 0x39
  39. /* Conexant 5051 specific */
  40. #define CXT5051_SPDIF_OUT 0x12
  41. #define CXT5051_PORTB_EVENT 0x38
  42. #define CXT5051_PORTC_EVENT 0x39
  43. #define AUTO_MIC_PORTB (1 << 1)
  44. #define AUTO_MIC_PORTC (1 << 2)
  45. struct pin_dac_pair {
  46. hda_nid_t pin;
  47. hda_nid_t dac;
  48. int type;
  49. };
  50. struct imux_info {
  51. hda_nid_t pin; /* input pin NID */
  52. hda_nid_t adc; /* connected ADC NID */
  53. hda_nid_t boost; /* optional boost volume NID */
  54. int index; /* corresponding to autocfg.input */
  55. };
  56. struct conexant_spec {
  57. const struct snd_kcontrol_new *mixers[5];
  58. int num_mixers;
  59. hda_nid_t vmaster_nid;
  60. const struct hda_verb *init_verbs[5]; /* initialization verbs
  61. * don't forget NULL
  62. * termination!
  63. */
  64. unsigned int num_init_verbs;
  65. /* playback */
  66. struct hda_multi_out multiout; /* playback set-up
  67. * max_channels, dacs must be set
  68. * dig_out_nid and hp_nid are optional
  69. */
  70. unsigned int cur_eapd;
  71. unsigned int hp_present;
  72. unsigned int line_present;
  73. unsigned int auto_mic;
  74. int auto_mic_ext; /* imux_pins[] index for ext mic */
  75. int auto_mic_dock; /* imux_pins[] index for dock mic */
  76. int auto_mic_int; /* imux_pins[] index for int mic */
  77. unsigned int need_dac_fix;
  78. hda_nid_t slave_dig_outs[2];
  79. /* capture */
  80. unsigned int num_adc_nids;
  81. const hda_nid_t *adc_nids;
  82. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  83. unsigned int cur_adc_idx;
  84. hda_nid_t cur_adc;
  85. unsigned int cur_adc_stream_tag;
  86. unsigned int cur_adc_format;
  87. const struct hda_pcm_stream *capture_stream;
  88. /* capture source */
  89. const struct hda_input_mux *input_mux;
  90. const hda_nid_t *capsrc_nids;
  91. unsigned int cur_mux[3];
  92. /* channel model */
  93. const struct hda_channel_mode *channel_mode;
  94. int num_channel_mode;
  95. /* PCM information */
  96. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  97. unsigned int spdif_route;
  98. /* dynamic controls, init_verbs and input_mux */
  99. struct auto_pin_cfg autocfg;
  100. struct hda_input_mux private_imux;
  101. struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
  102. hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
  103. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  104. struct pin_dac_pair dac_info[8];
  105. int dac_info_filled;
  106. unsigned int port_d_mode;
  107. unsigned int auto_mute:1; /* used in auto-parser */
  108. unsigned int detect_line:1; /* Line-out detection enabled */
  109. unsigned int automute_lines:1; /* automute line-out as well */
  110. unsigned int automute_hp_lo:1; /* both HP and LO available */
  111. unsigned int dell_automute:1;
  112. unsigned int dell_vostro:1;
  113. unsigned int ideapad:1;
  114. unsigned int thinkpad:1;
  115. unsigned int hp_laptop:1;
  116. unsigned int asus:1;
  117. unsigned int adc_switching:1;
  118. unsigned int ext_mic_present;
  119. unsigned int recording;
  120. void (*capture_prepare)(struct hda_codec *codec);
  121. void (*capture_cleanup)(struct hda_codec *codec);
  122. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  123. * through the microphone jack.
  124. * When the user enables this through a mixer switch, both internal and
  125. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  126. * we also allow the bias to be configured through a separate mixer
  127. * control. */
  128. unsigned int dc_enable;
  129. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  130. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  131. unsigned int beep_amp;
  132. /* extra EAPD pins */
  133. unsigned int num_eapds;
  134. hda_nid_t eapds[4];
  135. };
  136. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  137. struct hda_codec *codec,
  138. struct snd_pcm_substream *substream)
  139. {
  140. struct conexant_spec *spec = codec->spec;
  141. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  142. hinfo);
  143. }
  144. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  145. struct hda_codec *codec,
  146. unsigned int stream_tag,
  147. unsigned int format,
  148. struct snd_pcm_substream *substream)
  149. {
  150. struct conexant_spec *spec = codec->spec;
  151. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  152. stream_tag,
  153. format, substream);
  154. }
  155. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  156. struct hda_codec *codec,
  157. struct snd_pcm_substream *substream)
  158. {
  159. struct conexant_spec *spec = codec->spec;
  160. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  161. }
  162. /*
  163. * Digital out
  164. */
  165. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  166. struct hda_codec *codec,
  167. struct snd_pcm_substream *substream)
  168. {
  169. struct conexant_spec *spec = codec->spec;
  170. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  171. }
  172. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  173. struct hda_codec *codec,
  174. struct snd_pcm_substream *substream)
  175. {
  176. struct conexant_spec *spec = codec->spec;
  177. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  178. }
  179. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  180. struct hda_codec *codec,
  181. unsigned int stream_tag,
  182. unsigned int format,
  183. struct snd_pcm_substream *substream)
  184. {
  185. struct conexant_spec *spec = codec->spec;
  186. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  187. stream_tag,
  188. format, substream);
  189. }
  190. /*
  191. * Analog capture
  192. */
  193. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  194. struct hda_codec *codec,
  195. unsigned int stream_tag,
  196. unsigned int format,
  197. struct snd_pcm_substream *substream)
  198. {
  199. struct conexant_spec *spec = codec->spec;
  200. if (spec->capture_prepare)
  201. spec->capture_prepare(codec);
  202. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  203. stream_tag, 0, format);
  204. return 0;
  205. }
  206. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  207. struct hda_codec *codec,
  208. struct snd_pcm_substream *substream)
  209. {
  210. struct conexant_spec *spec = codec->spec;
  211. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  212. if (spec->capture_cleanup)
  213. spec->capture_cleanup(codec);
  214. return 0;
  215. }
  216. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  217. .substreams = 1,
  218. .channels_min = 2,
  219. .channels_max = 2,
  220. .nid = 0, /* fill later */
  221. .ops = {
  222. .open = conexant_playback_pcm_open,
  223. .prepare = conexant_playback_pcm_prepare,
  224. .cleanup = conexant_playback_pcm_cleanup
  225. },
  226. };
  227. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  228. .substreams = 1,
  229. .channels_min = 2,
  230. .channels_max = 2,
  231. .nid = 0, /* fill later */
  232. .ops = {
  233. .prepare = conexant_capture_pcm_prepare,
  234. .cleanup = conexant_capture_pcm_cleanup
  235. },
  236. };
  237. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  238. .substreams = 1,
  239. .channels_min = 2,
  240. .channels_max = 2,
  241. .nid = 0, /* fill later */
  242. .ops = {
  243. .open = conexant_dig_playback_pcm_open,
  244. .close = conexant_dig_playback_pcm_close,
  245. .prepare = conexant_dig_playback_pcm_prepare
  246. },
  247. };
  248. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  249. .substreams = 1,
  250. .channels_min = 2,
  251. .channels_max = 2,
  252. /* NID is set in alc_build_pcms */
  253. };
  254. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  255. struct hda_codec *codec,
  256. unsigned int stream_tag,
  257. unsigned int format,
  258. struct snd_pcm_substream *substream)
  259. {
  260. struct conexant_spec *spec = codec->spec;
  261. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  262. spec->cur_adc_stream_tag = stream_tag;
  263. spec->cur_adc_format = format;
  264. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  265. return 0;
  266. }
  267. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  268. struct hda_codec *codec,
  269. struct snd_pcm_substream *substream)
  270. {
  271. struct conexant_spec *spec = codec->spec;
  272. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  273. spec->cur_adc = 0;
  274. return 0;
  275. }
  276. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  277. .substreams = 1,
  278. .channels_min = 2,
  279. .channels_max = 2,
  280. .nid = 0, /* fill later */
  281. .ops = {
  282. .prepare = cx5051_capture_pcm_prepare,
  283. .cleanup = cx5051_capture_pcm_cleanup
  284. },
  285. };
  286. static int conexant_build_pcms(struct hda_codec *codec)
  287. {
  288. struct conexant_spec *spec = codec->spec;
  289. struct hda_pcm *info = spec->pcm_rec;
  290. codec->num_pcms = 1;
  291. codec->pcm_info = info;
  292. info->name = "CONEXANT Analog";
  293. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  294. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  295. spec->multiout.max_channels;
  296. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  297. spec->multiout.dac_nids[0];
  298. if (spec->capture_stream)
  299. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  300. else {
  301. if (codec->vendor_id == 0x14f15051)
  302. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  303. cx5051_pcm_analog_capture;
  304. else {
  305. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  306. conexant_pcm_analog_capture;
  307. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  308. spec->num_adc_nids;
  309. }
  310. }
  311. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  312. if (spec->multiout.dig_out_nid) {
  313. info++;
  314. codec->num_pcms++;
  315. info->name = "Conexant Digital";
  316. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  317. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  318. conexant_pcm_digital_playback;
  319. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  320. spec->multiout.dig_out_nid;
  321. if (spec->dig_in_nid) {
  322. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  323. conexant_pcm_digital_capture;
  324. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  325. spec->dig_in_nid;
  326. }
  327. if (spec->slave_dig_outs[0])
  328. codec->slave_dig_outs = spec->slave_dig_outs;
  329. }
  330. return 0;
  331. }
  332. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  333. struct snd_ctl_elem_info *uinfo)
  334. {
  335. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  336. struct conexant_spec *spec = codec->spec;
  337. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  338. }
  339. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  340. struct snd_ctl_elem_value *ucontrol)
  341. {
  342. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  343. struct conexant_spec *spec = codec->spec;
  344. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  345. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  346. return 0;
  347. }
  348. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  349. struct snd_ctl_elem_value *ucontrol)
  350. {
  351. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  352. struct conexant_spec *spec = codec->spec;
  353. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  354. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  355. spec->capsrc_nids[adc_idx],
  356. &spec->cur_mux[adc_idx]);
  357. }
  358. static int conexant_init_jacks(struct hda_codec *codec)
  359. {
  360. #ifdef CONFIG_SND_HDA_INPUT_JACK
  361. struct conexant_spec *spec = codec->spec;
  362. int i;
  363. for (i = 0; i < spec->num_init_verbs; i++) {
  364. const struct hda_verb *hv;
  365. hv = spec->init_verbs[i];
  366. while (hv->nid) {
  367. int err = 0;
  368. switch (hv->param ^ AC_USRSP_EN) {
  369. case CONEXANT_HP_EVENT:
  370. err = snd_hda_input_jack_add(codec, hv->nid,
  371. SND_JACK_HEADPHONE, NULL);
  372. snd_hda_input_jack_report(codec, hv->nid);
  373. break;
  374. case CXT5051_PORTC_EVENT:
  375. case CONEXANT_MIC_EVENT:
  376. err = snd_hda_input_jack_add(codec, hv->nid,
  377. SND_JACK_MICROPHONE, NULL);
  378. snd_hda_input_jack_report(codec, hv->nid);
  379. break;
  380. }
  381. if (err < 0)
  382. return err;
  383. ++hv;
  384. }
  385. }
  386. #endif /* CONFIG_SND_HDA_INPUT_JACK */
  387. return 0;
  388. }
  389. static int conexant_init(struct hda_codec *codec)
  390. {
  391. struct conexant_spec *spec = codec->spec;
  392. int i;
  393. for (i = 0; i < spec->num_init_verbs; i++)
  394. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  395. return 0;
  396. }
  397. static void conexant_free(struct hda_codec *codec)
  398. {
  399. snd_hda_input_jack_free(codec);
  400. snd_hda_detach_beep_device(codec);
  401. kfree(codec->spec);
  402. }
  403. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  404. {
  405. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  406. .name = "Capture Source",
  407. .info = conexant_mux_enum_info,
  408. .get = conexant_mux_enum_get,
  409. .put = conexant_mux_enum_put
  410. },
  411. {}
  412. };
  413. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  414. /* additional beep mixers; the actual parameters are overwritten at build */
  415. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  416. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  417. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  418. { } /* end */
  419. };
  420. #endif
  421. static const char * const slave_vols[] = {
  422. "Headphone Playback Volume",
  423. "Speaker Playback Volume",
  424. "Front Playback Volume",
  425. "Surround Playback Volume",
  426. "CLFE Playback Volume",
  427. NULL
  428. };
  429. static const char * const slave_sws[] = {
  430. "Headphone Playback Switch",
  431. "Speaker Playback Switch",
  432. "Front Playback Switch",
  433. "Surround Playback Switch",
  434. "CLFE Playback Switch",
  435. NULL
  436. };
  437. static int conexant_build_controls(struct hda_codec *codec)
  438. {
  439. struct conexant_spec *spec = codec->spec;
  440. unsigned int i;
  441. int err;
  442. for (i = 0; i < spec->num_mixers; i++) {
  443. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  444. if (err < 0)
  445. return err;
  446. }
  447. if (spec->multiout.dig_out_nid) {
  448. err = snd_hda_create_spdif_out_ctls(codec,
  449. spec->multiout.dig_out_nid,
  450. spec->multiout.dig_out_nid);
  451. if (err < 0)
  452. return err;
  453. err = snd_hda_create_spdif_share_sw(codec,
  454. &spec->multiout);
  455. if (err < 0)
  456. return err;
  457. spec->multiout.share_spdif = 1;
  458. }
  459. if (spec->dig_in_nid) {
  460. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  461. if (err < 0)
  462. return err;
  463. }
  464. /* if we have no master control, let's create it */
  465. if (spec->vmaster_nid &&
  466. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  467. unsigned int vmaster_tlv[4];
  468. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  469. HDA_OUTPUT, vmaster_tlv);
  470. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  471. vmaster_tlv, slave_vols);
  472. if (err < 0)
  473. return err;
  474. }
  475. if (spec->vmaster_nid &&
  476. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  477. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  478. NULL, slave_sws);
  479. if (err < 0)
  480. return err;
  481. }
  482. if (spec->input_mux) {
  483. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  484. if (err < 0)
  485. return err;
  486. }
  487. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  488. /* create beep controls if needed */
  489. if (spec->beep_amp) {
  490. const struct snd_kcontrol_new *knew;
  491. for (knew = cxt_beep_mixer; knew->name; knew++) {
  492. struct snd_kcontrol *kctl;
  493. kctl = snd_ctl_new1(knew, codec);
  494. if (!kctl)
  495. return -ENOMEM;
  496. kctl->private_value = spec->beep_amp;
  497. err = snd_hda_ctl_add(codec, 0, kctl);
  498. if (err < 0)
  499. return err;
  500. }
  501. }
  502. #endif
  503. return 0;
  504. }
  505. #ifdef CONFIG_SND_HDA_POWER_SAVE
  506. static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
  507. {
  508. snd_hda_shutup_pins(codec);
  509. return 0;
  510. }
  511. #endif
  512. static const struct hda_codec_ops conexant_patch_ops = {
  513. .build_controls = conexant_build_controls,
  514. .build_pcms = conexant_build_pcms,
  515. .init = conexant_init,
  516. .free = conexant_free,
  517. #ifdef CONFIG_SND_HDA_POWER_SAVE
  518. .suspend = conexant_suspend,
  519. #endif
  520. .reboot_notify = snd_hda_shutup_pins,
  521. };
  522. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  523. #define set_beep_amp(spec, nid, idx, dir) \
  524. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
  525. #else
  526. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  527. #endif
  528. static int patch_conexant_auto(struct hda_codec *codec);
  529. /*
  530. * EAPD control
  531. * the private value = nid | (invert << 8)
  532. */
  533. #define cxt_eapd_info snd_ctl_boolean_mono_info
  534. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  535. struct snd_ctl_elem_value *ucontrol)
  536. {
  537. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  538. struct conexant_spec *spec = codec->spec;
  539. int invert = (kcontrol->private_value >> 8) & 1;
  540. if (invert)
  541. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  542. else
  543. ucontrol->value.integer.value[0] = spec->cur_eapd;
  544. return 0;
  545. }
  546. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  547. struct snd_ctl_elem_value *ucontrol)
  548. {
  549. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  550. struct conexant_spec *spec = codec->spec;
  551. int invert = (kcontrol->private_value >> 8) & 1;
  552. hda_nid_t nid = kcontrol->private_value & 0xff;
  553. unsigned int eapd;
  554. eapd = !!ucontrol->value.integer.value[0];
  555. if (invert)
  556. eapd = !eapd;
  557. if (eapd == spec->cur_eapd)
  558. return 0;
  559. spec->cur_eapd = eapd;
  560. snd_hda_codec_write_cache(codec, nid,
  561. 0, AC_VERB_SET_EAPD_BTLENABLE,
  562. eapd ? 0x02 : 0x00);
  563. return 1;
  564. }
  565. /* controls for test mode */
  566. #ifdef CONFIG_SND_DEBUG
  567. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  568. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  569. .info = cxt_eapd_info, \
  570. .get = cxt_eapd_get, \
  571. .put = cxt_eapd_put, \
  572. .private_value = nid | (mask<<16) }
  573. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  574. struct snd_ctl_elem_info *uinfo)
  575. {
  576. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  577. struct conexant_spec *spec = codec->spec;
  578. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  579. spec->num_channel_mode);
  580. }
  581. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  582. struct snd_ctl_elem_value *ucontrol)
  583. {
  584. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  585. struct conexant_spec *spec = codec->spec;
  586. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  587. spec->num_channel_mode,
  588. spec->multiout.max_channels);
  589. }
  590. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  591. struct snd_ctl_elem_value *ucontrol)
  592. {
  593. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  594. struct conexant_spec *spec = codec->spec;
  595. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  596. spec->num_channel_mode,
  597. &spec->multiout.max_channels);
  598. if (err >= 0 && spec->need_dac_fix)
  599. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  600. return err;
  601. }
  602. #define CXT_PIN_MODE(xname, nid, dir) \
  603. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  604. .info = conexant_ch_mode_info, \
  605. .get = conexant_ch_mode_get, \
  606. .put = conexant_ch_mode_put, \
  607. .private_value = nid | (dir<<16) }
  608. #endif /* CONFIG_SND_DEBUG */
  609. /* Conexant 5045 specific */
  610. static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  611. static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  612. static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  613. #define CXT5045_SPDIF_OUT 0x18
  614. static const struct hda_channel_mode cxt5045_modes[1] = {
  615. { 2, NULL },
  616. };
  617. static const struct hda_input_mux cxt5045_capture_source = {
  618. .num_items = 2,
  619. .items = {
  620. { "IntMic", 0x1 },
  621. { "ExtMic", 0x2 },
  622. }
  623. };
  624. static const struct hda_input_mux cxt5045_capture_source_benq = {
  625. .num_items = 5,
  626. .items = {
  627. { "IntMic", 0x1 },
  628. { "ExtMic", 0x2 },
  629. { "LineIn", 0x3 },
  630. { "CD", 0x4 },
  631. { "Mixer", 0x0 },
  632. }
  633. };
  634. static const struct hda_input_mux cxt5045_capture_source_hp530 = {
  635. .num_items = 2,
  636. .items = {
  637. { "ExtMic", 0x1 },
  638. { "IntMic", 0x2 },
  639. }
  640. };
  641. /* turn on/off EAPD (+ mute HP) as a master switch */
  642. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  643. struct snd_ctl_elem_value *ucontrol)
  644. {
  645. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  646. struct conexant_spec *spec = codec->spec;
  647. unsigned int bits;
  648. if (!cxt_eapd_put(kcontrol, ucontrol))
  649. return 0;
  650. /* toggle internal speakers mute depending of presence of
  651. * the headphone jack
  652. */
  653. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  654. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  655. HDA_AMP_MUTE, bits);
  656. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  657. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  658. HDA_AMP_MUTE, bits);
  659. return 1;
  660. }
  661. /* bind volumes of both NID 0x10 and 0x11 */
  662. static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  663. .ops = &snd_hda_bind_vol,
  664. .values = {
  665. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  666. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  667. 0
  668. },
  669. };
  670. /* toggle input of built-in and mic jack appropriately */
  671. static void cxt5045_hp_automic(struct hda_codec *codec)
  672. {
  673. static const struct hda_verb mic_jack_on[] = {
  674. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  675. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  676. {}
  677. };
  678. static const struct hda_verb mic_jack_off[] = {
  679. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  680. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  681. {}
  682. };
  683. unsigned int present;
  684. present = snd_hda_jack_detect(codec, 0x12);
  685. if (present)
  686. snd_hda_sequence_write(codec, mic_jack_on);
  687. else
  688. snd_hda_sequence_write(codec, mic_jack_off);
  689. }
  690. /* mute internal speaker if HP is plugged */
  691. static void cxt5045_hp_automute(struct hda_codec *codec)
  692. {
  693. struct conexant_spec *spec = codec->spec;
  694. unsigned int bits;
  695. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  696. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  697. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  698. HDA_AMP_MUTE, bits);
  699. }
  700. /* unsolicited event for HP jack sensing */
  701. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  702. unsigned int res)
  703. {
  704. res >>= 26;
  705. switch (res) {
  706. case CONEXANT_HP_EVENT:
  707. cxt5045_hp_automute(codec);
  708. break;
  709. case CONEXANT_MIC_EVENT:
  710. cxt5045_hp_automic(codec);
  711. break;
  712. }
  713. }
  714. static const struct snd_kcontrol_new cxt5045_mixers[] = {
  715. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  716. HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  717. HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  718. HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  719. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  720. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  721. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  722. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  723. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  724. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  725. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  726. {
  727. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  728. .name = "Master Playback Switch",
  729. .info = cxt_eapd_info,
  730. .get = cxt_eapd_get,
  731. .put = cxt5045_hp_master_sw_put,
  732. .private_value = 0x10,
  733. },
  734. {}
  735. };
  736. static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  737. HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
  738. HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
  739. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
  740. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
  741. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  742. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  743. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  744. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  745. HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
  746. HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
  747. {}
  748. };
  749. static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  750. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  751. HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  752. HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  753. HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  754. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  755. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  756. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  757. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  758. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  759. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  760. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  761. {
  762. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  763. .name = "Master Playback Switch",
  764. .info = cxt_eapd_info,
  765. .get = cxt_eapd_get,
  766. .put = cxt5045_hp_master_sw_put,
  767. .private_value = 0x10,
  768. },
  769. {}
  770. };
  771. static const struct hda_verb cxt5045_init_verbs[] = {
  772. /* Line in, Mic */
  773. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  774. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  775. /* HP, Amp */
  776. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  777. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  778. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  779. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  780. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  781. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  782. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  783. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  784. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  785. /* Record selector: Internal mic */
  786. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  787. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  788. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  789. /* SPDIF route: PCM */
  790. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  791. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  792. /* EAPD */
  793. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  794. { } /* end */
  795. };
  796. static const struct hda_verb cxt5045_benq_init_verbs[] = {
  797. /* Internal Mic, Mic */
  798. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  799. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  800. /* Line In,HP, Amp */
  801. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  802. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  803. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  804. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  805. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  806. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  807. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  808. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  809. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  810. /* Record selector: Internal mic */
  811. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  812. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  813. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  814. /* SPDIF route: PCM */
  815. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  816. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  817. /* EAPD */
  818. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  819. { } /* end */
  820. };
  821. static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  822. /* pin sensing on HP jack */
  823. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  824. { } /* end */
  825. };
  826. static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  827. /* pin sensing on HP jack */
  828. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  829. { } /* end */
  830. };
  831. #ifdef CONFIG_SND_DEBUG
  832. /* Test configuration for debugging, modelled after the ALC260 test
  833. * configuration.
  834. */
  835. static const struct hda_input_mux cxt5045_test_capture_source = {
  836. .num_items = 5,
  837. .items = {
  838. { "MIXER", 0x0 },
  839. { "MIC1 pin", 0x1 },
  840. { "LINE1 pin", 0x2 },
  841. { "HP-OUT pin", 0x3 },
  842. { "CD pin", 0x4 },
  843. },
  844. };
  845. static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
  846. /* Output controls */
  847. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  848. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  849. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  850. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  851. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  852. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  853. /* Modes for retasking pin widgets */
  854. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  855. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  856. /* EAPD Switch Control */
  857. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  858. /* Loopback mixer controls */
  859. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  860. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  861. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  862. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  863. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  864. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  865. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  866. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  867. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  868. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  869. {
  870. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  871. .name = "Input Source",
  872. .info = conexant_mux_enum_info,
  873. .get = conexant_mux_enum_get,
  874. .put = conexant_mux_enum_put,
  875. },
  876. /* Audio input controls */
  877. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  878. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  879. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  880. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  881. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  882. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  883. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  884. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  885. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  886. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  887. { } /* end */
  888. };
  889. static const struct hda_verb cxt5045_test_init_verbs[] = {
  890. /* Set connections */
  891. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  892. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  893. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  894. /* Enable retasking pins as output, initially without power amp */
  895. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  896. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  897. /* Disable digital (SPDIF) pins initially, but users can enable
  898. * them via a mixer switch. In the case of SPDIF-out, this initverb
  899. * payload also sets the generation to 0, output to be in "consumer"
  900. * PCM format, copyright asserted, no pre-emphasis and no validity
  901. * control.
  902. */
  903. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  904. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  905. /* Start with output sum widgets muted and their output gains at min */
  906. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  907. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  908. /* Unmute retasking pin widget output buffers since the default
  909. * state appears to be output. As the pin mode is changed by the
  910. * user the pin mode control will take care of enabling the pin's
  911. * input/output buffers as needed.
  912. */
  913. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  914. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  915. /* Mute capture amp left and right */
  916. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  917. /* Set ADC connection select to match default mixer setting (mic1
  918. * pin)
  919. */
  920. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  921. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  922. /* Mute all inputs to mixer widget (even unconnected ones) */
  923. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  924. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  925. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  926. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  927. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  928. { }
  929. };
  930. #endif
  931. /* initialize jack-sensing, too */
  932. static int cxt5045_init(struct hda_codec *codec)
  933. {
  934. conexant_init(codec);
  935. cxt5045_hp_automute(codec);
  936. return 0;
  937. }
  938. enum {
  939. CXT5045_LAPTOP_HPSENSE,
  940. CXT5045_LAPTOP_MICSENSE,
  941. CXT5045_LAPTOP_HPMICSENSE,
  942. CXT5045_BENQ,
  943. CXT5045_LAPTOP_HP530,
  944. #ifdef CONFIG_SND_DEBUG
  945. CXT5045_TEST,
  946. #endif
  947. CXT5045_AUTO,
  948. CXT5045_MODELS
  949. };
  950. static const char * const cxt5045_models[CXT5045_MODELS] = {
  951. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  952. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  953. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  954. [CXT5045_BENQ] = "benq",
  955. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  956. #ifdef CONFIG_SND_DEBUG
  957. [CXT5045_TEST] = "test",
  958. #endif
  959. [CXT5045_AUTO] = "auto",
  960. };
  961. static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  962. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  963. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  964. CXT5045_LAPTOP_HPSENSE),
  965. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  966. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  967. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  968. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  969. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  970. CXT5045_LAPTOP_HPMICSENSE),
  971. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  972. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  973. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  974. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  975. CXT5045_LAPTOP_HPMICSENSE),
  976. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  977. {}
  978. };
  979. static int patch_cxt5045(struct hda_codec *codec)
  980. {
  981. struct conexant_spec *spec;
  982. int board_config;
  983. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  984. cxt5045_models,
  985. cxt5045_cfg_tbl);
  986. if (board_config < 0)
  987. board_config = CXT5045_AUTO; /* model=auto as default */
  988. if (board_config == CXT5045_AUTO)
  989. return patch_conexant_auto(codec);
  990. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  991. if (!spec)
  992. return -ENOMEM;
  993. codec->spec = spec;
  994. codec->pin_amp_workaround = 1;
  995. spec->multiout.max_channels = 2;
  996. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  997. spec->multiout.dac_nids = cxt5045_dac_nids;
  998. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  999. spec->num_adc_nids = 1;
  1000. spec->adc_nids = cxt5045_adc_nids;
  1001. spec->capsrc_nids = cxt5045_capsrc_nids;
  1002. spec->input_mux = &cxt5045_capture_source;
  1003. spec->num_mixers = 1;
  1004. spec->mixers[0] = cxt5045_mixers;
  1005. spec->num_init_verbs = 1;
  1006. spec->init_verbs[0] = cxt5045_init_verbs;
  1007. spec->spdif_route = 0;
  1008. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
  1009. spec->channel_mode = cxt5045_modes;
  1010. set_beep_amp(spec, 0x16, 0, 1);
  1011. codec->patch_ops = conexant_patch_ops;
  1012. switch (board_config) {
  1013. case CXT5045_LAPTOP_HPSENSE:
  1014. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1015. spec->input_mux = &cxt5045_capture_source;
  1016. spec->num_init_verbs = 2;
  1017. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1018. spec->mixers[0] = cxt5045_mixers;
  1019. codec->patch_ops.init = cxt5045_init;
  1020. break;
  1021. case CXT5045_LAPTOP_MICSENSE:
  1022. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1023. spec->input_mux = &cxt5045_capture_source;
  1024. spec->num_init_verbs = 2;
  1025. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  1026. spec->mixers[0] = cxt5045_mixers;
  1027. codec->patch_ops.init = cxt5045_init;
  1028. break;
  1029. default:
  1030. case CXT5045_LAPTOP_HPMICSENSE:
  1031. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1032. spec->input_mux = &cxt5045_capture_source;
  1033. spec->num_init_verbs = 3;
  1034. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1035. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  1036. spec->mixers[0] = cxt5045_mixers;
  1037. codec->patch_ops.init = cxt5045_init;
  1038. break;
  1039. case CXT5045_BENQ:
  1040. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1041. spec->input_mux = &cxt5045_capture_source_benq;
  1042. spec->num_init_verbs = 1;
  1043. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  1044. spec->mixers[0] = cxt5045_mixers;
  1045. spec->mixers[1] = cxt5045_benq_mixers;
  1046. spec->num_mixers = 2;
  1047. codec->patch_ops.init = cxt5045_init;
  1048. break;
  1049. case CXT5045_LAPTOP_HP530:
  1050. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1051. spec->input_mux = &cxt5045_capture_source_hp530;
  1052. spec->num_init_verbs = 2;
  1053. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1054. spec->mixers[0] = cxt5045_mixers_hp530;
  1055. codec->patch_ops.init = cxt5045_init;
  1056. break;
  1057. #ifdef CONFIG_SND_DEBUG
  1058. case CXT5045_TEST:
  1059. spec->input_mux = &cxt5045_test_capture_source;
  1060. spec->mixers[0] = cxt5045_test_mixer;
  1061. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1062. break;
  1063. #endif
  1064. }
  1065. switch (codec->subsystem_id >> 16) {
  1066. case 0x103c:
  1067. case 0x1631:
  1068. case 0x1734:
  1069. case 0x17aa:
  1070. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  1071. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  1072. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  1073. */
  1074. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1075. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1076. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1077. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1078. (1 << AC_AMPCAP_MUTE_SHIFT));
  1079. break;
  1080. }
  1081. if (spec->beep_amp)
  1082. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1083. return 0;
  1084. }
  1085. /* Conexant 5047 specific */
  1086. #define CXT5047_SPDIF_OUT 0x11
  1087. static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1088. static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1089. static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1090. static const struct hda_channel_mode cxt5047_modes[1] = {
  1091. { 2, NULL },
  1092. };
  1093. static const struct hda_input_mux cxt5047_toshiba_capture_source = {
  1094. .num_items = 2,
  1095. .items = {
  1096. { "ExtMic", 0x2 },
  1097. { "Line-In", 0x1 },
  1098. }
  1099. };
  1100. /* turn on/off EAPD (+ mute HP) as a master switch */
  1101. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1102. struct snd_ctl_elem_value *ucontrol)
  1103. {
  1104. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1105. struct conexant_spec *spec = codec->spec;
  1106. unsigned int bits;
  1107. if (!cxt_eapd_put(kcontrol, ucontrol))
  1108. return 0;
  1109. /* toggle internal speakers mute depending of presence of
  1110. * the headphone jack
  1111. */
  1112. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1113. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1114. * pin widgets unlike other codecs. In this case, we need to
  1115. * set index 0x01 for the volume from the mixer amp 0x19.
  1116. */
  1117. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1118. HDA_AMP_MUTE, bits);
  1119. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1120. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1121. HDA_AMP_MUTE, bits);
  1122. return 1;
  1123. }
  1124. /* mute internal speaker if HP is plugged */
  1125. static void cxt5047_hp_automute(struct hda_codec *codec)
  1126. {
  1127. struct conexant_spec *spec = codec->spec;
  1128. unsigned int bits;
  1129. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1130. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1131. /* See the note in cxt5047_hp_master_sw_put */
  1132. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1133. HDA_AMP_MUTE, bits);
  1134. }
  1135. /* toggle input of built-in and mic jack appropriately */
  1136. static void cxt5047_hp_automic(struct hda_codec *codec)
  1137. {
  1138. static const struct hda_verb mic_jack_on[] = {
  1139. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1140. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1141. {}
  1142. };
  1143. static const struct hda_verb mic_jack_off[] = {
  1144. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1145. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1146. {}
  1147. };
  1148. unsigned int present;
  1149. present = snd_hda_jack_detect(codec, 0x15);
  1150. if (present)
  1151. snd_hda_sequence_write(codec, mic_jack_on);
  1152. else
  1153. snd_hda_sequence_write(codec, mic_jack_off);
  1154. }
  1155. /* unsolicited event for HP jack sensing */
  1156. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1157. unsigned int res)
  1158. {
  1159. switch (res >> 26) {
  1160. case CONEXANT_HP_EVENT:
  1161. cxt5047_hp_automute(codec);
  1162. break;
  1163. case CONEXANT_MIC_EVENT:
  1164. cxt5047_hp_automic(codec);
  1165. break;
  1166. }
  1167. }
  1168. static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1169. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1170. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1171. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1172. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1173. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1174. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1175. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1176. {
  1177. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1178. .name = "Master Playback Switch",
  1179. .info = cxt_eapd_info,
  1180. .get = cxt_eapd_get,
  1181. .put = cxt5047_hp_master_sw_put,
  1182. .private_value = 0x13,
  1183. },
  1184. {}
  1185. };
  1186. static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1187. /* See the note in cxt5047_hp_master_sw_put */
  1188. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1189. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1190. {}
  1191. };
  1192. static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1193. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1194. { } /* end */
  1195. };
  1196. static const struct hda_verb cxt5047_init_verbs[] = {
  1197. /* Line in, Mic, Built-in Mic */
  1198. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1199. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1200. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1201. /* HP, Speaker */
  1202. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1203. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1204. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1205. /* Record selector: Mic */
  1206. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1207. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1208. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1209. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1210. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1211. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1212. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1213. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1214. /* SPDIF route: PCM */
  1215. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1216. /* Enable unsolicited events */
  1217. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1218. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1219. { } /* end */
  1220. };
  1221. /* configuration for Toshiba Laptops */
  1222. static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1223. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1224. {}
  1225. };
  1226. /* Test configuration for debugging, modelled after the ALC260 test
  1227. * configuration.
  1228. */
  1229. #ifdef CONFIG_SND_DEBUG
  1230. static const struct hda_input_mux cxt5047_test_capture_source = {
  1231. .num_items = 4,
  1232. .items = {
  1233. { "LINE1 pin", 0x0 },
  1234. { "MIC1 pin", 0x1 },
  1235. { "MIC2 pin", 0x2 },
  1236. { "CD pin", 0x3 },
  1237. },
  1238. };
  1239. static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1240. /* Output only controls */
  1241. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1242. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1243. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1244. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1245. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1246. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1247. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1248. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1249. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1250. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1251. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1252. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1253. /* Modes for retasking pin widgets */
  1254. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1255. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1256. /* EAPD Switch Control */
  1257. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1258. /* Loopback mixer controls */
  1259. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1260. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1261. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1262. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1263. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1264. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1265. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1266. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1267. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1268. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1269. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1270. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1271. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1272. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1273. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1274. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1275. {
  1276. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1277. .name = "Input Source",
  1278. .info = conexant_mux_enum_info,
  1279. .get = conexant_mux_enum_get,
  1280. .put = conexant_mux_enum_put,
  1281. },
  1282. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1283. { } /* end */
  1284. };
  1285. static const struct hda_verb cxt5047_test_init_verbs[] = {
  1286. /* Enable retasking pins as output, initially without power amp */
  1287. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1288. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1289. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1290. /* Disable digital (SPDIF) pins initially, but users can enable
  1291. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1292. * payload also sets the generation to 0, output to be in "consumer"
  1293. * PCM format, copyright asserted, no pre-emphasis and no validity
  1294. * control.
  1295. */
  1296. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1297. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1298. * OUT1 sum bus when acting as an output.
  1299. */
  1300. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1301. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1302. /* Start with output sum widgets muted and their output gains at min */
  1303. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1304. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1305. /* Unmute retasking pin widget output buffers since the default
  1306. * state appears to be output. As the pin mode is changed by the
  1307. * user the pin mode control will take care of enabling the pin's
  1308. * input/output buffers as needed.
  1309. */
  1310. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1311. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1312. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1313. /* Mute capture amp left and right */
  1314. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1315. /* Set ADC connection select to match default mixer setting (mic1
  1316. * pin)
  1317. */
  1318. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1319. /* Mute all inputs to mixer widget (even unconnected ones) */
  1320. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1321. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1322. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1323. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1324. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1325. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1326. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1327. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1328. { }
  1329. };
  1330. #endif
  1331. /* initialize jack-sensing, too */
  1332. static int cxt5047_hp_init(struct hda_codec *codec)
  1333. {
  1334. conexant_init(codec);
  1335. cxt5047_hp_automute(codec);
  1336. return 0;
  1337. }
  1338. enum {
  1339. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1340. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1341. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1342. #ifdef CONFIG_SND_DEBUG
  1343. CXT5047_TEST,
  1344. #endif
  1345. CXT5047_AUTO,
  1346. CXT5047_MODELS
  1347. };
  1348. static const char * const cxt5047_models[CXT5047_MODELS] = {
  1349. [CXT5047_LAPTOP] = "laptop",
  1350. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1351. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1352. #ifdef CONFIG_SND_DEBUG
  1353. [CXT5047_TEST] = "test",
  1354. #endif
  1355. [CXT5047_AUTO] = "auto",
  1356. };
  1357. static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1358. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1359. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1360. CXT5047_LAPTOP),
  1361. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1362. {}
  1363. };
  1364. static int patch_cxt5047(struct hda_codec *codec)
  1365. {
  1366. struct conexant_spec *spec;
  1367. int board_config;
  1368. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1369. cxt5047_models,
  1370. cxt5047_cfg_tbl);
  1371. if (board_config < 0)
  1372. board_config = CXT5047_AUTO; /* model=auto as default */
  1373. if (board_config == CXT5047_AUTO)
  1374. return patch_conexant_auto(codec);
  1375. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1376. if (!spec)
  1377. return -ENOMEM;
  1378. codec->spec = spec;
  1379. codec->pin_amp_workaround = 1;
  1380. spec->multiout.max_channels = 2;
  1381. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1382. spec->multiout.dac_nids = cxt5047_dac_nids;
  1383. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1384. spec->num_adc_nids = 1;
  1385. spec->adc_nids = cxt5047_adc_nids;
  1386. spec->capsrc_nids = cxt5047_capsrc_nids;
  1387. spec->num_mixers = 1;
  1388. spec->mixers[0] = cxt5047_base_mixers;
  1389. spec->num_init_verbs = 1;
  1390. spec->init_verbs[0] = cxt5047_init_verbs;
  1391. spec->spdif_route = 0;
  1392. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1393. spec->channel_mode = cxt5047_modes,
  1394. codec->patch_ops = conexant_patch_ops;
  1395. switch (board_config) {
  1396. case CXT5047_LAPTOP:
  1397. spec->num_mixers = 2;
  1398. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1399. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1400. break;
  1401. case CXT5047_LAPTOP_HP:
  1402. spec->num_mixers = 2;
  1403. spec->mixers[1] = cxt5047_hp_only_mixers;
  1404. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1405. codec->patch_ops.init = cxt5047_hp_init;
  1406. break;
  1407. case CXT5047_LAPTOP_EAPD:
  1408. spec->input_mux = &cxt5047_toshiba_capture_source;
  1409. spec->num_mixers = 2;
  1410. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1411. spec->num_init_verbs = 2;
  1412. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1413. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1414. break;
  1415. #ifdef CONFIG_SND_DEBUG
  1416. case CXT5047_TEST:
  1417. spec->input_mux = &cxt5047_test_capture_source;
  1418. spec->mixers[0] = cxt5047_test_mixer;
  1419. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1420. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1421. #endif
  1422. }
  1423. spec->vmaster_nid = 0x13;
  1424. switch (codec->subsystem_id >> 16) {
  1425. case 0x103c:
  1426. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1427. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1428. * with 0 dB offset 0x17)
  1429. */
  1430. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1431. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1432. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1433. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1434. (1 << AC_AMPCAP_MUTE_SHIFT));
  1435. break;
  1436. }
  1437. return 0;
  1438. }
  1439. /* Conexant 5051 specific */
  1440. static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1441. static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1442. static const struct hda_channel_mode cxt5051_modes[1] = {
  1443. { 2, NULL },
  1444. };
  1445. static void cxt5051_update_speaker(struct hda_codec *codec)
  1446. {
  1447. struct conexant_spec *spec = codec->spec;
  1448. unsigned int pinctl;
  1449. /* headphone pin */
  1450. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1451. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1452. pinctl);
  1453. /* speaker pin */
  1454. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1455. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1456. pinctl);
  1457. /* on ideapad there is an aditional speaker (subwoofer) to mute */
  1458. if (spec->ideapad)
  1459. snd_hda_codec_write(codec, 0x1b, 0,
  1460. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1461. pinctl);
  1462. }
  1463. /* turn on/off EAPD (+ mute HP) as a master switch */
  1464. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1465. struct snd_ctl_elem_value *ucontrol)
  1466. {
  1467. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1468. if (!cxt_eapd_put(kcontrol, ucontrol))
  1469. return 0;
  1470. cxt5051_update_speaker(codec);
  1471. return 1;
  1472. }
  1473. /* toggle input of built-in and mic jack appropriately */
  1474. static void cxt5051_portb_automic(struct hda_codec *codec)
  1475. {
  1476. struct conexant_spec *spec = codec->spec;
  1477. unsigned int present;
  1478. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1479. return;
  1480. present = snd_hda_jack_detect(codec, 0x17);
  1481. snd_hda_codec_write(codec, 0x14, 0,
  1482. AC_VERB_SET_CONNECT_SEL,
  1483. present ? 0x01 : 0x00);
  1484. }
  1485. /* switch the current ADC according to the jack state */
  1486. static void cxt5051_portc_automic(struct hda_codec *codec)
  1487. {
  1488. struct conexant_spec *spec = codec->spec;
  1489. unsigned int present;
  1490. hda_nid_t new_adc;
  1491. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1492. return;
  1493. present = snd_hda_jack_detect(codec, 0x18);
  1494. if (present)
  1495. spec->cur_adc_idx = 1;
  1496. else
  1497. spec->cur_adc_idx = 0;
  1498. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1499. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1500. /* stream is running, let's swap the current ADC */
  1501. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1502. spec->cur_adc = new_adc;
  1503. snd_hda_codec_setup_stream(codec, new_adc,
  1504. spec->cur_adc_stream_tag, 0,
  1505. spec->cur_adc_format);
  1506. }
  1507. }
  1508. /* mute internal speaker if HP is plugged */
  1509. static void cxt5051_hp_automute(struct hda_codec *codec)
  1510. {
  1511. struct conexant_spec *spec = codec->spec;
  1512. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1513. cxt5051_update_speaker(codec);
  1514. }
  1515. /* unsolicited event for HP jack sensing */
  1516. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1517. unsigned int res)
  1518. {
  1519. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1520. switch (res >> 26) {
  1521. case CONEXANT_HP_EVENT:
  1522. cxt5051_hp_automute(codec);
  1523. break;
  1524. case CXT5051_PORTB_EVENT:
  1525. cxt5051_portb_automic(codec);
  1526. break;
  1527. case CXT5051_PORTC_EVENT:
  1528. cxt5051_portc_automic(codec);
  1529. break;
  1530. }
  1531. snd_hda_input_jack_report(codec, nid);
  1532. }
  1533. static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1534. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1535. {
  1536. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1537. .name = "Master Playback Switch",
  1538. .info = cxt_eapd_info,
  1539. .get = cxt_eapd_get,
  1540. .put = cxt5051_hp_master_sw_put,
  1541. .private_value = 0x1a,
  1542. },
  1543. {}
  1544. };
  1545. static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1546. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1547. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1548. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1549. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1550. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1551. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1552. {}
  1553. };
  1554. static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1555. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1556. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1557. HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
  1558. HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
  1559. {}
  1560. };
  1561. static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1562. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1563. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1564. {}
  1565. };
  1566. static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1567. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1568. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1569. {}
  1570. };
  1571. static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1572. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1573. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1574. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1575. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1576. {}
  1577. };
  1578. static const struct hda_verb cxt5051_init_verbs[] = {
  1579. /* Line in, Mic */
  1580. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1581. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1582. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1583. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1584. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1585. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1586. /* SPK */
  1587. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1588. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1589. /* HP, Amp */
  1590. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1591. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1592. /* DAC1 */
  1593. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1594. /* Record selector: Internal mic */
  1595. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1596. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1597. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1598. /* SPDIF route: PCM */
  1599. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1600. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1601. /* EAPD */
  1602. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1603. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1604. { } /* end */
  1605. };
  1606. static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1607. /* Line in, Mic */
  1608. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1609. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1610. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1611. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1612. /* SPK */
  1613. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1614. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1615. /* HP, Amp */
  1616. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1617. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1618. /* DAC1 */
  1619. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1620. /* Record selector: Internal mic */
  1621. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1622. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1623. /* SPDIF route: PCM */
  1624. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1625. /* EAPD */
  1626. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1627. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1628. { } /* end */
  1629. };
  1630. static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
  1631. /* Line in, Mic */
  1632. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1633. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1634. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1635. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1636. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1637. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1638. /* SPK */
  1639. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1640. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1641. /* HP, Amp */
  1642. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1643. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1644. /* Docking HP */
  1645. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1646. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
  1647. /* DAC1 */
  1648. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1649. /* Record selector: Internal mic */
  1650. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1651. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1652. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1653. /* SPDIF route: PCM */
  1654. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
  1655. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1656. /* EAPD */
  1657. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1658. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1659. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1660. { } /* end */
  1661. };
  1662. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1663. /* Line in, Mic */
  1664. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1665. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1666. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1667. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1668. /* SPK */
  1669. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1670. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1671. /* HP, Amp */
  1672. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1673. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1674. /* DAC1 */
  1675. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1676. /* Record selector: Internal mic */
  1677. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1678. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1679. /* SPDIF route: PCM */
  1680. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1681. /* EAPD */
  1682. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1683. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1684. { } /* end */
  1685. };
  1686. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1687. unsigned int event)
  1688. {
  1689. snd_hda_codec_write(codec, nid, 0,
  1690. AC_VERB_SET_UNSOLICITED_ENABLE,
  1691. AC_USRSP_EN | event);
  1692. snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
  1693. snd_hda_input_jack_report(codec, nid);
  1694. }
  1695. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1696. /* Subwoofer */
  1697. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1698. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1699. { } /* end */
  1700. };
  1701. /* initialize jack-sensing, too */
  1702. static int cxt5051_init(struct hda_codec *codec)
  1703. {
  1704. struct conexant_spec *spec = codec->spec;
  1705. conexant_init(codec);
  1706. conexant_init_jacks(codec);
  1707. if (spec->auto_mic & AUTO_MIC_PORTB)
  1708. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1709. if (spec->auto_mic & AUTO_MIC_PORTC)
  1710. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1711. if (codec->patch_ops.unsol_event) {
  1712. cxt5051_hp_automute(codec);
  1713. cxt5051_portb_automic(codec);
  1714. cxt5051_portc_automic(codec);
  1715. }
  1716. return 0;
  1717. }
  1718. enum {
  1719. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1720. CXT5051_HP, /* no docking */
  1721. CXT5051_HP_DV6736, /* HP without mic switch */
  1722. CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
  1723. CXT5051_F700, /* HP Compaq Presario F700 */
  1724. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1725. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1726. CXT5051_AUTO, /* auto-parser */
  1727. CXT5051_MODELS
  1728. };
  1729. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1730. [CXT5051_LAPTOP] = "laptop",
  1731. [CXT5051_HP] = "hp",
  1732. [CXT5051_HP_DV6736] = "hp-dv6736",
  1733. [CXT5051_LENOVO_X200] = "lenovo-x200",
  1734. [CXT5051_F700] = "hp-700",
  1735. [CXT5051_TOSHIBA] = "toshiba",
  1736. [CXT5051_IDEAPAD] = "ideapad",
  1737. [CXT5051_AUTO] = "auto",
  1738. };
  1739. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1740. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1741. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1742. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1743. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1744. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1745. CXT5051_LAPTOP),
  1746. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1747. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
  1748. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1749. {}
  1750. };
  1751. static int patch_cxt5051(struct hda_codec *codec)
  1752. {
  1753. struct conexant_spec *spec;
  1754. int board_config;
  1755. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1756. cxt5051_models,
  1757. cxt5051_cfg_tbl);
  1758. if (board_config < 0)
  1759. board_config = CXT5051_AUTO; /* model=auto as default */
  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(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
  2663. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2664. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2665. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2666. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2667. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2668. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2669. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2670. SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
  2671. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2672. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2673. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2674. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2675. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2676. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2677. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", CXT5066_OLPC_XO_1_5),
  2678. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  2679. CXT5066_LAPTOP),
  2680. SND_PCI_QUIRK(0x152d, 0x0833, "OLPC XO-1.5", CXT5066_OLPC_XO_1_5),
  2681. SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo T400s", CXT5066_THINKPAD),
  2682. SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
  2683. SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
  2684. SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
  2685. SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
  2686. SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
  2687. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
  2688. SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo G560", CXT5066_ASUS),
  2689. SND_PCI_QUIRK(0x17aa, 0x3938, "Lenovo G565", CXT5066_AUTO),
  2690. SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", CXT5066_IDEAPAD), /* Fallback for Lenovos without dock mic */
  2691. SND_PCI_QUIRK(0x1b0a, 0x2092, "CyberpowerPC Gamer Xplorer N57001", CXT5066_AUTO),
  2692. {}
  2693. };
  2694. static int patch_cxt5066(struct hda_codec *codec)
  2695. {
  2696. struct conexant_spec *spec;
  2697. int board_config;
  2698. board_config = snd_hda_check_board_config(codec, CXT5066_MODELS,
  2699. cxt5066_models, cxt5066_cfg_tbl);
  2700. if (board_config < 0)
  2701. board_config = CXT5066_AUTO; /* model=auto as default */
  2702. if (board_config == CXT5066_AUTO)
  2703. return patch_conexant_auto(codec);
  2704. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2705. if (!spec)
  2706. return -ENOMEM;
  2707. codec->spec = spec;
  2708. codec->patch_ops = conexant_patch_ops;
  2709. codec->patch_ops.init = conexant_init;
  2710. spec->dell_automute = 0;
  2711. spec->multiout.max_channels = 2;
  2712. spec->multiout.num_dacs = ARRAY_SIZE(cxt5066_dac_nids);
  2713. spec->multiout.dac_nids = cxt5066_dac_nids;
  2714. conexant_check_dig_outs(codec, cxt5066_digout_pin_nids,
  2715. ARRAY_SIZE(cxt5066_digout_pin_nids));
  2716. spec->num_adc_nids = 1;
  2717. spec->adc_nids = cxt5066_adc_nids;
  2718. spec->capsrc_nids = cxt5066_capsrc_nids;
  2719. spec->input_mux = &cxt5066_capture_source;
  2720. spec->port_d_mode = PIN_HP;
  2721. spec->num_init_verbs = 1;
  2722. spec->init_verbs[0] = cxt5066_init_verbs;
  2723. spec->num_channel_mode = ARRAY_SIZE(cxt5066_modes);
  2724. spec->channel_mode = cxt5066_modes;
  2725. spec->cur_adc = 0;
  2726. spec->cur_adc_idx = 0;
  2727. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  2728. switch (board_config) {
  2729. default:
  2730. case CXT5066_LAPTOP:
  2731. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2732. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2733. break;
  2734. case CXT5066_DELL_LAPTOP:
  2735. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2736. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2737. spec->port_d_mode = PIN_OUT;
  2738. spec->init_verbs[spec->num_init_verbs] = cxt5066_init_verbs_portd_lo;
  2739. spec->num_init_verbs++;
  2740. spec->dell_automute = 1;
  2741. break;
  2742. case CXT5066_ASUS:
  2743. case CXT5066_HP_LAPTOP:
  2744. codec->patch_ops.init = cxt5066_init;
  2745. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2746. spec->init_verbs[spec->num_init_verbs] =
  2747. cxt5066_init_verbs_hp_laptop;
  2748. spec->num_init_verbs++;
  2749. spec->hp_laptop = board_config == CXT5066_HP_LAPTOP;
  2750. spec->asus = board_config == CXT5066_ASUS;
  2751. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2752. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2753. /* no S/PDIF out */
  2754. if (board_config == CXT5066_HP_LAPTOP)
  2755. spec->multiout.dig_out_nid = 0;
  2756. /* input source automatically selected */
  2757. spec->input_mux = NULL;
  2758. spec->port_d_mode = 0;
  2759. spec->mic_boost = 3; /* default 30dB gain */
  2760. break;
  2761. case CXT5066_OLPC_XO_1_5:
  2762. codec->patch_ops.init = cxt5066_olpc_init;
  2763. codec->patch_ops.unsol_event = cxt5066_olpc_unsol_event;
  2764. spec->init_verbs[0] = cxt5066_init_verbs_olpc;
  2765. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2766. spec->mixers[spec->num_mixers++] = cxt5066_mixer_olpc_dc;
  2767. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2768. spec->port_d_mode = 0;
  2769. spec->mic_boost = 3; /* default 30dB gain */
  2770. /* no S/PDIF out */
  2771. spec->multiout.dig_out_nid = 0;
  2772. /* input source automatically selected */
  2773. spec->input_mux = NULL;
  2774. /* our capture hooks which allow us to turn on the microphone LED
  2775. * at the right time */
  2776. spec->capture_prepare = cxt5066_olpc_capture_prepare;
  2777. spec->capture_cleanup = cxt5066_olpc_capture_cleanup;
  2778. break;
  2779. case CXT5066_DELL_VOSTRO:
  2780. codec->patch_ops.init = cxt5066_init;
  2781. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2782. spec->init_verbs[0] = cxt5066_init_verbs_vostro;
  2783. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master_olpc;
  2784. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2785. spec->mixers[spec->num_mixers++] = cxt5066_vostro_mixers;
  2786. spec->port_d_mode = 0;
  2787. spec->dell_vostro = 1;
  2788. spec->mic_boost = 3; /* default 30dB gain */
  2789. /* no S/PDIF out */
  2790. spec->multiout.dig_out_nid = 0;
  2791. /* input source automatically selected */
  2792. spec->input_mux = NULL;
  2793. break;
  2794. case CXT5066_IDEAPAD:
  2795. codec->patch_ops.init = cxt5066_init;
  2796. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2797. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2798. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2799. spec->init_verbs[0] = cxt5066_init_verbs_ideapad;
  2800. spec->port_d_mode = 0;
  2801. spec->ideapad = 1;
  2802. spec->mic_boost = 2; /* default 20dB gain */
  2803. /* no S/PDIF out */
  2804. spec->multiout.dig_out_nid = 0;
  2805. /* input source automatically selected */
  2806. spec->input_mux = NULL;
  2807. break;
  2808. case CXT5066_THINKPAD:
  2809. codec->patch_ops.init = cxt5066_init;
  2810. codec->patch_ops.unsol_event = cxt5066_unsol_event;
  2811. spec->mixers[spec->num_mixers++] = cxt5066_mixer_master;
  2812. spec->mixers[spec->num_mixers++] = cxt5066_mixers;
  2813. spec->init_verbs[0] = cxt5066_init_verbs_thinkpad;
  2814. spec->thinkpad = 1;
  2815. spec->port_d_mode = PIN_OUT;
  2816. spec->mic_boost = 2; /* default 20dB gain */
  2817. /* no S/PDIF out */
  2818. spec->multiout.dig_out_nid = 0;
  2819. /* input source automatically selected */
  2820. spec->input_mux = NULL;
  2821. break;
  2822. }
  2823. if (spec->beep_amp)
  2824. snd_hda_attach_beep_device(codec, spec->beep_amp);
  2825. return 0;
  2826. }
  2827. /*
  2828. * Automatic parser for CX20641 & co
  2829. */
  2830. static int cx_auto_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  2831. struct hda_codec *codec,
  2832. unsigned int stream_tag,
  2833. unsigned int format,
  2834. struct snd_pcm_substream *substream)
  2835. {
  2836. struct conexant_spec *spec = codec->spec;
  2837. hda_nid_t adc = spec->imux_info[spec->cur_mux[0]].adc;
  2838. if (spec->adc_switching) {
  2839. spec->cur_adc = adc;
  2840. spec->cur_adc_stream_tag = stream_tag;
  2841. spec->cur_adc_format = format;
  2842. }
  2843. snd_hda_codec_setup_stream(codec, adc, stream_tag, 0, format);
  2844. return 0;
  2845. }
  2846. static int cx_auto_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2847. struct hda_codec *codec,
  2848. struct snd_pcm_substream *substream)
  2849. {
  2850. struct conexant_spec *spec = codec->spec;
  2851. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  2852. spec->cur_adc = 0;
  2853. return 0;
  2854. }
  2855. static const struct hda_pcm_stream cx_auto_pcm_analog_capture = {
  2856. .substreams = 1,
  2857. .channels_min = 2,
  2858. .channels_max = 2,
  2859. .nid = 0, /* fill later */
  2860. .ops = {
  2861. .prepare = cx_auto_capture_pcm_prepare,
  2862. .cleanup = cx_auto_capture_pcm_cleanup
  2863. },
  2864. };
  2865. static const hda_nid_t cx_auto_adc_nids[] = { 0x14 };
  2866. #define get_connection_index(codec, mux, nid)\
  2867. snd_hda_get_conn_index(codec, mux, nid, 0)
  2868. /* get an unassigned DAC from the given list.
  2869. * Return the nid if found and reduce the DAC list, or return zero if
  2870. * not found
  2871. */
  2872. static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
  2873. hda_nid_t *dacs, int *num_dacs)
  2874. {
  2875. int i, nums = *num_dacs;
  2876. hda_nid_t ret = 0;
  2877. for (i = 0; i < nums; i++) {
  2878. if (get_connection_index(codec, pin, dacs[i]) >= 0) {
  2879. ret = dacs[i];
  2880. break;
  2881. }
  2882. }
  2883. if (!ret)
  2884. return 0;
  2885. if (--nums > 0)
  2886. memmove(dacs, dacs + 1, nums * sizeof(hda_nid_t));
  2887. *num_dacs = nums;
  2888. return ret;
  2889. }
  2890. #define MAX_AUTO_DACS 5
  2891. /* fill analog DAC list from the widget tree */
  2892. static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
  2893. {
  2894. hda_nid_t nid, end_nid;
  2895. int nums = 0;
  2896. end_nid = codec->start_nid + codec->num_nodes;
  2897. for (nid = codec->start_nid; nid < end_nid; nid++) {
  2898. unsigned int wcaps = get_wcaps(codec, nid);
  2899. unsigned int type = get_wcaps_type(wcaps);
  2900. if (type == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL)) {
  2901. dacs[nums++] = nid;
  2902. if (nums >= MAX_AUTO_DACS)
  2903. break;
  2904. }
  2905. }
  2906. return nums;
  2907. }
  2908. /* fill pin_dac_pair list from the pin and dac list */
  2909. static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
  2910. int num_pins, hda_nid_t *dacs, int *rest,
  2911. struct pin_dac_pair *filled, int type)
  2912. {
  2913. int i, nums;
  2914. nums = 0;
  2915. for (i = 0; i < num_pins; i++) {
  2916. filled[nums].pin = pins[i];
  2917. filled[nums].type = type;
  2918. filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
  2919. nums++;
  2920. }
  2921. return nums;
  2922. }
  2923. /* parse analog output paths */
  2924. static void cx_auto_parse_output(struct hda_codec *codec)
  2925. {
  2926. struct conexant_spec *spec = codec->spec;
  2927. struct auto_pin_cfg *cfg = &spec->autocfg;
  2928. hda_nid_t dacs[MAX_AUTO_DACS];
  2929. int i, j, nums, rest;
  2930. rest = fill_cx_auto_dacs(codec, dacs);
  2931. /* parse all analog output pins */
  2932. nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
  2933. dacs, &rest, spec->dac_info,
  2934. AUTO_PIN_LINE_OUT);
  2935. nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
  2936. dacs, &rest, spec->dac_info + nums,
  2937. AUTO_PIN_HP_OUT);
  2938. nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
  2939. dacs, &rest, spec->dac_info + nums,
  2940. AUTO_PIN_SPEAKER_OUT);
  2941. spec->dac_info_filled = nums;
  2942. /* fill multiout struct */
  2943. for (i = 0; i < nums; i++) {
  2944. hda_nid_t dac = spec->dac_info[i].dac;
  2945. if (!dac)
  2946. continue;
  2947. switch (spec->dac_info[i].type) {
  2948. case AUTO_PIN_LINE_OUT:
  2949. spec->private_dac_nids[spec->multiout.num_dacs] = dac;
  2950. spec->multiout.num_dacs++;
  2951. break;
  2952. case AUTO_PIN_HP_OUT:
  2953. case AUTO_PIN_SPEAKER_OUT:
  2954. if (!spec->multiout.hp_nid) {
  2955. spec->multiout.hp_nid = dac;
  2956. break;
  2957. }
  2958. for (j = 0; j < ARRAY_SIZE(spec->multiout.extra_out_nid); j++)
  2959. if (!spec->multiout.extra_out_nid[j]) {
  2960. spec->multiout.extra_out_nid[j] = dac;
  2961. break;
  2962. }
  2963. break;
  2964. }
  2965. }
  2966. spec->multiout.dac_nids = spec->private_dac_nids;
  2967. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  2968. for (i = 0; i < cfg->hp_outs; i++) {
  2969. if (is_jack_detectable(codec, cfg->hp_pins[i])) {
  2970. spec->auto_mute = 1;
  2971. break;
  2972. }
  2973. }
  2974. if (spec->auto_mute &&
  2975. cfg->line_out_pins[0] &&
  2976. cfg->line_out_type != AUTO_PIN_SPEAKER_OUT &&
  2977. cfg->line_out_pins[0] != cfg->hp_pins[0] &&
  2978. cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
  2979. for (i = 0; i < cfg->line_outs; i++) {
  2980. if (is_jack_detectable(codec, cfg->line_out_pins[i])) {
  2981. spec->detect_line = 1;
  2982. break;
  2983. }
  2984. }
  2985. spec->automute_lines = spec->detect_line;
  2986. }
  2987. spec->vmaster_nid = spec->private_dac_nids[0];
  2988. }
  2989. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  2990. hda_nid_t *pins, bool on);
  2991. static void do_automute(struct hda_codec *codec, int num_pins,
  2992. hda_nid_t *pins, bool on)
  2993. {
  2994. int i;
  2995. for (i = 0; i < num_pins; i++)
  2996. snd_hda_codec_write(codec, pins[i], 0,
  2997. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2998. on ? PIN_OUT : 0);
  2999. cx_auto_turn_eapd(codec, num_pins, pins, on);
  3000. }
  3001. static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
  3002. {
  3003. int i, present = 0;
  3004. for (i = 0; i < num_pins; i++) {
  3005. hda_nid_t nid = pins[i];
  3006. if (!nid || !is_jack_detectable(codec, nid))
  3007. break;
  3008. snd_hda_input_jack_report(codec, nid);
  3009. present |= snd_hda_jack_detect(codec, nid);
  3010. }
  3011. return present;
  3012. }
  3013. /* auto-mute/unmute speaker and line outs according to headphone jack */
  3014. static void cx_auto_update_speakers(struct hda_codec *codec)
  3015. {
  3016. struct conexant_spec *spec = codec->spec;
  3017. struct auto_pin_cfg *cfg = &spec->autocfg;
  3018. int on = 1;
  3019. /* turn on HP EAPD when HP jacks are present */
  3020. if (spec->auto_mute)
  3021. on = spec->hp_present;
  3022. cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
  3023. /* mute speakers in auto-mode if HP or LO jacks are plugged */
  3024. if (spec->auto_mute)
  3025. on = !(spec->hp_present ||
  3026. (spec->detect_line && spec->line_present));
  3027. do_automute(codec, cfg->speaker_outs, cfg->speaker_pins, on);
  3028. /* toggle line-out mutes if needed, too */
  3029. /* if LO is a copy of either HP or Speaker, don't need to handle it */
  3030. if (cfg->line_out_pins[0] == cfg->hp_pins[0] ||
  3031. cfg->line_out_pins[0] == cfg->speaker_pins[0])
  3032. return;
  3033. if (spec->auto_mute) {
  3034. /* mute LO in auto-mode when HP jack is present */
  3035. if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT ||
  3036. spec->automute_lines)
  3037. on = !spec->hp_present;
  3038. else
  3039. on = 1;
  3040. }
  3041. do_automute(codec, cfg->line_outs, cfg->line_out_pins, on);
  3042. }
  3043. static void cx_auto_hp_automute(struct hda_codec *codec)
  3044. {
  3045. struct conexant_spec *spec = codec->spec;
  3046. struct auto_pin_cfg *cfg = &spec->autocfg;
  3047. if (!spec->auto_mute)
  3048. return;
  3049. spec->hp_present = detect_jacks(codec, cfg->hp_outs, cfg->hp_pins);
  3050. cx_auto_update_speakers(codec);
  3051. }
  3052. static void cx_auto_line_automute(struct hda_codec *codec)
  3053. {
  3054. struct conexant_spec *spec = codec->spec;
  3055. struct auto_pin_cfg *cfg = &spec->autocfg;
  3056. if (!spec->auto_mute || !spec->detect_line)
  3057. return;
  3058. spec->line_present = detect_jacks(codec, cfg->line_outs,
  3059. cfg->line_out_pins);
  3060. cx_auto_update_speakers(codec);
  3061. }
  3062. static int cx_automute_mode_info(struct snd_kcontrol *kcontrol,
  3063. struct snd_ctl_elem_info *uinfo)
  3064. {
  3065. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3066. struct conexant_spec *spec = codec->spec;
  3067. static const char * const texts2[] = {
  3068. "Disabled", "Enabled"
  3069. };
  3070. static const char * const texts3[] = {
  3071. "Disabled", "Speaker Only", "Line-Out+Speaker"
  3072. };
  3073. const char * const *texts;
  3074. uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  3075. uinfo->count = 1;
  3076. if (spec->automute_hp_lo) {
  3077. uinfo->value.enumerated.items = 3;
  3078. texts = texts3;
  3079. } else {
  3080. uinfo->value.enumerated.items = 2;
  3081. texts = texts2;
  3082. }
  3083. if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
  3084. uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
  3085. strcpy(uinfo->value.enumerated.name,
  3086. texts[uinfo->value.enumerated.item]);
  3087. return 0;
  3088. }
  3089. static int cx_automute_mode_get(struct snd_kcontrol *kcontrol,
  3090. struct snd_ctl_elem_value *ucontrol)
  3091. {
  3092. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3093. struct conexant_spec *spec = codec->spec;
  3094. unsigned int val;
  3095. if (!spec->auto_mute)
  3096. val = 0;
  3097. else if (!spec->automute_lines)
  3098. val = 1;
  3099. else
  3100. val = 2;
  3101. ucontrol->value.enumerated.item[0] = val;
  3102. return 0;
  3103. }
  3104. static int cx_automute_mode_put(struct snd_kcontrol *kcontrol,
  3105. struct snd_ctl_elem_value *ucontrol)
  3106. {
  3107. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3108. struct conexant_spec *spec = codec->spec;
  3109. switch (ucontrol->value.enumerated.item[0]) {
  3110. case 0:
  3111. if (!spec->auto_mute)
  3112. return 0;
  3113. spec->auto_mute = 0;
  3114. break;
  3115. case 1:
  3116. if (spec->auto_mute && !spec->automute_lines)
  3117. return 0;
  3118. spec->auto_mute = 1;
  3119. spec->automute_lines = 0;
  3120. break;
  3121. case 2:
  3122. if (!spec->automute_hp_lo)
  3123. return -EINVAL;
  3124. if (spec->auto_mute && spec->automute_lines)
  3125. return 0;
  3126. spec->auto_mute = 1;
  3127. spec->automute_lines = 1;
  3128. break;
  3129. default:
  3130. return -EINVAL;
  3131. }
  3132. cx_auto_update_speakers(codec);
  3133. return 1;
  3134. }
  3135. static const struct snd_kcontrol_new cx_automute_mode_enum[] = {
  3136. {
  3137. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3138. .name = "Auto-Mute Mode",
  3139. .info = cx_automute_mode_info,
  3140. .get = cx_automute_mode_get,
  3141. .put = cx_automute_mode_put,
  3142. },
  3143. { }
  3144. };
  3145. static int cx_auto_mux_enum_info(struct snd_kcontrol *kcontrol,
  3146. struct snd_ctl_elem_info *uinfo)
  3147. {
  3148. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3149. struct conexant_spec *spec = codec->spec;
  3150. return snd_hda_input_mux_info(&spec->private_imux, uinfo);
  3151. }
  3152. static int cx_auto_mux_enum_get(struct snd_kcontrol *kcontrol,
  3153. struct snd_ctl_elem_value *ucontrol)
  3154. {
  3155. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3156. struct conexant_spec *spec = codec->spec;
  3157. ucontrol->value.enumerated.item[0] = spec->cur_mux[0];
  3158. return 0;
  3159. }
  3160. /* look for the route the given pin from mux and return the index;
  3161. * if do_select is set, actually select the route.
  3162. */
  3163. static int __select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3164. hda_nid_t pin, hda_nid_t *srcp,
  3165. bool do_select, int depth)
  3166. {
  3167. hda_nid_t conn[HDA_MAX_NUM_INPUTS];
  3168. int i, nums;
  3169. switch (get_wcaps_type(get_wcaps(codec, mux))) {
  3170. case AC_WID_AUD_IN:
  3171. case AC_WID_AUD_SEL:
  3172. case AC_WID_AUD_MIX:
  3173. break;
  3174. default:
  3175. return -1;
  3176. }
  3177. nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
  3178. for (i = 0; i < nums; i++)
  3179. if (conn[i] == pin) {
  3180. if (do_select)
  3181. snd_hda_codec_write(codec, mux, 0,
  3182. AC_VERB_SET_CONNECT_SEL, i);
  3183. if (srcp)
  3184. *srcp = mux;
  3185. return i;
  3186. }
  3187. depth++;
  3188. if (depth == 2)
  3189. return -1;
  3190. for (i = 0; i < nums; i++) {
  3191. int ret = __select_input_connection(codec, conn[i], pin, srcp,
  3192. do_select, depth);
  3193. if (ret >= 0) {
  3194. if (do_select)
  3195. snd_hda_codec_write(codec, mux, 0,
  3196. AC_VERB_SET_CONNECT_SEL, i);
  3197. return i;
  3198. }
  3199. }
  3200. return -1;
  3201. }
  3202. static void select_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3203. hda_nid_t pin)
  3204. {
  3205. __select_input_connection(codec, mux, pin, NULL, true, 0);
  3206. }
  3207. static int get_input_connection(struct hda_codec *codec, hda_nid_t mux,
  3208. hda_nid_t pin)
  3209. {
  3210. return __select_input_connection(codec, mux, pin, NULL, false, 0);
  3211. }
  3212. static int cx_auto_mux_enum_update(struct hda_codec *codec,
  3213. const struct hda_input_mux *imux,
  3214. unsigned int idx)
  3215. {
  3216. struct conexant_spec *spec = codec->spec;
  3217. hda_nid_t adc;
  3218. int changed = 1;
  3219. if (!imux->num_items)
  3220. return 0;
  3221. if (idx >= imux->num_items)
  3222. idx = imux->num_items - 1;
  3223. if (spec->cur_mux[0] == idx)
  3224. changed = 0;
  3225. adc = spec->imux_info[idx].adc;
  3226. select_input_connection(codec, spec->imux_info[idx].adc,
  3227. spec->imux_info[idx].pin);
  3228. if (spec->cur_adc && spec->cur_adc != adc) {
  3229. /* stream is running, let's swap the current ADC */
  3230. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  3231. spec->cur_adc = adc;
  3232. snd_hda_codec_setup_stream(codec, adc,
  3233. spec->cur_adc_stream_tag, 0,
  3234. spec->cur_adc_format);
  3235. }
  3236. spec->cur_mux[0] = idx;
  3237. return changed;
  3238. }
  3239. static int cx_auto_mux_enum_put(struct snd_kcontrol *kcontrol,
  3240. struct snd_ctl_elem_value *ucontrol)
  3241. {
  3242. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  3243. struct conexant_spec *spec = codec->spec;
  3244. return cx_auto_mux_enum_update(codec, &spec->private_imux,
  3245. ucontrol->value.enumerated.item[0]);
  3246. }
  3247. static const struct snd_kcontrol_new cx_auto_capture_mixers[] = {
  3248. {
  3249. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  3250. .name = "Capture Source",
  3251. .info = cx_auto_mux_enum_info,
  3252. .get = cx_auto_mux_enum_get,
  3253. .put = cx_auto_mux_enum_put
  3254. },
  3255. {}
  3256. };
  3257. static bool select_automic(struct hda_codec *codec, int idx, bool detect)
  3258. {
  3259. struct conexant_spec *spec = codec->spec;
  3260. if (idx < 0)
  3261. return false;
  3262. if (detect && !snd_hda_jack_detect(codec, spec->imux_info[idx].pin))
  3263. return false;
  3264. cx_auto_mux_enum_update(codec, &spec->private_imux, idx);
  3265. return true;
  3266. }
  3267. /* automatic switch internal and external mic */
  3268. static void cx_auto_automic(struct hda_codec *codec)
  3269. {
  3270. struct conexant_spec *spec = codec->spec;
  3271. if (!spec->auto_mic)
  3272. return;
  3273. if (!select_automic(codec, spec->auto_mic_ext, true))
  3274. if (!select_automic(codec, spec->auto_mic_dock, true))
  3275. select_automic(codec, spec->auto_mic_int, false);
  3276. }
  3277. static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
  3278. {
  3279. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  3280. switch (res >> 26) {
  3281. case CONEXANT_HP_EVENT:
  3282. cx_auto_hp_automute(codec);
  3283. break;
  3284. case CONEXANT_LINE_EVENT:
  3285. cx_auto_line_automute(codec);
  3286. break;
  3287. case CONEXANT_MIC_EVENT:
  3288. cx_auto_automic(codec);
  3289. snd_hda_input_jack_report(codec, nid);
  3290. break;
  3291. }
  3292. }
  3293. /* check whether the pin config is suitable for auto-mic switching;
  3294. * auto-mic is enabled only when one int-mic and one ext- and/or
  3295. * one dock-mic exist
  3296. */
  3297. static void cx_auto_check_auto_mic(struct hda_codec *codec)
  3298. {
  3299. struct conexant_spec *spec = codec->spec;
  3300. int pset[INPUT_PIN_ATTR_NORMAL + 1];
  3301. int i;
  3302. for (i = 0; i < ARRAY_SIZE(pset); i++)
  3303. pset[i] = -1;
  3304. for (i = 0; i < spec->private_imux.num_items; i++) {
  3305. hda_nid_t pin = spec->imux_info[i].pin;
  3306. unsigned int def_conf = snd_hda_codec_get_pincfg(codec, pin);
  3307. int type, attr;
  3308. attr = snd_hda_get_input_pin_attr(def_conf);
  3309. if (attr == INPUT_PIN_ATTR_UNUSED)
  3310. return; /* invalid entry */
  3311. if (attr > INPUT_PIN_ATTR_NORMAL)
  3312. attr = INPUT_PIN_ATTR_NORMAL;
  3313. if (attr != INPUT_PIN_ATTR_INT &&
  3314. !is_jack_detectable(codec, pin))
  3315. return; /* non-detectable pin */
  3316. type = get_defcfg_device(def_conf);
  3317. if (type != AC_JACK_MIC_IN &&
  3318. (attr != INPUT_PIN_ATTR_DOCK || type != AC_JACK_LINE_IN))
  3319. return; /* no valid input type */
  3320. if (pset[attr] >= 0)
  3321. return; /* already occupied */
  3322. pset[attr] = i;
  3323. }
  3324. if (pset[INPUT_PIN_ATTR_INT] < 0 ||
  3325. (pset[INPUT_PIN_ATTR_NORMAL] < 0 && pset[INPUT_PIN_ATTR_DOCK]))
  3326. return; /* no input to switch*/
  3327. spec->auto_mic = 1;
  3328. spec->auto_mic_ext = pset[INPUT_PIN_ATTR_NORMAL];
  3329. spec->auto_mic_dock = pset[INPUT_PIN_ATTR_DOCK];
  3330. spec->auto_mic_int = pset[INPUT_PIN_ATTR_INT];
  3331. }
  3332. static void cx_auto_parse_input(struct hda_codec *codec)
  3333. {
  3334. struct conexant_spec *spec = codec->spec;
  3335. struct auto_pin_cfg *cfg = &spec->autocfg;
  3336. struct hda_input_mux *imux;
  3337. int i, j;
  3338. imux = &spec->private_imux;
  3339. for (i = 0; i < cfg->num_inputs; i++) {
  3340. for (j = 0; j < spec->num_adc_nids; j++) {
  3341. hda_nid_t adc = spec->adc_nids[j];
  3342. int idx = get_input_connection(codec, adc,
  3343. cfg->inputs[i].pin);
  3344. if (idx >= 0) {
  3345. const char *label;
  3346. label = hda_get_autocfg_input_label(codec, cfg, i);
  3347. spec->imux_info[imux->num_items].index = i;
  3348. spec->imux_info[imux->num_items].boost = 0;
  3349. spec->imux_info[imux->num_items].adc = adc;
  3350. spec->imux_info[imux->num_items].pin =
  3351. cfg->inputs[i].pin;
  3352. snd_hda_add_imux_item(imux, label, idx, NULL);
  3353. break;
  3354. }
  3355. }
  3356. }
  3357. if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
  3358. cx_auto_check_auto_mic(codec);
  3359. if (imux->num_items > 1 && !spec->auto_mic) {
  3360. for (i = 1; i < imux->num_items; i++) {
  3361. if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
  3362. spec->adc_switching = 1;
  3363. break;
  3364. }
  3365. }
  3366. }
  3367. }
  3368. /* get digital-input audio widget corresponding to the given pin */
  3369. static hda_nid_t cx_auto_get_dig_in(struct hda_codec *codec, hda_nid_t pin)
  3370. {
  3371. hda_nid_t nid, end_nid;
  3372. end_nid = codec->start_nid + codec->num_nodes;
  3373. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3374. unsigned int wcaps = get_wcaps(codec, nid);
  3375. unsigned int type = get_wcaps_type(wcaps);
  3376. if (type == AC_WID_AUD_IN && (wcaps & AC_WCAP_DIGITAL)) {
  3377. if (get_connection_index(codec, nid, pin) >= 0)
  3378. return nid;
  3379. }
  3380. }
  3381. return 0;
  3382. }
  3383. static void cx_auto_parse_digital(struct hda_codec *codec)
  3384. {
  3385. struct conexant_spec *spec = codec->spec;
  3386. struct auto_pin_cfg *cfg = &spec->autocfg;
  3387. hda_nid_t nid;
  3388. if (cfg->dig_outs &&
  3389. snd_hda_get_connections(codec, cfg->dig_out_pins[0], &nid, 1) == 1)
  3390. spec->multiout.dig_out_nid = nid;
  3391. if (cfg->dig_in_pin)
  3392. spec->dig_in_nid = cx_auto_get_dig_in(codec, cfg->dig_in_pin);
  3393. }
  3394. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  3395. static void cx_auto_parse_beep(struct hda_codec *codec)
  3396. {
  3397. struct conexant_spec *spec = codec->spec;
  3398. hda_nid_t nid, end_nid;
  3399. end_nid = codec->start_nid + codec->num_nodes;
  3400. for (nid = codec->start_nid; nid < end_nid; nid++)
  3401. if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_BEEP) {
  3402. set_beep_amp(spec, nid, 0, HDA_OUTPUT);
  3403. break;
  3404. }
  3405. }
  3406. #else
  3407. #define cx_auto_parse_beep(codec)
  3408. #endif
  3409. static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
  3410. {
  3411. int i;
  3412. for (i = 0; i < nums; i++)
  3413. if (list[i] == nid)
  3414. return true;
  3415. return false;
  3416. }
  3417. /* parse extra-EAPD that aren't assigned to any pins */
  3418. static void cx_auto_parse_eapd(struct hda_codec *codec)
  3419. {
  3420. struct conexant_spec *spec = codec->spec;
  3421. struct auto_pin_cfg *cfg = &spec->autocfg;
  3422. hda_nid_t nid, end_nid;
  3423. end_nid = codec->start_nid + codec->num_nodes;
  3424. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3425. if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
  3426. continue;
  3427. if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
  3428. continue;
  3429. if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
  3430. found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
  3431. found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs))
  3432. continue;
  3433. spec->eapds[spec->num_eapds++] = nid;
  3434. if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
  3435. break;
  3436. }
  3437. }
  3438. static int cx_auto_parse_auto_config(struct hda_codec *codec)
  3439. {
  3440. struct conexant_spec *spec = codec->spec;
  3441. int err;
  3442. err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL);
  3443. if (err < 0)
  3444. return err;
  3445. cx_auto_parse_output(codec);
  3446. cx_auto_parse_input(codec);
  3447. cx_auto_parse_digital(codec);
  3448. cx_auto_parse_beep(codec);
  3449. cx_auto_parse_eapd(codec);
  3450. return 0;
  3451. }
  3452. static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
  3453. hda_nid_t *pins, bool on)
  3454. {
  3455. int i;
  3456. for (i = 0; i < num_pins; i++) {
  3457. if (snd_hda_query_pin_caps(codec, pins[i]) & AC_PINCAP_EAPD)
  3458. snd_hda_codec_write(codec, pins[i], 0,
  3459. AC_VERB_SET_EAPD_BTLENABLE,
  3460. on ? 0x02 : 0);
  3461. }
  3462. }
  3463. static void select_connection(struct hda_codec *codec, hda_nid_t pin,
  3464. hda_nid_t src)
  3465. {
  3466. int idx = get_connection_index(codec, pin, src);
  3467. if (idx >= 0)
  3468. snd_hda_codec_write(codec, pin, 0,
  3469. AC_VERB_SET_CONNECT_SEL, idx);
  3470. }
  3471. static void mute_outputs(struct hda_codec *codec, int num_nids,
  3472. const hda_nid_t *nids)
  3473. {
  3474. int i, val;
  3475. for (i = 0; i < num_nids; i++) {
  3476. hda_nid_t nid = nids[i];
  3477. if (!(get_wcaps(codec, nid) & AC_WCAP_OUT_AMP))
  3478. continue;
  3479. if (query_amp_caps(codec, nid, HDA_OUTPUT) & AC_AMPCAP_MUTE)
  3480. val = AMP_OUT_MUTE;
  3481. else
  3482. val = AMP_OUT_ZERO;
  3483. snd_hda_codec_write(codec, nid, 0,
  3484. AC_VERB_SET_AMP_GAIN_MUTE, val);
  3485. }
  3486. }
  3487. static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
  3488. hda_nid_t *pins, unsigned int tag)
  3489. {
  3490. int i;
  3491. for (i = 0; i < num_pins; i++)
  3492. snd_hda_codec_write(codec, pins[i], 0,
  3493. AC_VERB_SET_UNSOLICITED_ENABLE,
  3494. AC_USRSP_EN | tag);
  3495. }
  3496. static void cx_auto_init_output(struct hda_codec *codec)
  3497. {
  3498. struct conexant_spec *spec = codec->spec;
  3499. struct auto_pin_cfg *cfg = &spec->autocfg;
  3500. hda_nid_t nid;
  3501. int i;
  3502. mute_outputs(codec, spec->multiout.num_dacs, spec->multiout.dac_nids);
  3503. for (i = 0; i < cfg->hp_outs; i++)
  3504. snd_hda_codec_write(codec, cfg->hp_pins[i], 0,
  3505. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP);
  3506. mute_outputs(codec, cfg->hp_outs, cfg->hp_pins);
  3507. mute_outputs(codec, cfg->line_outs, cfg->line_out_pins);
  3508. mute_outputs(codec, cfg->speaker_outs, cfg->speaker_pins);
  3509. for (i = 0; i < spec->dac_info_filled; i++) {
  3510. nid = spec->dac_info[i].dac;
  3511. if (!nid)
  3512. nid = spec->multiout.dac_nids[0];
  3513. select_connection(codec, spec->dac_info[i].pin, nid);
  3514. }
  3515. if (spec->auto_mute) {
  3516. enable_unsol_pins(codec, cfg->hp_outs, cfg->hp_pins,
  3517. CONEXANT_HP_EVENT);
  3518. spec->hp_present = detect_jacks(codec, cfg->hp_outs,
  3519. cfg->hp_pins);
  3520. if (spec->detect_line) {
  3521. enable_unsol_pins(codec, cfg->line_outs,
  3522. cfg->line_out_pins,
  3523. CONEXANT_LINE_EVENT);
  3524. spec->line_present =
  3525. detect_jacks(codec, cfg->line_outs,
  3526. cfg->line_out_pins);
  3527. }
  3528. }
  3529. cx_auto_update_speakers(codec);
  3530. /* turn on/off extra EAPDs, too */
  3531. cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
  3532. }
  3533. static void cx_auto_init_input(struct hda_codec *codec)
  3534. {
  3535. struct conexant_spec *spec = codec->spec;
  3536. struct auto_pin_cfg *cfg = &spec->autocfg;
  3537. int i, val;
  3538. for (i = 0; i < spec->num_adc_nids; i++) {
  3539. hda_nid_t nid = spec->adc_nids[i];
  3540. if (!(get_wcaps(codec, nid) & AC_WCAP_IN_AMP))
  3541. continue;
  3542. if (query_amp_caps(codec, nid, HDA_INPUT) & AC_AMPCAP_MUTE)
  3543. val = AMP_IN_MUTE(0);
  3544. else
  3545. val = AMP_IN_UNMUTE(0);
  3546. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  3547. val);
  3548. }
  3549. for (i = 0; i < cfg->num_inputs; i++) {
  3550. unsigned int type;
  3551. if (cfg->inputs[i].type == AUTO_PIN_MIC)
  3552. type = PIN_VREF80;
  3553. else
  3554. type = PIN_IN;
  3555. snd_hda_codec_write(codec, cfg->inputs[i].pin, 0,
  3556. AC_VERB_SET_PIN_WIDGET_CONTROL, type);
  3557. }
  3558. if (spec->auto_mic) {
  3559. if (spec->auto_mic_ext >= 0) {
  3560. snd_hda_codec_write(codec,
  3561. cfg->inputs[spec->auto_mic_ext].pin, 0,
  3562. AC_VERB_SET_UNSOLICITED_ENABLE,
  3563. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3564. }
  3565. if (spec->auto_mic_dock >= 0) {
  3566. snd_hda_codec_write(codec,
  3567. cfg->inputs[spec->auto_mic_dock].pin, 0,
  3568. AC_VERB_SET_UNSOLICITED_ENABLE,
  3569. AC_USRSP_EN | CONEXANT_MIC_EVENT);
  3570. }
  3571. cx_auto_automic(codec);
  3572. } else {
  3573. select_input_connection(codec, spec->imux_info[0].adc,
  3574. spec->imux_info[0].pin);
  3575. }
  3576. }
  3577. static void cx_auto_init_digital(struct hda_codec *codec)
  3578. {
  3579. struct conexant_spec *spec = codec->spec;
  3580. struct auto_pin_cfg *cfg = &spec->autocfg;
  3581. if (spec->multiout.dig_out_nid)
  3582. snd_hda_codec_write(codec, cfg->dig_out_pins[0], 0,
  3583. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  3584. if (spec->dig_in_nid)
  3585. snd_hda_codec_write(codec, cfg->dig_in_pin, 0,
  3586. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN);
  3587. }
  3588. static int cx_auto_init(struct hda_codec *codec)
  3589. {
  3590. /*snd_hda_sequence_write(codec, cx_auto_init_verbs);*/
  3591. cx_auto_init_output(codec);
  3592. cx_auto_init_input(codec);
  3593. cx_auto_init_digital(codec);
  3594. return 0;
  3595. }
  3596. static int cx_auto_add_volume_idx(struct hda_codec *codec, const char *basename,
  3597. const char *dir, int cidx,
  3598. hda_nid_t nid, int hda_dir, int amp_idx)
  3599. {
  3600. static char name[32];
  3601. static struct snd_kcontrol_new knew[] = {
  3602. HDA_CODEC_VOLUME(name, 0, 0, 0),
  3603. HDA_CODEC_MUTE(name, 0, 0, 0),
  3604. };
  3605. static const char * const sfx[2] = { "Volume", "Switch" };
  3606. int i, err;
  3607. for (i = 0; i < 2; i++) {
  3608. struct snd_kcontrol *kctl;
  3609. knew[i].private_value = HDA_COMPOSE_AMP_VAL(nid, 3, amp_idx,
  3610. hda_dir);
  3611. knew[i].subdevice = HDA_SUBDEV_AMP_FLAG;
  3612. knew[i].index = cidx;
  3613. snprintf(name, sizeof(name), "%s%s %s", basename, dir, sfx[i]);
  3614. kctl = snd_ctl_new1(&knew[i], codec);
  3615. if (!kctl)
  3616. return -ENOMEM;
  3617. err = snd_hda_ctl_add(codec, nid, kctl);
  3618. if (err < 0)
  3619. return err;
  3620. if (!(query_amp_caps(codec, nid, hda_dir) & AC_AMPCAP_MUTE))
  3621. break;
  3622. }
  3623. return 0;
  3624. }
  3625. #define cx_auto_add_volume(codec, str, dir, cidx, nid, hda_dir) \
  3626. cx_auto_add_volume_idx(codec, str, dir, cidx, nid, hda_dir, 0)
  3627. #define cx_auto_add_pb_volume(codec, nid, str, idx) \
  3628. cx_auto_add_volume(codec, str, " Playback", idx, nid, HDA_OUTPUT)
  3629. static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
  3630. hda_nid_t pin, const char *name, int idx)
  3631. {
  3632. unsigned int caps;
  3633. caps = query_amp_caps(codec, dac, HDA_OUTPUT);
  3634. if (caps & AC_AMPCAP_NUM_STEPS)
  3635. return cx_auto_add_pb_volume(codec, dac, name, idx);
  3636. caps = query_amp_caps(codec, pin, HDA_OUTPUT);
  3637. if (caps & AC_AMPCAP_NUM_STEPS)
  3638. return cx_auto_add_pb_volume(codec, pin, name, idx);
  3639. return 0;
  3640. }
  3641. static int cx_auto_build_output_controls(struct hda_codec *codec)
  3642. {
  3643. struct conexant_spec *spec = codec->spec;
  3644. int i, err;
  3645. int num_line = 0, num_hp = 0, num_spk = 0;
  3646. static const char * const texts[3] = { "Front", "Surround", "CLFE" };
  3647. if (spec->dac_info_filled == 1)
  3648. return try_add_pb_volume(codec, spec->dac_info[0].dac,
  3649. spec->dac_info[0].pin,
  3650. "Master", 0);
  3651. for (i = 0; i < spec->dac_info_filled; i++) {
  3652. const char *label;
  3653. int idx, type;
  3654. if (!spec->dac_info[i].dac)
  3655. continue;
  3656. type = spec->dac_info[i].type;
  3657. if (type == AUTO_PIN_LINE_OUT)
  3658. type = spec->autocfg.line_out_type;
  3659. switch (type) {
  3660. case AUTO_PIN_LINE_OUT:
  3661. default:
  3662. label = texts[num_line++];
  3663. idx = 0;
  3664. break;
  3665. case AUTO_PIN_HP_OUT:
  3666. label = "Headphone";
  3667. idx = num_hp++;
  3668. break;
  3669. case AUTO_PIN_SPEAKER_OUT:
  3670. label = "Speaker";
  3671. idx = num_spk++;
  3672. break;
  3673. }
  3674. err = try_add_pb_volume(codec, spec->dac_info[i].dac,
  3675. spec->dac_info[i].pin,
  3676. label, idx);
  3677. if (err < 0)
  3678. return err;
  3679. }
  3680. if (spec->auto_mute) {
  3681. err = snd_hda_add_new_ctls(codec, cx_automute_mode_enum);
  3682. if (err < 0)
  3683. return err;
  3684. }
  3685. return 0;
  3686. }
  3687. static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
  3688. const char *label, const char *pfx,
  3689. int cidx)
  3690. {
  3691. struct conexant_spec *spec = codec->spec;
  3692. int i;
  3693. for (i = 0; i < spec->num_adc_nids; i++) {
  3694. hda_nid_t adc_nid = spec->adc_nids[i];
  3695. int idx = get_input_connection(codec, adc_nid, nid);
  3696. if (idx < 0)
  3697. continue;
  3698. return cx_auto_add_volume_idx(codec, label, pfx,
  3699. cidx, adc_nid, HDA_INPUT, idx);
  3700. }
  3701. return 0;
  3702. }
  3703. static int cx_auto_add_boost_volume(struct hda_codec *codec, int idx,
  3704. const char *label, int cidx)
  3705. {
  3706. struct conexant_spec *spec = codec->spec;
  3707. hda_nid_t mux, nid;
  3708. int i, con;
  3709. nid = spec->imux_info[idx].pin;
  3710. if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP)
  3711. return cx_auto_add_volume(codec, label, " Boost", cidx,
  3712. nid, HDA_INPUT);
  3713. con = __select_input_connection(codec, spec->imux_info[idx].adc, nid,
  3714. &mux, false, 0);
  3715. if (con < 0)
  3716. return 0;
  3717. for (i = 0; i < idx; i++) {
  3718. if (spec->imux_info[i].boost == mux)
  3719. return 0; /* already present */
  3720. }
  3721. if (get_wcaps(codec, mux) & AC_WCAP_OUT_AMP) {
  3722. spec->imux_info[idx].boost = mux;
  3723. return cx_auto_add_volume(codec, label, " Boost", 0,
  3724. mux, HDA_OUTPUT);
  3725. }
  3726. return 0;
  3727. }
  3728. static int cx_auto_build_input_controls(struct hda_codec *codec)
  3729. {
  3730. struct conexant_spec *spec = codec->spec;
  3731. struct hda_input_mux *imux = &spec->private_imux;
  3732. const char *prev_label;
  3733. int input_conn[HDA_MAX_NUM_INPUTS];
  3734. int i, err, cidx;
  3735. int multi_connection;
  3736. multi_connection = 0;
  3737. for (i = 0; i < imux->num_items; i++) {
  3738. cidx = get_input_connection(codec, spec->imux_info[i].adc,
  3739. spec->imux_info[i].pin);
  3740. input_conn[i] = (spec->imux_info[i].adc << 8) | cidx;
  3741. if (i > 0 && input_conn[i] != input_conn[0])
  3742. multi_connection = 1;
  3743. }
  3744. prev_label = NULL;
  3745. cidx = 0;
  3746. for (i = 0; i < imux->num_items; i++) {
  3747. hda_nid_t nid = spec->imux_info[i].pin;
  3748. const char *label;
  3749. label = hda_get_autocfg_input_label(codec, &spec->autocfg,
  3750. spec->imux_info[i].index);
  3751. if (label == prev_label)
  3752. cidx++;
  3753. else
  3754. cidx = 0;
  3755. prev_label = label;
  3756. err = cx_auto_add_boost_volume(codec, i, label, cidx);
  3757. if (err < 0)
  3758. return err;
  3759. if (!multi_connection) {
  3760. if (i > 0)
  3761. continue;
  3762. err = cx_auto_add_capture_volume(codec, nid,
  3763. "Capture", "", cidx);
  3764. } else {
  3765. err = cx_auto_add_capture_volume(codec, nid,
  3766. label, " Capture", cidx);
  3767. }
  3768. if (err < 0)
  3769. return err;
  3770. }
  3771. if (spec->private_imux.num_items > 1 && !spec->auto_mic) {
  3772. err = snd_hda_add_new_ctls(codec, cx_auto_capture_mixers);
  3773. if (err < 0)
  3774. return err;
  3775. }
  3776. return 0;
  3777. }
  3778. static int cx_auto_build_controls(struct hda_codec *codec)
  3779. {
  3780. int err;
  3781. err = cx_auto_build_output_controls(codec);
  3782. if (err < 0)
  3783. return err;
  3784. err = cx_auto_build_input_controls(codec);
  3785. if (err < 0)
  3786. return err;
  3787. return conexant_build_controls(codec);
  3788. }
  3789. static int cx_auto_search_adcs(struct hda_codec *codec)
  3790. {
  3791. struct conexant_spec *spec = codec->spec;
  3792. hda_nid_t nid, end_nid;
  3793. end_nid = codec->start_nid + codec->num_nodes;
  3794. for (nid = codec->start_nid; nid < end_nid; nid++) {
  3795. unsigned int caps = get_wcaps(codec, nid);
  3796. if (get_wcaps_type(caps) != AC_WID_AUD_IN)
  3797. continue;
  3798. if (caps & AC_WCAP_DIGITAL)
  3799. continue;
  3800. if (snd_BUG_ON(spec->num_adc_nids >=
  3801. ARRAY_SIZE(spec->private_adc_nids)))
  3802. break;
  3803. spec->private_adc_nids[spec->num_adc_nids++] = nid;
  3804. }
  3805. spec->adc_nids = spec->private_adc_nids;
  3806. return 0;
  3807. }
  3808. static const struct hda_codec_ops cx_auto_patch_ops = {
  3809. .build_controls = cx_auto_build_controls,
  3810. .build_pcms = conexant_build_pcms,
  3811. .init = cx_auto_init,
  3812. .free = conexant_free,
  3813. .unsol_event = cx_auto_unsol_event,
  3814. #ifdef CONFIG_SND_HDA_POWER_SAVE
  3815. .suspend = conexant_suspend,
  3816. #endif
  3817. .reboot_notify = snd_hda_shutup_pins,
  3818. };
  3819. static int patch_conexant_auto(struct hda_codec *codec)
  3820. {
  3821. struct conexant_spec *spec;
  3822. int err;
  3823. printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
  3824. codec->chip_name);
  3825. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  3826. if (!spec)
  3827. return -ENOMEM;
  3828. codec->spec = spec;
  3829. codec->pin_amp_workaround = 1;
  3830. err = cx_auto_search_adcs(codec);
  3831. if (err < 0)
  3832. return err;
  3833. err = cx_auto_parse_auto_config(codec);
  3834. if (err < 0) {
  3835. kfree(codec->spec);
  3836. codec->spec = NULL;
  3837. return err;
  3838. }
  3839. spec->capture_stream = &cx_auto_pcm_analog_capture;
  3840. codec->patch_ops = cx_auto_patch_ops;
  3841. if (spec->beep_amp)
  3842. snd_hda_attach_beep_device(codec, spec->beep_amp);
  3843. return 0;
  3844. }
  3845. /*
  3846. */
  3847. static const struct hda_codec_preset snd_hda_preset_conexant[] = {
  3848. { .id = 0x14f15045, .name = "CX20549 (Venice)",
  3849. .patch = patch_cxt5045 },
  3850. { .id = 0x14f15047, .name = "CX20551 (Waikiki)",
  3851. .patch = patch_cxt5047 },
  3852. { .id = 0x14f15051, .name = "CX20561 (Hermosa)",
  3853. .patch = patch_cxt5051 },
  3854. { .id = 0x14f15066, .name = "CX20582 (Pebble)",
  3855. .patch = patch_cxt5066 },
  3856. { .id = 0x14f15067, .name = "CX20583 (Pebble HSF)",
  3857. .patch = patch_cxt5066 },
  3858. { .id = 0x14f15068, .name = "CX20584",
  3859. .patch = patch_cxt5066 },
  3860. { .id = 0x14f15069, .name = "CX20585",
  3861. .patch = patch_cxt5066 },
  3862. { .id = 0x14f1506c, .name = "CX20588",
  3863. .patch = patch_cxt5066 },
  3864. { .id = 0x14f1506e, .name = "CX20590",
  3865. .patch = patch_cxt5066 },
  3866. { .id = 0x14f15097, .name = "CX20631",
  3867. .patch = patch_conexant_auto },
  3868. { .id = 0x14f15098, .name = "CX20632",
  3869. .patch = patch_conexant_auto },
  3870. { .id = 0x14f150a1, .name = "CX20641",
  3871. .patch = patch_conexant_auto },
  3872. { .id = 0x14f150a2, .name = "CX20642",
  3873. .patch = patch_conexant_auto },
  3874. { .id = 0x14f150ab, .name = "CX20651",
  3875. .patch = patch_conexant_auto },
  3876. { .id = 0x14f150ac, .name = "CX20652",
  3877. .patch = patch_conexant_auto },
  3878. { .id = 0x14f150b8, .name = "CX20664",
  3879. .patch = patch_conexant_auto },
  3880. { .id = 0x14f150b9, .name = "CX20665",
  3881. .patch = patch_conexant_auto },
  3882. {} /* terminator */
  3883. };
  3884. MODULE_ALIAS("snd-hda-codec-id:14f15045");
  3885. MODULE_ALIAS("snd-hda-codec-id:14f15047");
  3886. MODULE_ALIAS("snd-hda-codec-id:14f15051");
  3887. MODULE_ALIAS("snd-hda-codec-id:14f15066");
  3888. MODULE_ALIAS("snd-hda-codec-id:14f15067");
  3889. MODULE_ALIAS("snd-hda-codec-id:14f15068");
  3890. MODULE_ALIAS("snd-hda-codec-id:14f15069");
  3891. MODULE_ALIAS("snd-hda-codec-id:14f1506c");
  3892. MODULE_ALIAS("snd-hda-codec-id:14f1506e");
  3893. MODULE_ALIAS("snd-hda-codec-id:14f15097");
  3894. MODULE_ALIAS("snd-hda-codec-id:14f15098");
  3895. MODULE_ALIAS("snd-hda-codec-id:14f150a1");
  3896. MODULE_ALIAS("snd-hda-codec-id:14f150a2");
  3897. MODULE_ALIAS("snd-hda-codec-id:14f150ab");
  3898. MODULE_ALIAS("snd-hda-codec-id:14f150ac");
  3899. MODULE_ALIAS("snd-hda-codec-id:14f150b8");
  3900. MODULE_ALIAS("snd-hda-codec-id:14f150b9");
  3901. MODULE_LICENSE("GPL");
  3902. MODULE_DESCRIPTION("Conexant HD-audio codec");
  3903. static struct hda_codec_preset_list conexant_list = {
  3904. .preset = snd_hda_preset_conexant,
  3905. .owner = THIS_MODULE,
  3906. };
  3907. static int __init patch_conexant_init(void)
  3908. {
  3909. return snd_hda_add_codec_preset(&conexant_list);
  3910. }
  3911. static void __exit patch_conexant_exit(void)
  3912. {
  3913. snd_hda_delete_codec_preset(&conexant_list);
  3914. }
  3915. module_init(patch_conexant_init)
  3916. module_exit(patch_conexant_exit)