patch_conexant.c 133 KB

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