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 <sound/core.h>
  27. #include <sound/jack.h>
  28. #include "hda_codec.h"
  29. #include "hda_local.h"
  30. #include "hda_beep.h"
  31. #define CXT_PIN_DIR_IN 0x00
  32. #define CXT_PIN_DIR_OUT 0x01
  33. #define CXT_PIN_DIR_INOUT 0x02
  34. #define CXT_PIN_DIR_IN_NOMICBIAS 0x03
  35. #define CXT_PIN_DIR_INOUT_NOMICBIAS 0x04
  36. #define CONEXANT_HP_EVENT 0x37
  37. #define CONEXANT_MIC_EVENT 0x38
  38. #define CONEXANT_LINE_EVENT 0x39
  39. /* Conexant 5051 specific */
  40. #define CXT5051_SPDIF_OUT 0x12
  41. #define CXT5051_PORTB_EVENT 0x38
  42. #define CXT5051_PORTC_EVENT 0x39
  43. #define AUTO_MIC_PORTB (1 << 1)
  44. #define AUTO_MIC_PORTC (1 << 2)
  45. struct pin_dac_pair {
  46. hda_nid_t pin;
  47. hda_nid_t dac;
  48. int type;
  49. };
  50. struct imux_info {
  51. hda_nid_t pin; /* input pin NID */
  52. hda_nid_t adc; /* connected ADC NID */
  53. hda_nid_t boost; /* optional boost volume NID */
  54. int index; /* corresponding to autocfg.input */
  55. };
  56. struct conexant_spec {
  57. const struct snd_kcontrol_new *mixers[5];
  58. int num_mixers;
  59. hda_nid_t vmaster_nid;
  60. const struct hda_verb *init_verbs[5]; /* initialization verbs
  61. * don't forget NULL
  62. * termination!
  63. */
  64. unsigned int num_init_verbs;
  65. /* playback */
  66. struct hda_multi_out multiout; /* playback set-up
  67. * max_channels, dacs must be set
  68. * dig_out_nid and hp_nid are optional
  69. */
  70. unsigned int cur_eapd;
  71. unsigned int hp_present;
  72. unsigned int line_present;
  73. unsigned int auto_mic;
  74. int auto_mic_ext; /* imux_pins[] index for ext mic */
  75. int auto_mic_dock; /* imux_pins[] index for dock mic */
  76. int auto_mic_int; /* imux_pins[] index for int mic */
  77. unsigned int need_dac_fix;
  78. hda_nid_t slave_dig_outs[2];
  79. /* capture */
  80. unsigned int num_adc_nids;
  81. const hda_nid_t *adc_nids;
  82. hda_nid_t dig_in_nid; /* digital-in NID; optional */
  83. unsigned int cur_adc_idx;
  84. hda_nid_t cur_adc;
  85. unsigned int cur_adc_stream_tag;
  86. unsigned int cur_adc_format;
  87. const struct hda_pcm_stream *capture_stream;
  88. /* capture source */
  89. const struct hda_input_mux *input_mux;
  90. const hda_nid_t *capsrc_nids;
  91. unsigned int cur_mux[3];
  92. /* channel model */
  93. const struct hda_channel_mode *channel_mode;
  94. int num_channel_mode;
  95. /* PCM information */
  96. struct hda_pcm pcm_rec[2]; /* used in build_pcms() */
  97. unsigned int spdif_route;
  98. /* dynamic controls, init_verbs and input_mux */
  99. struct auto_pin_cfg autocfg;
  100. struct hda_input_mux private_imux;
  101. struct imux_info imux_info[HDA_MAX_NUM_INPUTS];
  102. hda_nid_t private_adc_nids[HDA_MAX_NUM_INPUTS];
  103. hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
  104. struct pin_dac_pair dac_info[8];
  105. int dac_info_filled;
  106. unsigned int port_d_mode;
  107. unsigned int auto_mute:1; /* used in auto-parser */
  108. unsigned int detect_line:1; /* Line-out detection enabled */
  109. unsigned int automute_lines:1; /* automute line-out as well */
  110. unsigned int automute_hp_lo:1; /* both HP and LO available */
  111. unsigned int dell_automute:1;
  112. unsigned int dell_vostro:1;
  113. unsigned int ideapad:1;
  114. unsigned int thinkpad:1;
  115. unsigned int hp_laptop:1;
  116. unsigned int asus:1;
  117. unsigned int pin_eapd_ctrls:1;
  118. unsigned int single_adc_amp:1;
  119. unsigned int adc_switching:1;
  120. unsigned int ext_mic_present;
  121. unsigned int recording;
  122. void (*capture_prepare)(struct hda_codec *codec);
  123. void (*capture_cleanup)(struct hda_codec *codec);
  124. /* OLPC XO-1.5 supports DC input mode (e.g. for use with analog sensors)
  125. * through the microphone jack.
  126. * When the user enables this through a mixer switch, both internal and
  127. * external microphones are disabled. Gain is fixed at 0dB. In this mode,
  128. * we also allow the bias to be configured through a separate mixer
  129. * control. */
  130. unsigned int dc_enable;
  131. unsigned int dc_input_bias; /* offset into cxt5066_olpc_dc_bias */
  132. unsigned int mic_boost; /* offset into cxt5066_analog_mic_boost */
  133. unsigned int beep_amp;
  134. /* extra EAPD pins */
  135. unsigned int num_eapds;
  136. hda_nid_t eapds[4];
  137. };
  138. static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
  139. struct hda_codec *codec,
  140. struct snd_pcm_substream *substream)
  141. {
  142. struct conexant_spec *spec = codec->spec;
  143. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
  144. hinfo);
  145. }
  146. static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  147. struct hda_codec *codec,
  148. unsigned int stream_tag,
  149. unsigned int format,
  150. struct snd_pcm_substream *substream)
  151. {
  152. struct conexant_spec *spec = codec->spec;
  153. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
  154. stream_tag,
  155. format, substream);
  156. }
  157. static int conexant_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  158. struct hda_codec *codec,
  159. struct snd_pcm_substream *substream)
  160. {
  161. struct conexant_spec *spec = codec->spec;
  162. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  163. }
  164. /*
  165. * Digital out
  166. */
  167. static int conexant_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  168. struct hda_codec *codec,
  169. struct snd_pcm_substream *substream)
  170. {
  171. struct conexant_spec *spec = codec->spec;
  172. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  173. }
  174. static int conexant_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  175. struct hda_codec *codec,
  176. struct snd_pcm_substream *substream)
  177. {
  178. struct conexant_spec *spec = codec->spec;
  179. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  180. }
  181. static int conexant_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  182. struct hda_codec *codec,
  183. unsigned int stream_tag,
  184. unsigned int format,
  185. struct snd_pcm_substream *substream)
  186. {
  187. struct conexant_spec *spec = codec->spec;
  188. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  189. stream_tag,
  190. format, substream);
  191. }
  192. /*
  193. * Analog capture
  194. */
  195. static int conexant_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  196. struct hda_codec *codec,
  197. unsigned int stream_tag,
  198. unsigned int format,
  199. struct snd_pcm_substream *substream)
  200. {
  201. struct conexant_spec *spec = codec->spec;
  202. if (spec->capture_prepare)
  203. spec->capture_prepare(codec);
  204. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  205. stream_tag, 0, format);
  206. return 0;
  207. }
  208. static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  209. struct hda_codec *codec,
  210. struct snd_pcm_substream *substream)
  211. {
  212. struct conexant_spec *spec = codec->spec;
  213. snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
  214. if (spec->capture_cleanup)
  215. spec->capture_cleanup(codec);
  216. return 0;
  217. }
  218. static const struct hda_pcm_stream conexant_pcm_analog_playback = {
  219. .substreams = 1,
  220. .channels_min = 2,
  221. .channels_max = 2,
  222. .nid = 0, /* fill later */
  223. .ops = {
  224. .open = conexant_playback_pcm_open,
  225. .prepare = conexant_playback_pcm_prepare,
  226. .cleanup = conexant_playback_pcm_cleanup
  227. },
  228. };
  229. static const struct hda_pcm_stream conexant_pcm_analog_capture = {
  230. .substreams = 1,
  231. .channels_min = 2,
  232. .channels_max = 2,
  233. .nid = 0, /* fill later */
  234. .ops = {
  235. .prepare = conexant_capture_pcm_prepare,
  236. .cleanup = conexant_capture_pcm_cleanup
  237. },
  238. };
  239. static const struct hda_pcm_stream conexant_pcm_digital_playback = {
  240. .substreams = 1,
  241. .channels_min = 2,
  242. .channels_max = 2,
  243. .nid = 0, /* fill later */
  244. .ops = {
  245. .open = conexant_dig_playback_pcm_open,
  246. .close = conexant_dig_playback_pcm_close,
  247. .prepare = conexant_dig_playback_pcm_prepare
  248. },
  249. };
  250. static const struct hda_pcm_stream conexant_pcm_digital_capture = {
  251. .substreams = 1,
  252. .channels_min = 2,
  253. .channels_max = 2,
  254. /* NID is set in alc_build_pcms */
  255. };
  256. static int cx5051_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  257. struct hda_codec *codec,
  258. unsigned int stream_tag,
  259. unsigned int format,
  260. struct snd_pcm_substream *substream)
  261. {
  262. struct conexant_spec *spec = codec->spec;
  263. spec->cur_adc = spec->adc_nids[spec->cur_adc_idx];
  264. spec->cur_adc_stream_tag = stream_tag;
  265. spec->cur_adc_format = format;
  266. snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
  267. return 0;
  268. }
  269. static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  270. struct hda_codec *codec,
  271. struct snd_pcm_substream *substream)
  272. {
  273. struct conexant_spec *spec = codec->spec;
  274. snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
  275. spec->cur_adc = 0;
  276. return 0;
  277. }
  278. static const struct hda_pcm_stream cx5051_pcm_analog_capture = {
  279. .substreams = 1,
  280. .channels_min = 2,
  281. .channels_max = 2,
  282. .nid = 0, /* fill later */
  283. .ops = {
  284. .prepare = cx5051_capture_pcm_prepare,
  285. .cleanup = cx5051_capture_pcm_cleanup
  286. },
  287. };
  288. static int conexant_build_pcms(struct hda_codec *codec)
  289. {
  290. struct conexant_spec *spec = codec->spec;
  291. struct hda_pcm *info = spec->pcm_rec;
  292. codec->num_pcms = 1;
  293. codec->pcm_info = info;
  294. info->name = "CONEXANT Analog";
  295. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = conexant_pcm_analog_playback;
  296. info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
  297. spec->multiout.max_channels;
  298. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  299. spec->multiout.dac_nids[0];
  300. if (spec->capture_stream)
  301. info->stream[SNDRV_PCM_STREAM_CAPTURE] = *spec->capture_stream;
  302. else {
  303. if (codec->vendor_id == 0x14f15051)
  304. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  305. cx5051_pcm_analog_capture;
  306. else {
  307. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  308. conexant_pcm_analog_capture;
  309. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
  310. spec->num_adc_nids;
  311. }
  312. }
  313. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  314. if (spec->multiout.dig_out_nid) {
  315. info++;
  316. codec->num_pcms++;
  317. info->name = "Conexant Digital";
  318. info->pcm_type = HDA_PCM_TYPE_SPDIF;
  319. info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
  320. conexant_pcm_digital_playback;
  321. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
  322. spec->multiout.dig_out_nid;
  323. if (spec->dig_in_nid) {
  324. info->stream[SNDRV_PCM_STREAM_CAPTURE] =
  325. conexant_pcm_digital_capture;
  326. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
  327. spec->dig_in_nid;
  328. }
  329. if (spec->slave_dig_outs[0])
  330. codec->slave_dig_outs = spec->slave_dig_outs;
  331. }
  332. return 0;
  333. }
  334. static int conexant_mux_enum_info(struct snd_kcontrol *kcontrol,
  335. struct snd_ctl_elem_info *uinfo)
  336. {
  337. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  338. struct conexant_spec *spec = codec->spec;
  339. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  340. }
  341. static int conexant_mux_enum_get(struct snd_kcontrol *kcontrol,
  342. struct snd_ctl_elem_value *ucontrol)
  343. {
  344. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  345. struct conexant_spec *spec = codec->spec;
  346. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  347. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  348. return 0;
  349. }
  350. static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
  351. struct snd_ctl_elem_value *ucontrol)
  352. {
  353. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  354. struct conexant_spec *spec = codec->spec;
  355. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  356. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  357. spec->capsrc_nids[adc_idx],
  358. &spec->cur_mux[adc_idx]);
  359. }
  360. static int conexant_init_jacks(struct hda_codec *codec)
  361. {
  362. #ifdef CONFIG_SND_HDA_INPUT_JACK
  363. struct conexant_spec *spec = codec->spec;
  364. int i;
  365. for (i = 0; i < spec->num_init_verbs; i++) {
  366. const struct hda_verb *hv;
  367. hv = spec->init_verbs[i];
  368. while (hv->nid) {
  369. int err = 0;
  370. switch (hv->param ^ AC_USRSP_EN) {
  371. case CONEXANT_HP_EVENT:
  372. err = snd_hda_input_jack_add(codec, hv->nid,
  373. SND_JACK_HEADPHONE, NULL);
  374. snd_hda_input_jack_report(codec, hv->nid);
  375. break;
  376. case CXT5051_PORTC_EVENT:
  377. case CONEXANT_MIC_EVENT:
  378. err = snd_hda_input_jack_add(codec, hv->nid,
  379. SND_JACK_MICROPHONE, NULL);
  380. snd_hda_input_jack_report(codec, hv->nid);
  381. break;
  382. }
  383. if (err < 0)
  384. return err;
  385. ++hv;
  386. }
  387. }
  388. #endif /* CONFIG_SND_HDA_INPUT_JACK */
  389. return 0;
  390. }
  391. static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
  392. unsigned int power_state)
  393. {
  394. if (power_state == AC_PWRST_D3)
  395. msleep(100);
  396. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
  397. power_state);
  398. /* partial workaround for "azx_get_response timeout" */
  399. if (power_state == AC_PWRST_D0)
  400. msleep(10);
  401. snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
  402. }
  403. static int conexant_init(struct hda_codec *codec)
  404. {
  405. struct conexant_spec *spec = codec->spec;
  406. int i;
  407. for (i = 0; i < spec->num_init_verbs; i++)
  408. snd_hda_sequence_write(codec, spec->init_verbs[i]);
  409. return 0;
  410. }
  411. static void conexant_free(struct hda_codec *codec)
  412. {
  413. snd_hda_input_jack_free(codec);
  414. snd_hda_detach_beep_device(codec);
  415. kfree(codec->spec);
  416. }
  417. static const struct snd_kcontrol_new cxt_capture_mixers[] = {
  418. {
  419. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  420. .name = "Capture Source",
  421. .info = conexant_mux_enum_info,
  422. .get = conexant_mux_enum_get,
  423. .put = conexant_mux_enum_put
  424. },
  425. {}
  426. };
  427. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  428. /* additional beep mixers; the actual parameters are overwritten at build */
  429. static const struct snd_kcontrol_new cxt_beep_mixer[] = {
  430. HDA_CODEC_VOLUME_MONO("Beep Playback Volume", 0, 1, 0, HDA_OUTPUT),
  431. HDA_CODEC_MUTE_BEEP_MONO("Beep Playback Switch", 0, 1, 0, HDA_OUTPUT),
  432. { } /* end */
  433. };
  434. #endif
  435. static const char * const slave_vols[] = {
  436. "Headphone Playback Volume",
  437. "Speaker Playback Volume",
  438. "Front Playback Volume",
  439. "Surround Playback Volume",
  440. "CLFE Playback Volume",
  441. NULL
  442. };
  443. static const char * const slave_sws[] = {
  444. "Headphone Playback Switch",
  445. "Speaker Playback Switch",
  446. "Front Playback Switch",
  447. "Surround Playback Switch",
  448. "CLFE Playback Switch",
  449. NULL
  450. };
  451. static int conexant_build_controls(struct hda_codec *codec)
  452. {
  453. struct conexant_spec *spec = codec->spec;
  454. unsigned int i;
  455. int err;
  456. for (i = 0; i < spec->num_mixers; i++) {
  457. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  458. if (err < 0)
  459. return err;
  460. }
  461. if (spec->multiout.dig_out_nid) {
  462. err = snd_hda_create_spdif_out_ctls(codec,
  463. spec->multiout.dig_out_nid,
  464. spec->multiout.dig_out_nid);
  465. if (err < 0)
  466. return err;
  467. err = snd_hda_create_spdif_share_sw(codec,
  468. &spec->multiout);
  469. if (err < 0)
  470. return err;
  471. spec->multiout.share_spdif = 1;
  472. }
  473. if (spec->dig_in_nid) {
  474. err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
  475. if (err < 0)
  476. return err;
  477. }
  478. /* if we have no master control, let's create it */
  479. if (spec->vmaster_nid &&
  480. !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
  481. unsigned int vmaster_tlv[4];
  482. snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
  483. HDA_OUTPUT, vmaster_tlv);
  484. err = snd_hda_add_vmaster(codec, "Master Playback Volume",
  485. vmaster_tlv, slave_vols);
  486. if (err < 0)
  487. return err;
  488. }
  489. if (spec->vmaster_nid &&
  490. !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
  491. err = snd_hda_add_vmaster(codec, "Master Playback Switch",
  492. NULL, slave_sws);
  493. if (err < 0)
  494. return err;
  495. }
  496. if (spec->input_mux) {
  497. err = snd_hda_add_new_ctls(codec, cxt_capture_mixers);
  498. if (err < 0)
  499. return err;
  500. }
  501. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  502. /* create beep controls if needed */
  503. if (spec->beep_amp) {
  504. const struct snd_kcontrol_new *knew;
  505. for (knew = cxt_beep_mixer; knew->name; knew++) {
  506. struct snd_kcontrol *kctl;
  507. kctl = snd_ctl_new1(knew, codec);
  508. if (!kctl)
  509. return -ENOMEM;
  510. kctl->private_value = spec->beep_amp;
  511. err = snd_hda_ctl_add(codec, 0, kctl);
  512. if (err < 0)
  513. return err;
  514. }
  515. }
  516. #endif
  517. return 0;
  518. }
  519. #ifdef CONFIG_SND_HDA_POWER_SAVE
  520. static int conexant_suspend(struct hda_codec *codec, pm_message_t state)
  521. {
  522. snd_hda_shutup_pins(codec);
  523. return 0;
  524. }
  525. #endif
  526. static const struct hda_codec_ops conexant_patch_ops = {
  527. .build_controls = conexant_build_controls,
  528. .build_pcms = conexant_build_pcms,
  529. .init = conexant_init,
  530. .free = conexant_free,
  531. .set_power_state = conexant_set_power,
  532. #ifdef CONFIG_SND_HDA_POWER_SAVE
  533. .suspend = conexant_suspend,
  534. #endif
  535. .reboot_notify = snd_hda_shutup_pins,
  536. };
  537. #ifdef CONFIG_SND_HDA_INPUT_BEEP
  538. #define set_beep_amp(spec, nid, idx, dir) \
  539. ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 1, idx, dir))
  540. #else
  541. #define set_beep_amp(spec, nid, idx, dir) /* NOP */
  542. #endif
  543. static int patch_conexant_auto(struct hda_codec *codec);
  544. /*
  545. * EAPD control
  546. * the private value = nid | (invert << 8)
  547. */
  548. #define cxt_eapd_info snd_ctl_boolean_mono_info
  549. static int cxt_eapd_get(struct snd_kcontrol *kcontrol,
  550. struct snd_ctl_elem_value *ucontrol)
  551. {
  552. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  553. struct conexant_spec *spec = codec->spec;
  554. int invert = (kcontrol->private_value >> 8) & 1;
  555. if (invert)
  556. ucontrol->value.integer.value[0] = !spec->cur_eapd;
  557. else
  558. ucontrol->value.integer.value[0] = spec->cur_eapd;
  559. return 0;
  560. }
  561. static int cxt_eapd_put(struct snd_kcontrol *kcontrol,
  562. struct snd_ctl_elem_value *ucontrol)
  563. {
  564. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  565. struct conexant_spec *spec = codec->spec;
  566. int invert = (kcontrol->private_value >> 8) & 1;
  567. hda_nid_t nid = kcontrol->private_value & 0xff;
  568. unsigned int eapd;
  569. eapd = !!ucontrol->value.integer.value[0];
  570. if (invert)
  571. eapd = !eapd;
  572. if (eapd == spec->cur_eapd)
  573. return 0;
  574. spec->cur_eapd = eapd;
  575. snd_hda_codec_write_cache(codec, nid,
  576. 0, AC_VERB_SET_EAPD_BTLENABLE,
  577. eapd ? 0x02 : 0x00);
  578. return 1;
  579. }
  580. /* controls for test mode */
  581. #ifdef CONFIG_SND_DEBUG
  582. #define CXT_EAPD_SWITCH(xname, nid, mask) \
  583. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  584. .info = cxt_eapd_info, \
  585. .get = cxt_eapd_get, \
  586. .put = cxt_eapd_put, \
  587. .private_value = nid | (mask<<16) }
  588. static int conexant_ch_mode_info(struct snd_kcontrol *kcontrol,
  589. struct snd_ctl_elem_info *uinfo)
  590. {
  591. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  592. struct conexant_spec *spec = codec->spec;
  593. return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
  594. spec->num_channel_mode);
  595. }
  596. static int conexant_ch_mode_get(struct snd_kcontrol *kcontrol,
  597. struct snd_ctl_elem_value *ucontrol)
  598. {
  599. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  600. struct conexant_spec *spec = codec->spec;
  601. return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
  602. spec->num_channel_mode,
  603. spec->multiout.max_channels);
  604. }
  605. static int conexant_ch_mode_put(struct snd_kcontrol *kcontrol,
  606. struct snd_ctl_elem_value *ucontrol)
  607. {
  608. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  609. struct conexant_spec *spec = codec->spec;
  610. int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
  611. spec->num_channel_mode,
  612. &spec->multiout.max_channels);
  613. if (err >= 0 && spec->need_dac_fix)
  614. spec->multiout.num_dacs = spec->multiout.max_channels / 2;
  615. return err;
  616. }
  617. #define CXT_PIN_MODE(xname, nid, dir) \
  618. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = 0, \
  619. .info = conexant_ch_mode_info, \
  620. .get = conexant_ch_mode_get, \
  621. .put = conexant_ch_mode_put, \
  622. .private_value = nid | (dir<<16) }
  623. #endif /* CONFIG_SND_DEBUG */
  624. /* Conexant 5045 specific */
  625. static const hda_nid_t cxt5045_dac_nids[1] = { 0x19 };
  626. static const hda_nid_t cxt5045_adc_nids[1] = { 0x1a };
  627. static const hda_nid_t cxt5045_capsrc_nids[1] = { 0x1a };
  628. #define CXT5045_SPDIF_OUT 0x18
  629. static const struct hda_channel_mode cxt5045_modes[1] = {
  630. { 2, NULL },
  631. };
  632. static const struct hda_input_mux cxt5045_capture_source = {
  633. .num_items = 2,
  634. .items = {
  635. { "IntMic", 0x1 },
  636. { "ExtMic", 0x2 },
  637. }
  638. };
  639. static const struct hda_input_mux cxt5045_capture_source_benq = {
  640. .num_items = 5,
  641. .items = {
  642. { "IntMic", 0x1 },
  643. { "ExtMic", 0x2 },
  644. { "LineIn", 0x3 },
  645. { "CD", 0x4 },
  646. { "Mixer", 0x0 },
  647. }
  648. };
  649. static const struct hda_input_mux cxt5045_capture_source_hp530 = {
  650. .num_items = 2,
  651. .items = {
  652. { "ExtMic", 0x1 },
  653. { "IntMic", 0x2 },
  654. }
  655. };
  656. /* turn on/off EAPD (+ mute HP) as a master switch */
  657. static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  658. struct snd_ctl_elem_value *ucontrol)
  659. {
  660. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  661. struct conexant_spec *spec = codec->spec;
  662. unsigned int bits;
  663. if (!cxt_eapd_put(kcontrol, ucontrol))
  664. return 0;
  665. /* toggle internal speakers mute depending of presence of
  666. * the headphone jack
  667. */
  668. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  669. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  670. HDA_AMP_MUTE, bits);
  671. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  672. snd_hda_codec_amp_stereo(codec, 0x11, HDA_OUTPUT, 0,
  673. HDA_AMP_MUTE, bits);
  674. return 1;
  675. }
  676. /* bind volumes of both NID 0x10 and 0x11 */
  677. static const struct hda_bind_ctls cxt5045_hp_bind_master_vol = {
  678. .ops = &snd_hda_bind_vol,
  679. .values = {
  680. HDA_COMPOSE_AMP_VAL(0x10, 3, 0, HDA_OUTPUT),
  681. HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
  682. 0
  683. },
  684. };
  685. /* toggle input of built-in and mic jack appropriately */
  686. static void cxt5045_hp_automic(struct hda_codec *codec)
  687. {
  688. static const struct hda_verb mic_jack_on[] = {
  689. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  690. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  691. {}
  692. };
  693. static const struct hda_verb mic_jack_off[] = {
  694. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080},
  695. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  696. {}
  697. };
  698. unsigned int present;
  699. present = snd_hda_jack_detect(codec, 0x12);
  700. if (present)
  701. snd_hda_sequence_write(codec, mic_jack_on);
  702. else
  703. snd_hda_sequence_write(codec, mic_jack_off);
  704. }
  705. /* mute internal speaker if HP is plugged */
  706. static void cxt5045_hp_automute(struct hda_codec *codec)
  707. {
  708. struct conexant_spec *spec = codec->spec;
  709. unsigned int bits;
  710. spec->hp_present = snd_hda_jack_detect(codec, 0x11);
  711. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  712. snd_hda_codec_amp_stereo(codec, 0x10, HDA_OUTPUT, 0,
  713. HDA_AMP_MUTE, bits);
  714. }
  715. /* unsolicited event for HP jack sensing */
  716. static void cxt5045_hp_unsol_event(struct hda_codec *codec,
  717. unsigned int res)
  718. {
  719. res >>= 26;
  720. switch (res) {
  721. case CONEXANT_HP_EVENT:
  722. cxt5045_hp_automute(codec);
  723. break;
  724. case CONEXANT_MIC_EVENT:
  725. cxt5045_hp_automic(codec);
  726. break;
  727. }
  728. }
  729. static const struct snd_kcontrol_new cxt5045_mixers[] = {
  730. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  731. HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  732. HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  733. HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  734. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  735. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  736. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  737. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  738. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  739. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  740. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  741. {
  742. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  743. .name = "Master Playback Switch",
  744. .info = cxt_eapd_info,
  745. .get = cxt_eapd_get,
  746. .put = cxt5045_hp_master_sw_put,
  747. .private_value = 0x10,
  748. },
  749. {}
  750. };
  751. static const struct snd_kcontrol_new cxt5045_benq_mixers[] = {
  752. HDA_CODEC_VOLUME("CD Capture Volume", 0x1a, 0x04, HDA_INPUT),
  753. HDA_CODEC_MUTE("CD Capture Switch", 0x1a, 0x04, HDA_INPUT),
  754. HDA_CODEC_VOLUME("CD Playback Volume", 0x17, 0x4, HDA_INPUT),
  755. HDA_CODEC_MUTE("CD Playback Switch", 0x17, 0x4, HDA_INPUT),
  756. HDA_CODEC_VOLUME("Line In Capture Volume", 0x1a, 0x03, HDA_INPUT),
  757. HDA_CODEC_MUTE("Line In Capture Switch", 0x1a, 0x03, HDA_INPUT),
  758. HDA_CODEC_VOLUME("Line In Playback Volume", 0x17, 0x3, HDA_INPUT),
  759. HDA_CODEC_MUTE("Line In Playback Switch", 0x17, 0x3, HDA_INPUT),
  760. HDA_CODEC_VOLUME("Mixer Capture Volume", 0x1a, 0x0, HDA_INPUT),
  761. HDA_CODEC_MUTE("Mixer Capture Switch", 0x1a, 0x0, HDA_INPUT),
  762. {}
  763. };
  764. static const struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
  765. HDA_CODEC_VOLUME("Internal Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
  766. HDA_CODEC_MUTE("Internal Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
  767. HDA_CODEC_VOLUME("Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
  768. HDA_CODEC_MUTE("Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
  769. HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
  770. HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
  771. HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
  772. HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
  773. HDA_CODEC_VOLUME("Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
  774. HDA_CODEC_MUTE("Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
  775. HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
  776. {
  777. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  778. .name = "Master Playback Switch",
  779. .info = cxt_eapd_info,
  780. .get = cxt_eapd_get,
  781. .put = cxt5045_hp_master_sw_put,
  782. .private_value = 0x10,
  783. },
  784. {}
  785. };
  786. static const struct hda_verb cxt5045_init_verbs[] = {
  787. /* Line in, Mic */
  788. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  789. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  790. /* HP, Amp */
  791. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  792. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  793. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  794. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  795. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  796. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  797. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  798. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  799. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  800. /* Record selector: Internal mic */
  801. {0x1a, AC_VERB_SET_CONNECT_SEL,0x1},
  802. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  803. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  804. /* SPDIF route: PCM */
  805. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  806. { 0x13, AC_VERB_SET_CONNECT_SEL, 0x0 },
  807. /* EAPD */
  808. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2 }, /* default on */
  809. { } /* end */
  810. };
  811. static const struct hda_verb cxt5045_benq_init_verbs[] = {
  812. /* Internal Mic, Mic */
  813. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  814. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_80 },
  815. /* Line In,HP, Amp */
  816. {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  817. {0x10, AC_VERB_SET_CONNECT_SEL, 0x1},
  818. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  819. {0x11, AC_VERB_SET_CONNECT_SEL, 0x1},
  820. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  821. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  822. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  823. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  824. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  825. /* Record selector: Internal mic */
  826. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x1},
  827. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE,
  828. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  829. /* SPDIF route: PCM */
  830. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  831. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0},
  832. /* EAPD */
  833. {0x10, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  834. { } /* end */
  835. };
  836. static const struct hda_verb cxt5045_hp_sense_init_verbs[] = {
  837. /* pin sensing on HP jack */
  838. {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  839. { } /* end */
  840. };
  841. static const struct hda_verb cxt5045_mic_sense_init_verbs[] = {
  842. /* pin sensing on HP jack */
  843. {0x12, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  844. { } /* end */
  845. };
  846. #ifdef CONFIG_SND_DEBUG
  847. /* Test configuration for debugging, modelled after the ALC260 test
  848. * configuration.
  849. */
  850. static const struct hda_input_mux cxt5045_test_capture_source = {
  851. .num_items = 5,
  852. .items = {
  853. { "MIXER", 0x0 },
  854. { "MIC1 pin", 0x1 },
  855. { "LINE1 pin", 0x2 },
  856. { "HP-OUT pin", 0x3 },
  857. { "CD pin", 0x4 },
  858. },
  859. };
  860. static const struct snd_kcontrol_new cxt5045_test_mixer[] = {
  861. /* Output controls */
  862. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x10, 0x0, HDA_OUTPUT),
  863. HDA_CODEC_MUTE("Speaker Playback Switch", 0x10, 0x0, HDA_OUTPUT),
  864. HDA_CODEC_VOLUME("Node 11 Playback Volume", 0x11, 0x0, HDA_OUTPUT),
  865. HDA_CODEC_MUTE("Node 11 Playback Switch", 0x11, 0x0, HDA_OUTPUT),
  866. HDA_CODEC_VOLUME("Node 12 Playback Volume", 0x12, 0x0, HDA_OUTPUT),
  867. HDA_CODEC_MUTE("Node 12 Playback Switch", 0x12, 0x0, HDA_OUTPUT),
  868. /* Modes for retasking pin widgets */
  869. CXT_PIN_MODE("HP-OUT pin mode", 0x11, CXT_PIN_DIR_INOUT),
  870. CXT_PIN_MODE("LINE1 pin mode", 0x12, CXT_PIN_DIR_INOUT),
  871. /* EAPD Switch Control */
  872. CXT_EAPD_SWITCH("External Amplifier", 0x10, 0x0),
  873. /* Loopback mixer controls */
  874. HDA_CODEC_VOLUME("Mixer-1 Volume", 0x17, 0x0, HDA_INPUT),
  875. HDA_CODEC_MUTE("Mixer-1 Switch", 0x17, 0x0, HDA_INPUT),
  876. HDA_CODEC_VOLUME("Mixer-2 Volume", 0x17, 0x1, HDA_INPUT),
  877. HDA_CODEC_MUTE("Mixer-2 Switch", 0x17, 0x1, HDA_INPUT),
  878. HDA_CODEC_VOLUME("Mixer-3 Volume", 0x17, 0x2, HDA_INPUT),
  879. HDA_CODEC_MUTE("Mixer-3 Switch", 0x17, 0x2, HDA_INPUT),
  880. HDA_CODEC_VOLUME("Mixer-4 Volume", 0x17, 0x3, HDA_INPUT),
  881. HDA_CODEC_MUTE("Mixer-4 Switch", 0x17, 0x3, HDA_INPUT),
  882. HDA_CODEC_VOLUME("Mixer-5 Volume", 0x17, 0x4, HDA_INPUT),
  883. HDA_CODEC_MUTE("Mixer-5 Switch", 0x17, 0x4, HDA_INPUT),
  884. {
  885. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  886. .name = "Input Source",
  887. .info = conexant_mux_enum_info,
  888. .get = conexant_mux_enum_get,
  889. .put = conexant_mux_enum_put,
  890. },
  891. /* Audio input controls */
  892. HDA_CODEC_VOLUME("Input-1 Volume", 0x1a, 0x0, HDA_INPUT),
  893. HDA_CODEC_MUTE("Input-1 Switch", 0x1a, 0x0, HDA_INPUT),
  894. HDA_CODEC_VOLUME("Input-2 Volume", 0x1a, 0x1, HDA_INPUT),
  895. HDA_CODEC_MUTE("Input-2 Switch", 0x1a, 0x1, HDA_INPUT),
  896. HDA_CODEC_VOLUME("Input-3 Volume", 0x1a, 0x2, HDA_INPUT),
  897. HDA_CODEC_MUTE("Input-3 Switch", 0x1a, 0x2, HDA_INPUT),
  898. HDA_CODEC_VOLUME("Input-4 Volume", 0x1a, 0x3, HDA_INPUT),
  899. HDA_CODEC_MUTE("Input-4 Switch", 0x1a, 0x3, HDA_INPUT),
  900. HDA_CODEC_VOLUME("Input-5 Volume", 0x1a, 0x4, HDA_INPUT),
  901. HDA_CODEC_MUTE("Input-5 Switch", 0x1a, 0x4, HDA_INPUT),
  902. { } /* end */
  903. };
  904. static const struct hda_verb cxt5045_test_init_verbs[] = {
  905. /* Set connections */
  906. { 0x10, AC_VERB_SET_CONNECT_SEL, 0x0 },
  907. { 0x11, AC_VERB_SET_CONNECT_SEL, 0x0 },
  908. { 0x12, AC_VERB_SET_CONNECT_SEL, 0x0 },
  909. /* Enable retasking pins as output, initially without power amp */
  910. {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  911. {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  912. /* Disable digital (SPDIF) pins initially, but users can enable
  913. * them via a mixer switch. In the case of SPDIF-out, this initverb
  914. * payload also sets the generation to 0, output to be in "consumer"
  915. * PCM format, copyright asserted, no pre-emphasis and no validity
  916. * control.
  917. */
  918. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  919. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  920. /* Start with output sum widgets muted and their output gains at min */
  921. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  922. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  923. /* Unmute retasking pin widget output buffers since the default
  924. * state appears to be output. As the pin mode is changed by the
  925. * user the pin mode control will take care of enabling the pin's
  926. * input/output buffers as needed.
  927. */
  928. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  929. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  930. /* Mute capture amp left and right */
  931. {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  932. /* Set ADC connection select to match default mixer setting (mic1
  933. * pin)
  934. */
  935. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  936. {0x17, AC_VERB_SET_CONNECT_SEL, 0x00},
  937. /* Mute all inputs to mixer widget (even unconnected ones) */
  938. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* Mixer pin */
  939. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* Mic1 pin */
  940. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* Line pin */
  941. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* HP pin */
  942. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  943. { }
  944. };
  945. #endif
  946. /* initialize jack-sensing, too */
  947. static int cxt5045_init(struct hda_codec *codec)
  948. {
  949. conexant_init(codec);
  950. cxt5045_hp_automute(codec);
  951. return 0;
  952. }
  953. enum {
  954. CXT5045_LAPTOP_HPSENSE,
  955. CXT5045_LAPTOP_MICSENSE,
  956. CXT5045_LAPTOP_HPMICSENSE,
  957. CXT5045_BENQ,
  958. CXT5045_LAPTOP_HP530,
  959. #ifdef CONFIG_SND_DEBUG
  960. CXT5045_TEST,
  961. #endif
  962. CXT5045_AUTO,
  963. CXT5045_MODELS
  964. };
  965. static const char * const cxt5045_models[CXT5045_MODELS] = {
  966. [CXT5045_LAPTOP_HPSENSE] = "laptop-hpsense",
  967. [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
  968. [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
  969. [CXT5045_BENQ] = "benq",
  970. [CXT5045_LAPTOP_HP530] = "laptop-hp530",
  971. #ifdef CONFIG_SND_DEBUG
  972. [CXT5045_TEST] = "test",
  973. #endif
  974. [CXT5045_AUTO] = "auto",
  975. };
  976. static const struct snd_pci_quirk cxt5045_cfg_tbl[] = {
  977. SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
  978. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  979. CXT5045_LAPTOP_HPSENSE),
  980. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P105", CXT5045_LAPTOP_MICSENSE),
  981. SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
  982. SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
  983. SND_PCI_QUIRK(0x1734, 0x10cb, "Fujitsu Si3515", CXT5045_LAPTOP_HPMICSENSE),
  984. SND_PCI_QUIRK(0x1734, 0x110e, "Fujitsu V5505",
  985. CXT5045_LAPTOP_HPMICSENSE),
  986. SND_PCI_QUIRK(0x1509, 0x1e40, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  987. SND_PCI_QUIRK(0x1509, 0x2f05, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  988. SND_PCI_QUIRK(0x1509, 0x2f06, "FIC", CXT5045_LAPTOP_HPMICSENSE),
  989. SND_PCI_QUIRK_MASK(0x1631, 0xff00, 0xc100, "Packard Bell",
  990. CXT5045_LAPTOP_HPMICSENSE),
  991. SND_PCI_QUIRK(0x8086, 0x2111, "Conexant Reference board", CXT5045_LAPTOP_HPSENSE),
  992. {}
  993. };
  994. static int patch_cxt5045(struct hda_codec *codec)
  995. {
  996. struct conexant_spec *spec;
  997. int board_config;
  998. board_config = snd_hda_check_board_config(codec, CXT5045_MODELS,
  999. cxt5045_models,
  1000. cxt5045_cfg_tbl);
  1001. if (board_config < 0)
  1002. board_config = CXT5045_AUTO; /* model=auto as default */
  1003. if (board_config == CXT5045_AUTO)
  1004. return patch_conexant_auto(codec);
  1005. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1006. if (!spec)
  1007. return -ENOMEM;
  1008. codec->spec = spec;
  1009. codec->pin_amp_workaround = 1;
  1010. spec->multiout.max_channels = 2;
  1011. spec->multiout.num_dacs = ARRAY_SIZE(cxt5045_dac_nids);
  1012. spec->multiout.dac_nids = cxt5045_dac_nids;
  1013. spec->multiout.dig_out_nid = CXT5045_SPDIF_OUT;
  1014. spec->num_adc_nids = 1;
  1015. spec->adc_nids = cxt5045_adc_nids;
  1016. spec->capsrc_nids = cxt5045_capsrc_nids;
  1017. spec->input_mux = &cxt5045_capture_source;
  1018. spec->num_mixers = 1;
  1019. spec->mixers[0] = cxt5045_mixers;
  1020. spec->num_init_verbs = 1;
  1021. spec->init_verbs[0] = cxt5045_init_verbs;
  1022. spec->spdif_route = 0;
  1023. spec->num_channel_mode = ARRAY_SIZE(cxt5045_modes);
  1024. spec->channel_mode = cxt5045_modes;
  1025. set_beep_amp(spec, 0x16, 0, 1);
  1026. codec->patch_ops = conexant_patch_ops;
  1027. switch (board_config) {
  1028. case CXT5045_LAPTOP_HPSENSE:
  1029. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1030. spec->input_mux = &cxt5045_capture_source;
  1031. spec->num_init_verbs = 2;
  1032. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1033. spec->mixers[0] = cxt5045_mixers;
  1034. codec->patch_ops.init = cxt5045_init;
  1035. break;
  1036. case CXT5045_LAPTOP_MICSENSE:
  1037. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1038. spec->input_mux = &cxt5045_capture_source;
  1039. spec->num_init_verbs = 2;
  1040. spec->init_verbs[1] = cxt5045_mic_sense_init_verbs;
  1041. spec->mixers[0] = cxt5045_mixers;
  1042. codec->patch_ops.init = cxt5045_init;
  1043. break;
  1044. default:
  1045. case CXT5045_LAPTOP_HPMICSENSE:
  1046. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1047. spec->input_mux = &cxt5045_capture_source;
  1048. spec->num_init_verbs = 3;
  1049. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1050. spec->init_verbs[2] = cxt5045_mic_sense_init_verbs;
  1051. spec->mixers[0] = cxt5045_mixers;
  1052. codec->patch_ops.init = cxt5045_init;
  1053. break;
  1054. case CXT5045_BENQ:
  1055. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1056. spec->input_mux = &cxt5045_capture_source_benq;
  1057. spec->num_init_verbs = 1;
  1058. spec->init_verbs[0] = cxt5045_benq_init_verbs;
  1059. spec->mixers[0] = cxt5045_mixers;
  1060. spec->mixers[1] = cxt5045_benq_mixers;
  1061. spec->num_mixers = 2;
  1062. codec->patch_ops.init = cxt5045_init;
  1063. break;
  1064. case CXT5045_LAPTOP_HP530:
  1065. codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
  1066. spec->input_mux = &cxt5045_capture_source_hp530;
  1067. spec->num_init_verbs = 2;
  1068. spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
  1069. spec->mixers[0] = cxt5045_mixers_hp530;
  1070. codec->patch_ops.init = cxt5045_init;
  1071. break;
  1072. #ifdef CONFIG_SND_DEBUG
  1073. case CXT5045_TEST:
  1074. spec->input_mux = &cxt5045_test_capture_source;
  1075. spec->mixers[0] = cxt5045_test_mixer;
  1076. spec->init_verbs[0] = cxt5045_test_init_verbs;
  1077. break;
  1078. #endif
  1079. }
  1080. switch (codec->subsystem_id >> 16) {
  1081. case 0x103c:
  1082. case 0x1631:
  1083. case 0x1734:
  1084. case 0x17aa:
  1085. /* HP, Packard Bell, Fujitsu-Siemens & Lenovo laptops have
  1086. * really bad sound over 0dB on NID 0x17. Fix max PCM level to
  1087. * 0 dB (originally it has 0x2b steps with 0dB offset 0x14)
  1088. */
  1089. snd_hda_override_amp_caps(codec, 0x17, HDA_INPUT,
  1090. (0x14 << AC_AMPCAP_OFFSET_SHIFT) |
  1091. (0x14 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1092. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1093. (1 << AC_AMPCAP_MUTE_SHIFT));
  1094. break;
  1095. }
  1096. if (spec->beep_amp)
  1097. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1098. return 0;
  1099. }
  1100. /* Conexant 5047 specific */
  1101. #define CXT5047_SPDIF_OUT 0x11
  1102. static const hda_nid_t cxt5047_dac_nids[1] = { 0x10 }; /* 0x1c */
  1103. static const hda_nid_t cxt5047_adc_nids[1] = { 0x12 };
  1104. static const hda_nid_t cxt5047_capsrc_nids[1] = { 0x1a };
  1105. static const struct hda_channel_mode cxt5047_modes[1] = {
  1106. { 2, NULL },
  1107. };
  1108. static const struct hda_input_mux cxt5047_toshiba_capture_source = {
  1109. .num_items = 2,
  1110. .items = {
  1111. { "ExtMic", 0x2 },
  1112. { "Line-In", 0x1 },
  1113. }
  1114. };
  1115. /* turn on/off EAPD (+ mute HP) as a master switch */
  1116. static int cxt5047_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1117. struct snd_ctl_elem_value *ucontrol)
  1118. {
  1119. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1120. struct conexant_spec *spec = codec->spec;
  1121. unsigned int bits;
  1122. if (!cxt_eapd_put(kcontrol, ucontrol))
  1123. return 0;
  1124. /* toggle internal speakers mute depending of presence of
  1125. * the headphone jack
  1126. */
  1127. bits = (!spec->hp_present && spec->cur_eapd) ? 0 : HDA_AMP_MUTE;
  1128. /* NOTE: Conexat codec needs the index for *OUTPUT* amp of
  1129. * pin widgets unlike other codecs. In this case, we need to
  1130. * set index 0x01 for the volume from the mixer amp 0x19.
  1131. */
  1132. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1133. HDA_AMP_MUTE, bits);
  1134. bits = spec->cur_eapd ? 0 : HDA_AMP_MUTE;
  1135. snd_hda_codec_amp_stereo(codec, 0x13, HDA_OUTPUT, 0,
  1136. HDA_AMP_MUTE, bits);
  1137. return 1;
  1138. }
  1139. /* mute internal speaker if HP is plugged */
  1140. static void cxt5047_hp_automute(struct hda_codec *codec)
  1141. {
  1142. struct conexant_spec *spec = codec->spec;
  1143. unsigned int bits;
  1144. spec->hp_present = snd_hda_jack_detect(codec, 0x13);
  1145. bits = (spec->hp_present || !spec->cur_eapd) ? HDA_AMP_MUTE : 0;
  1146. /* See the note in cxt5047_hp_master_sw_put */
  1147. snd_hda_codec_amp_stereo(codec, 0x1d, HDA_OUTPUT, 0x01,
  1148. HDA_AMP_MUTE, bits);
  1149. }
  1150. /* toggle input of built-in and mic jack appropriately */
  1151. static void cxt5047_hp_automic(struct hda_codec *codec)
  1152. {
  1153. static const struct hda_verb mic_jack_on[] = {
  1154. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1155. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1156. {}
  1157. };
  1158. static const struct hda_verb mic_jack_off[] = {
  1159. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  1160. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1161. {}
  1162. };
  1163. unsigned int present;
  1164. present = snd_hda_jack_detect(codec, 0x15);
  1165. if (present)
  1166. snd_hda_sequence_write(codec, mic_jack_on);
  1167. else
  1168. snd_hda_sequence_write(codec, mic_jack_off);
  1169. }
  1170. /* unsolicited event for HP jack sensing */
  1171. static void cxt5047_hp_unsol_event(struct hda_codec *codec,
  1172. unsigned int res)
  1173. {
  1174. switch (res >> 26) {
  1175. case CONEXANT_HP_EVENT:
  1176. cxt5047_hp_automute(codec);
  1177. break;
  1178. case CONEXANT_MIC_EVENT:
  1179. cxt5047_hp_automic(codec);
  1180. break;
  1181. }
  1182. }
  1183. static const struct snd_kcontrol_new cxt5047_base_mixers[] = {
  1184. HDA_CODEC_VOLUME("Mic Playback Volume", 0x19, 0x02, HDA_INPUT),
  1185. HDA_CODEC_MUTE("Mic Playback Switch", 0x19, 0x02, HDA_INPUT),
  1186. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1187. HDA_CODEC_VOLUME("Capture Volume", 0x12, 0x03, HDA_INPUT),
  1188. HDA_CODEC_MUTE("Capture Switch", 0x12, 0x03, HDA_INPUT),
  1189. HDA_CODEC_VOLUME("PCM Volume", 0x10, 0x00, HDA_OUTPUT),
  1190. HDA_CODEC_MUTE("PCM Switch", 0x10, 0x00, HDA_OUTPUT),
  1191. {
  1192. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1193. .name = "Master Playback Switch",
  1194. .info = cxt_eapd_info,
  1195. .get = cxt_eapd_get,
  1196. .put = cxt5047_hp_master_sw_put,
  1197. .private_value = 0x13,
  1198. },
  1199. {}
  1200. };
  1201. static const struct snd_kcontrol_new cxt5047_hp_spk_mixers[] = {
  1202. /* See the note in cxt5047_hp_master_sw_put */
  1203. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x01, HDA_OUTPUT),
  1204. HDA_CODEC_VOLUME("Headphone Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1205. {}
  1206. };
  1207. static const struct snd_kcontrol_new cxt5047_hp_only_mixers[] = {
  1208. HDA_CODEC_VOLUME("Master Playback Volume", 0x13, 0x00, HDA_OUTPUT),
  1209. { } /* end */
  1210. };
  1211. static const struct hda_verb cxt5047_init_verbs[] = {
  1212. /* Line in, Mic, Built-in Mic */
  1213. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
  1214. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1215. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN|AC_PINCTL_VREF_50 },
  1216. /* HP, Speaker */
  1217. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP },
  1218. {0x13, AC_VERB_SET_CONNECT_SEL, 0x0}, /* mixer(0x19) */
  1219. {0x1d, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mixer(0x19) */
  1220. /* Record selector: Mic */
  1221. {0x12, AC_VERB_SET_CONNECT_SEL,0x03},
  1222. {0x19, AC_VERB_SET_AMP_GAIN_MUTE,
  1223. AC_AMP_SET_INPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x17},
  1224. {0x1A, AC_VERB_SET_CONNECT_SEL,0x02},
  1225. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1226. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x00},
  1227. {0x1A, AC_VERB_SET_AMP_GAIN_MUTE,
  1228. AC_AMP_SET_OUTPUT|AC_AMP_SET_RIGHT|AC_AMP_SET_LEFT|0x03},
  1229. /* SPDIF route: PCM */
  1230. { 0x18, AC_VERB_SET_CONNECT_SEL, 0x0 },
  1231. /* Enable unsolicited events */
  1232. {0x13, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  1233. {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  1234. { } /* end */
  1235. };
  1236. /* configuration for Toshiba Laptops */
  1237. static const struct hda_verb cxt5047_toshiba_init_verbs[] = {
  1238. {0x13, AC_VERB_SET_EAPD_BTLENABLE, 0x0}, /* default off */
  1239. {}
  1240. };
  1241. /* Test configuration for debugging, modelled after the ALC260 test
  1242. * configuration.
  1243. */
  1244. #ifdef CONFIG_SND_DEBUG
  1245. static const struct hda_input_mux cxt5047_test_capture_source = {
  1246. .num_items = 4,
  1247. .items = {
  1248. { "LINE1 pin", 0x0 },
  1249. { "MIC1 pin", 0x1 },
  1250. { "MIC2 pin", 0x2 },
  1251. { "CD pin", 0x3 },
  1252. },
  1253. };
  1254. static const struct snd_kcontrol_new cxt5047_test_mixer[] = {
  1255. /* Output only controls */
  1256. HDA_CODEC_VOLUME("OutAmp-1 Volume", 0x10, 0x0, HDA_OUTPUT),
  1257. HDA_CODEC_MUTE("OutAmp-1 Switch", 0x10,0x0, HDA_OUTPUT),
  1258. HDA_CODEC_VOLUME("OutAmp-2 Volume", 0x1c, 0x0, HDA_OUTPUT),
  1259. HDA_CODEC_MUTE("OutAmp-2 Switch", 0x1c, 0x0, HDA_OUTPUT),
  1260. HDA_CODEC_VOLUME("Speaker Playback Volume", 0x1d, 0x0, HDA_OUTPUT),
  1261. HDA_CODEC_MUTE("Speaker Playback Switch", 0x1d, 0x0, HDA_OUTPUT),
  1262. HDA_CODEC_VOLUME("HeadPhone Playback Volume", 0x13, 0x0, HDA_OUTPUT),
  1263. HDA_CODEC_MUTE("HeadPhone Playback Switch", 0x13, 0x0, HDA_OUTPUT),
  1264. HDA_CODEC_VOLUME("Line1-Out Playback Volume", 0x14, 0x0, HDA_OUTPUT),
  1265. HDA_CODEC_MUTE("Line1-Out Playback Switch", 0x14, 0x0, HDA_OUTPUT),
  1266. HDA_CODEC_VOLUME("Line2-Out Playback Volume", 0x15, 0x0, HDA_OUTPUT),
  1267. HDA_CODEC_MUTE("Line2-Out Playback Switch", 0x15, 0x0, HDA_OUTPUT),
  1268. /* Modes for retasking pin widgets */
  1269. CXT_PIN_MODE("LINE1 pin mode", 0x14, CXT_PIN_DIR_INOUT),
  1270. CXT_PIN_MODE("MIC1 pin mode", 0x15, CXT_PIN_DIR_INOUT),
  1271. /* EAPD Switch Control */
  1272. CXT_EAPD_SWITCH("External Amplifier", 0x13, 0x0),
  1273. /* Loopback mixer controls */
  1274. HDA_CODEC_VOLUME("MIC1 Playback Volume", 0x12, 0x01, HDA_INPUT),
  1275. HDA_CODEC_MUTE("MIC1 Playback Switch", 0x12, 0x01, HDA_INPUT),
  1276. HDA_CODEC_VOLUME("MIC2 Playback Volume", 0x12, 0x02, HDA_INPUT),
  1277. HDA_CODEC_MUTE("MIC2 Playback Switch", 0x12, 0x02, HDA_INPUT),
  1278. HDA_CODEC_VOLUME("LINE Playback Volume", 0x12, 0x0, HDA_INPUT),
  1279. HDA_CODEC_MUTE("LINE Playback Switch", 0x12, 0x0, HDA_INPUT),
  1280. HDA_CODEC_VOLUME("CD Playback Volume", 0x12, 0x04, HDA_INPUT),
  1281. HDA_CODEC_MUTE("CD Playback Switch", 0x12, 0x04, HDA_INPUT),
  1282. HDA_CODEC_VOLUME("Capture-1 Volume", 0x19, 0x0, HDA_INPUT),
  1283. HDA_CODEC_MUTE("Capture-1 Switch", 0x19, 0x0, HDA_INPUT),
  1284. HDA_CODEC_VOLUME("Capture-2 Volume", 0x19, 0x1, HDA_INPUT),
  1285. HDA_CODEC_MUTE("Capture-2 Switch", 0x19, 0x1, HDA_INPUT),
  1286. HDA_CODEC_VOLUME("Capture-3 Volume", 0x19, 0x2, HDA_INPUT),
  1287. HDA_CODEC_MUTE("Capture-3 Switch", 0x19, 0x2, HDA_INPUT),
  1288. HDA_CODEC_VOLUME("Capture-4 Volume", 0x19, 0x3, HDA_INPUT),
  1289. HDA_CODEC_MUTE("Capture-4 Switch", 0x19, 0x3, HDA_INPUT),
  1290. {
  1291. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1292. .name = "Input Source",
  1293. .info = conexant_mux_enum_info,
  1294. .get = conexant_mux_enum_get,
  1295. .put = conexant_mux_enum_put,
  1296. },
  1297. HDA_CODEC_VOLUME("Mic Boost Volume", 0x1a, 0x0, HDA_OUTPUT),
  1298. { } /* end */
  1299. };
  1300. static const struct hda_verb cxt5047_test_init_verbs[] = {
  1301. /* Enable retasking pins as output, initially without power amp */
  1302. {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1303. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1304. {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1305. /* Disable digital (SPDIF) pins initially, but users can enable
  1306. * them via a mixer switch. In the case of SPDIF-out, this initverb
  1307. * payload also sets the generation to 0, output to be in "consumer"
  1308. * PCM format, copyright asserted, no pre-emphasis and no validity
  1309. * control.
  1310. */
  1311. {0x18, AC_VERB_SET_DIGI_CONVERT_1, 0},
  1312. /* Ensure mic1, mic2, line1 pin widgets take input from the
  1313. * OUT1 sum bus when acting as an output.
  1314. */
  1315. {0x1a, AC_VERB_SET_CONNECT_SEL, 0},
  1316. {0x1b, AC_VERB_SET_CONNECT_SEL, 0},
  1317. /* Start with output sum widgets muted and their output gains at min */
  1318. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1319. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  1320. /* Unmute retasking pin widget output buffers since the default
  1321. * state appears to be output. As the pin mode is changed by the
  1322. * user the pin mode control will take care of enabling the pin's
  1323. * input/output buffers as needed.
  1324. */
  1325. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1326. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1327. {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1328. /* Mute capture amp left and right */
  1329. {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  1330. /* Set ADC connection select to match default mixer setting (mic1
  1331. * pin)
  1332. */
  1333. {0x12, AC_VERB_SET_CONNECT_SEL, 0x00},
  1334. /* Mute all inputs to mixer widget (even unconnected ones) */
  1335. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* mic1 pin */
  1336. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, /* mic2 pin */
  1337. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)}, /* line1 pin */
  1338. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)}, /* line2 pin */
  1339. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)}, /* CD pin */
  1340. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)}, /* Beep-gen pin */
  1341. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)}, /* Line-out pin */
  1342. {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)}, /* HP-pin pin */
  1343. { }
  1344. };
  1345. #endif
  1346. /* initialize jack-sensing, too */
  1347. static int cxt5047_hp_init(struct hda_codec *codec)
  1348. {
  1349. conexant_init(codec);
  1350. cxt5047_hp_automute(codec);
  1351. return 0;
  1352. }
  1353. enum {
  1354. CXT5047_LAPTOP, /* Laptops w/o EAPD support */
  1355. CXT5047_LAPTOP_HP, /* Some HP laptops */
  1356. CXT5047_LAPTOP_EAPD, /* Laptops with EAPD support */
  1357. #ifdef CONFIG_SND_DEBUG
  1358. CXT5047_TEST,
  1359. #endif
  1360. CXT5047_AUTO,
  1361. CXT5047_MODELS
  1362. };
  1363. static const char * const cxt5047_models[CXT5047_MODELS] = {
  1364. [CXT5047_LAPTOP] = "laptop",
  1365. [CXT5047_LAPTOP_HP] = "laptop-hp",
  1366. [CXT5047_LAPTOP_EAPD] = "laptop-eapd",
  1367. #ifdef CONFIG_SND_DEBUG
  1368. [CXT5047_TEST] = "test",
  1369. #endif
  1370. [CXT5047_AUTO] = "auto",
  1371. };
  1372. static const struct snd_pci_quirk cxt5047_cfg_tbl[] = {
  1373. SND_PCI_QUIRK(0x103c, 0x30a5, "HP DV5200T/DV8000T", CXT5047_LAPTOP_HP),
  1374. SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP DV Series",
  1375. CXT5047_LAPTOP),
  1376. SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba P100", CXT5047_LAPTOP_EAPD),
  1377. {}
  1378. };
  1379. static int patch_cxt5047(struct hda_codec *codec)
  1380. {
  1381. struct conexant_spec *spec;
  1382. int board_config;
  1383. board_config = snd_hda_check_board_config(codec, CXT5047_MODELS,
  1384. cxt5047_models,
  1385. cxt5047_cfg_tbl);
  1386. if (board_config < 0)
  1387. board_config = CXT5047_AUTO; /* model=auto as default */
  1388. if (board_config == CXT5047_AUTO)
  1389. return patch_conexant_auto(codec);
  1390. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1391. if (!spec)
  1392. return -ENOMEM;
  1393. codec->spec = spec;
  1394. codec->pin_amp_workaround = 1;
  1395. spec->multiout.max_channels = 2;
  1396. spec->multiout.num_dacs = ARRAY_SIZE(cxt5047_dac_nids);
  1397. spec->multiout.dac_nids = cxt5047_dac_nids;
  1398. spec->multiout.dig_out_nid = CXT5047_SPDIF_OUT;
  1399. spec->num_adc_nids = 1;
  1400. spec->adc_nids = cxt5047_adc_nids;
  1401. spec->capsrc_nids = cxt5047_capsrc_nids;
  1402. spec->num_mixers = 1;
  1403. spec->mixers[0] = cxt5047_base_mixers;
  1404. spec->num_init_verbs = 1;
  1405. spec->init_verbs[0] = cxt5047_init_verbs;
  1406. spec->spdif_route = 0;
  1407. spec->num_channel_mode = ARRAY_SIZE(cxt5047_modes),
  1408. spec->channel_mode = cxt5047_modes,
  1409. codec->patch_ops = conexant_patch_ops;
  1410. switch (board_config) {
  1411. case CXT5047_LAPTOP:
  1412. spec->num_mixers = 2;
  1413. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1414. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1415. break;
  1416. case CXT5047_LAPTOP_HP:
  1417. spec->num_mixers = 2;
  1418. spec->mixers[1] = cxt5047_hp_only_mixers;
  1419. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1420. codec->patch_ops.init = cxt5047_hp_init;
  1421. break;
  1422. case CXT5047_LAPTOP_EAPD:
  1423. spec->input_mux = &cxt5047_toshiba_capture_source;
  1424. spec->num_mixers = 2;
  1425. spec->mixers[1] = cxt5047_hp_spk_mixers;
  1426. spec->num_init_verbs = 2;
  1427. spec->init_verbs[1] = cxt5047_toshiba_init_verbs;
  1428. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1429. break;
  1430. #ifdef CONFIG_SND_DEBUG
  1431. case CXT5047_TEST:
  1432. spec->input_mux = &cxt5047_test_capture_source;
  1433. spec->mixers[0] = cxt5047_test_mixer;
  1434. spec->init_verbs[0] = cxt5047_test_init_verbs;
  1435. codec->patch_ops.unsol_event = cxt5047_hp_unsol_event;
  1436. #endif
  1437. }
  1438. spec->vmaster_nid = 0x13;
  1439. switch (codec->subsystem_id >> 16) {
  1440. case 0x103c:
  1441. /* HP laptops have really bad sound over 0 dB on NID 0x10.
  1442. * Fix max PCM level to 0 dB (originally it has 0x1e steps
  1443. * with 0 dB offset 0x17)
  1444. */
  1445. snd_hda_override_amp_caps(codec, 0x10, HDA_INPUT,
  1446. (0x17 << AC_AMPCAP_OFFSET_SHIFT) |
  1447. (0x17 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  1448. (0x05 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  1449. (1 << AC_AMPCAP_MUTE_SHIFT));
  1450. break;
  1451. }
  1452. return 0;
  1453. }
  1454. /* Conexant 5051 specific */
  1455. static const hda_nid_t cxt5051_dac_nids[1] = { 0x10 };
  1456. static const hda_nid_t cxt5051_adc_nids[2] = { 0x14, 0x15 };
  1457. static const struct hda_channel_mode cxt5051_modes[1] = {
  1458. { 2, NULL },
  1459. };
  1460. static void cxt5051_update_speaker(struct hda_codec *codec)
  1461. {
  1462. struct conexant_spec *spec = codec->spec;
  1463. unsigned int pinctl;
  1464. /* headphone pin */
  1465. pinctl = (spec->hp_present && spec->cur_eapd) ? PIN_HP : 0;
  1466. snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1467. pinctl);
  1468. /* speaker pin */
  1469. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1470. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1471. pinctl);
  1472. /* on ideapad there is an aditional speaker (subwoofer) to mute */
  1473. if (spec->ideapad)
  1474. snd_hda_codec_write(codec, 0x1b, 0,
  1475. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1476. pinctl);
  1477. }
  1478. /* turn on/off EAPD (+ mute HP) as a master switch */
  1479. static int cxt5051_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1480. struct snd_ctl_elem_value *ucontrol)
  1481. {
  1482. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1483. if (!cxt_eapd_put(kcontrol, ucontrol))
  1484. return 0;
  1485. cxt5051_update_speaker(codec);
  1486. return 1;
  1487. }
  1488. /* toggle input of built-in and mic jack appropriately */
  1489. static void cxt5051_portb_automic(struct hda_codec *codec)
  1490. {
  1491. struct conexant_spec *spec = codec->spec;
  1492. unsigned int present;
  1493. if (!(spec->auto_mic & AUTO_MIC_PORTB))
  1494. return;
  1495. present = snd_hda_jack_detect(codec, 0x17);
  1496. snd_hda_codec_write(codec, 0x14, 0,
  1497. AC_VERB_SET_CONNECT_SEL,
  1498. present ? 0x01 : 0x00);
  1499. }
  1500. /* switch the current ADC according to the jack state */
  1501. static void cxt5051_portc_automic(struct hda_codec *codec)
  1502. {
  1503. struct conexant_spec *spec = codec->spec;
  1504. unsigned int present;
  1505. hda_nid_t new_adc;
  1506. if (!(spec->auto_mic & AUTO_MIC_PORTC))
  1507. return;
  1508. present = snd_hda_jack_detect(codec, 0x18);
  1509. if (present)
  1510. spec->cur_adc_idx = 1;
  1511. else
  1512. spec->cur_adc_idx = 0;
  1513. new_adc = spec->adc_nids[spec->cur_adc_idx];
  1514. if (spec->cur_adc && spec->cur_adc != new_adc) {
  1515. /* stream is running, let's swap the current ADC */
  1516. __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
  1517. spec->cur_adc = new_adc;
  1518. snd_hda_codec_setup_stream(codec, new_adc,
  1519. spec->cur_adc_stream_tag, 0,
  1520. spec->cur_adc_format);
  1521. }
  1522. }
  1523. /* mute internal speaker if HP is plugged */
  1524. static void cxt5051_hp_automute(struct hda_codec *codec)
  1525. {
  1526. struct conexant_spec *spec = codec->spec;
  1527. spec->hp_present = snd_hda_jack_detect(codec, 0x16);
  1528. cxt5051_update_speaker(codec);
  1529. }
  1530. /* unsolicited event for HP jack sensing */
  1531. static void cxt5051_hp_unsol_event(struct hda_codec *codec,
  1532. unsigned int res)
  1533. {
  1534. int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
  1535. switch (res >> 26) {
  1536. case CONEXANT_HP_EVENT:
  1537. cxt5051_hp_automute(codec);
  1538. break;
  1539. case CXT5051_PORTB_EVENT:
  1540. cxt5051_portb_automic(codec);
  1541. break;
  1542. case CXT5051_PORTC_EVENT:
  1543. cxt5051_portc_automic(codec);
  1544. break;
  1545. }
  1546. snd_hda_input_jack_report(codec, nid);
  1547. }
  1548. static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
  1549. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  1550. {
  1551. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1552. .name = "Master Playback Switch",
  1553. .info = cxt_eapd_info,
  1554. .get = cxt_eapd_get,
  1555. .put = cxt5051_hp_master_sw_put,
  1556. .private_value = 0x1a,
  1557. },
  1558. {}
  1559. };
  1560. static const struct snd_kcontrol_new cxt5051_capture_mixers[] = {
  1561. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1562. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1563. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1564. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1565. HDA_CODEC_VOLUME("Docking Mic Volume", 0x15, 0x00, HDA_INPUT),
  1566. HDA_CODEC_MUTE("Docking Mic Switch", 0x15, 0x00, HDA_INPUT),
  1567. {}
  1568. };
  1569. static const struct snd_kcontrol_new cxt5051_hp_mixers[] = {
  1570. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1571. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1572. HDA_CODEC_VOLUME("Mic Volume", 0x15, 0x00, HDA_INPUT),
  1573. HDA_CODEC_MUTE("Mic Switch", 0x15, 0x00, HDA_INPUT),
  1574. {}
  1575. };
  1576. static const struct snd_kcontrol_new cxt5051_hp_dv6736_mixers[] = {
  1577. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x00, HDA_INPUT),
  1578. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x00, HDA_INPUT),
  1579. {}
  1580. };
  1581. static const struct snd_kcontrol_new cxt5051_f700_mixers[] = {
  1582. HDA_CODEC_VOLUME("Capture Volume", 0x14, 0x01, HDA_INPUT),
  1583. HDA_CODEC_MUTE("Capture Switch", 0x14, 0x01, HDA_INPUT),
  1584. {}
  1585. };
  1586. static const struct snd_kcontrol_new cxt5051_toshiba_mixers[] = {
  1587. HDA_CODEC_VOLUME("Internal Mic Volume", 0x14, 0x00, HDA_INPUT),
  1588. HDA_CODEC_MUTE("Internal Mic Switch", 0x14, 0x00, HDA_INPUT),
  1589. HDA_CODEC_VOLUME("Mic Volume", 0x14, 0x01, HDA_INPUT),
  1590. HDA_CODEC_MUTE("Mic Switch", 0x14, 0x01, HDA_INPUT),
  1591. {}
  1592. };
  1593. static const struct hda_verb cxt5051_init_verbs[] = {
  1594. /* Line in, Mic */
  1595. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1596. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1597. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1598. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1599. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1600. {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1601. /* SPK */
  1602. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1603. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1604. /* HP, Amp */
  1605. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1606. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1607. /* DAC1 */
  1608. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1609. /* Record selector: Internal mic */
  1610. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1611. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1612. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
  1613. /* SPDIF route: PCM */
  1614. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1615. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1616. /* EAPD */
  1617. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1618. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1619. { } /* end */
  1620. };
  1621. static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
  1622. /* Line in, Mic */
  1623. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1624. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1625. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1626. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1627. /* SPK */
  1628. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1629. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1630. /* HP, Amp */
  1631. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1632. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1633. /* DAC1 */
  1634. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1635. /* Record selector: Internal mic */
  1636. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1637. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1638. /* SPDIF route: PCM */
  1639. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1640. /* EAPD */
  1641. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1642. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1643. { } /* end */
  1644. };
  1645. static const struct hda_verb cxt5051_f700_init_verbs[] = {
  1646. /* Line in, Mic */
  1647. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
  1648. {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1649. {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1650. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x0},
  1651. /* SPK */
  1652. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1653. {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
  1654. /* HP, Amp */
  1655. {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  1656. {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
  1657. /* DAC1 */
  1658. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  1659. /* Record selector: Internal mic */
  1660. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
  1661. {0x14, AC_VERB_SET_CONNECT_SEL, 0x1},
  1662. /* SPDIF route: PCM */
  1663. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
  1664. /* EAPD */
  1665. {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  1666. {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
  1667. { } /* end */
  1668. };
  1669. static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
  1670. unsigned int event)
  1671. {
  1672. snd_hda_codec_write(codec, nid, 0,
  1673. AC_VERB_SET_UNSOLICITED_ENABLE,
  1674. AC_USRSP_EN | event);
  1675. snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
  1676. snd_hda_input_jack_report(codec, nid);
  1677. }
  1678. static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
  1679. /* Subwoofer */
  1680. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  1681. {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
  1682. { } /* end */
  1683. };
  1684. /* initialize jack-sensing, too */
  1685. static int cxt5051_init(struct hda_codec *codec)
  1686. {
  1687. struct conexant_spec *spec = codec->spec;
  1688. conexant_init(codec);
  1689. conexant_init_jacks(codec);
  1690. if (spec->auto_mic & AUTO_MIC_PORTB)
  1691. cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
  1692. if (spec->auto_mic & AUTO_MIC_PORTC)
  1693. cxt5051_init_mic_port(codec, 0x18, CXT5051_PORTC_EVENT);
  1694. if (codec->patch_ops.unsol_event) {
  1695. cxt5051_hp_automute(codec);
  1696. cxt5051_portb_automic(codec);
  1697. cxt5051_portc_automic(codec);
  1698. }
  1699. return 0;
  1700. }
  1701. enum {
  1702. CXT5051_LAPTOP, /* Laptops w/ EAPD support */
  1703. CXT5051_HP, /* no docking */
  1704. CXT5051_HP_DV6736, /* HP without mic switch */
  1705. CXT5051_F700, /* HP Compaq Presario F700 */
  1706. CXT5051_TOSHIBA, /* Toshiba M300 & co */
  1707. CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
  1708. CXT5051_AUTO, /* auto-parser */
  1709. CXT5051_MODELS
  1710. };
  1711. static const char *const cxt5051_models[CXT5051_MODELS] = {
  1712. [CXT5051_LAPTOP] = "laptop",
  1713. [CXT5051_HP] = "hp",
  1714. [CXT5051_HP_DV6736] = "hp-dv6736",
  1715. [CXT5051_F700] = "hp-700",
  1716. [CXT5051_TOSHIBA] = "toshiba",
  1717. [CXT5051_IDEAPAD] = "ideapad",
  1718. [CXT5051_AUTO] = "auto",
  1719. };
  1720. static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
  1721. SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV6736", CXT5051_HP_DV6736),
  1722. SND_PCI_QUIRK(0x103c, 0x360b, "Compaq Presario CQ60", CXT5051_HP),
  1723. SND_PCI_QUIRK(0x103c, 0x30ea, "Compaq Presario F700", CXT5051_F700),
  1724. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba M30x", CXT5051_TOSHIBA),
  1725. SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
  1726. CXT5051_LAPTOP),
  1727. SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
  1728. SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
  1729. {}
  1730. };
  1731. static int patch_cxt5051(struct hda_codec *codec)
  1732. {
  1733. struct conexant_spec *spec;
  1734. int board_config;
  1735. board_config = snd_hda_check_board_config(codec, CXT5051_MODELS,
  1736. cxt5051_models,
  1737. cxt5051_cfg_tbl);
  1738. if (board_config < 0)
  1739. board_config = CXT5051_AUTO; /* model=auto as default */
  1740. if (board_config == CXT5051_AUTO)
  1741. return patch_conexant_auto(codec);
  1742. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1743. if (!spec)
  1744. return -ENOMEM;
  1745. codec->spec = spec;
  1746. codec->pin_amp_workaround = 1;
  1747. codec->patch_ops = conexant_patch_ops;
  1748. codec->patch_ops.init = cxt5051_init;
  1749. spec->multiout.max_channels = 2;
  1750. spec->multiout.num_dacs = ARRAY_SIZE(cxt5051_dac_nids);
  1751. spec->multiout.dac_nids = cxt5051_dac_nids;
  1752. spec->multiout.dig_out_nid = CXT5051_SPDIF_OUT;
  1753. spec->num_adc_nids = 1; /* not 2; via auto-mic switch */
  1754. spec->adc_nids = cxt5051_adc_nids;
  1755. spec->num_mixers = 2;
  1756. spec->mixers[0] = cxt5051_capture_mixers;
  1757. spec->mixers[1] = cxt5051_playback_mixers;
  1758. spec->num_init_verbs = 1;
  1759. spec->init_verbs[0] = cxt5051_init_verbs;
  1760. spec->spdif_route = 0;
  1761. spec->num_channel_mode = ARRAY_SIZE(cxt5051_modes);
  1762. spec->channel_mode = cxt5051_modes;
  1763. spec->cur_adc = 0;
  1764. spec->cur_adc_idx = 0;
  1765. set_beep_amp(spec, 0x13, 0, HDA_OUTPUT);
  1766. codec->patch_ops.unsol_event = cxt5051_hp_unsol_event;
  1767. spec->auto_mic = AUTO_MIC_PORTB | AUTO_MIC_PORTC;
  1768. switch (board_config) {
  1769. case CXT5051_HP:
  1770. spec->mixers[0] = cxt5051_hp_mixers;
  1771. break;
  1772. case CXT5051_HP_DV6736:
  1773. spec->init_verbs[0] = cxt5051_hp_dv6736_init_verbs;
  1774. spec->mixers[0] = cxt5051_hp_dv6736_mixers;
  1775. spec->auto_mic = 0;
  1776. break;
  1777. case CXT5051_F700:
  1778. spec->init_verbs[0] = cxt5051_f700_init_verbs;
  1779. spec->mixers[0] = cxt5051_f700_mixers;
  1780. spec->auto_mic = 0;
  1781. break;
  1782. case CXT5051_TOSHIBA:
  1783. spec->mixers[0] = cxt5051_toshiba_mixers;
  1784. spec->auto_mic = AUTO_MIC_PORTB;
  1785. break;
  1786. case CXT5051_IDEAPAD:
  1787. spec->init_verbs[spec->num_init_verbs++] =
  1788. cxt5051_ideapad_init_verbs;
  1789. spec->ideapad = 1;
  1790. break;
  1791. }
  1792. if (spec->beep_amp)
  1793. snd_hda_attach_beep_device(codec, spec->beep_amp);
  1794. return 0;
  1795. }
  1796. /* Conexant 5066 specific */
  1797. static const hda_nid_t cxt5066_dac_nids[1] = { 0x10 };
  1798. static const hda_nid_t cxt5066_adc_nids[3] = { 0x14, 0x15, 0x16 };
  1799. static const hda_nid_t cxt5066_capsrc_nids[1] = { 0x17 };
  1800. static const hda_nid_t cxt5066_digout_pin_nids[2] = { 0x20, 0x22 };
  1801. /* OLPC's microphone port is DC coupled for use with external sensors,
  1802. * therefore we use a 50% mic bias in order to center the input signal with
  1803. * the DC input range of the codec. */
  1804. #define CXT5066_OLPC_EXT_MIC_BIAS PIN_VREF50
  1805. static const struct hda_channel_mode cxt5066_modes[1] = {
  1806. { 2, NULL },
  1807. };
  1808. #define HP_PRESENT_PORT_A (1 << 0)
  1809. #define HP_PRESENT_PORT_D (1 << 1)
  1810. #define hp_port_a_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_A)
  1811. #define hp_port_d_present(spec) ((spec)->hp_present & HP_PRESENT_PORT_D)
  1812. static void cxt5066_update_speaker(struct hda_codec *codec)
  1813. {
  1814. struct conexant_spec *spec = codec->spec;
  1815. unsigned int pinctl;
  1816. snd_printdd("CXT5066: update speaker, hp_present=%d, cur_eapd=%d\n",
  1817. spec->hp_present, spec->cur_eapd);
  1818. /* Port A (HP) */
  1819. pinctl = (hp_port_a_present(spec) && spec->cur_eapd) ? PIN_HP : 0;
  1820. snd_hda_codec_write(codec, 0x19, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1821. pinctl);
  1822. /* Port D (HP/LO) */
  1823. pinctl = spec->cur_eapd ? spec->port_d_mode : 0;
  1824. if (spec->dell_automute || spec->thinkpad) {
  1825. /* Mute if Port A is connected */
  1826. if (hp_port_a_present(spec))
  1827. pinctl = 0;
  1828. } else {
  1829. /* Thinkpad/Dell doesn't give pin-D status */
  1830. if (!hp_port_d_present(spec))
  1831. pinctl = 0;
  1832. }
  1833. snd_hda_codec_write(codec, 0x1c, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1834. pinctl);
  1835. /* CLASS_D AMP */
  1836. pinctl = (!spec->hp_present && spec->cur_eapd) ? PIN_OUT : 0;
  1837. snd_hda_codec_write(codec, 0x1f, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1838. pinctl);
  1839. }
  1840. /* turn on/off EAPD (+ mute HP) as a master switch */
  1841. static int cxt5066_hp_master_sw_put(struct snd_kcontrol *kcontrol,
  1842. struct snd_ctl_elem_value *ucontrol)
  1843. {
  1844. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1845. if (!cxt_eapd_put(kcontrol, ucontrol))
  1846. return 0;
  1847. cxt5066_update_speaker(codec);
  1848. return 1;
  1849. }
  1850. static const struct hda_input_mux cxt5066_olpc_dc_bias = {
  1851. .num_items = 3,
  1852. .items = {
  1853. { "Off", PIN_IN },
  1854. { "50%", PIN_VREF50 },
  1855. { "80%", PIN_VREF80 },
  1856. },
  1857. };
  1858. static int cxt5066_set_olpc_dc_bias(struct hda_codec *codec)
  1859. {
  1860. struct conexant_spec *spec = codec->spec;
  1861. /* Even though port F is the DC input, the bias is controlled on port B.
  1862. * we also leave that port as an active input (but unselected) in DC mode
  1863. * just in case that is necessary to make the bias setting take effect. */
  1864. return snd_hda_codec_write_cache(codec, 0x1a, 0,
  1865. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1866. cxt5066_olpc_dc_bias.items[spec->dc_input_bias].index);
  1867. }
  1868. /* OLPC defers mic widget control until when capture is started because the
  1869. * microphone LED comes on as soon as these settings are put in place. if we
  1870. * did this before recording, it would give the false indication that recording
  1871. * is happening when it is not. */
  1872. static void cxt5066_olpc_select_mic(struct hda_codec *codec)
  1873. {
  1874. struct conexant_spec *spec = codec->spec;
  1875. if (!spec->recording)
  1876. return;
  1877. if (spec->dc_enable) {
  1878. /* in DC mode we ignore presence detection and just use the jack
  1879. * through our special DC port */
  1880. const struct hda_verb enable_dc_mode[] = {
  1881. /* disble internal mic, port C */
  1882. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1883. /* enable DC capture, port F */
  1884. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1885. {},
  1886. };
  1887. snd_hda_sequence_write(codec, enable_dc_mode);
  1888. /* port B input disabled (and bias set) through the following call */
  1889. cxt5066_set_olpc_dc_bias(codec);
  1890. return;
  1891. }
  1892. /* disable DC (port F) */
  1893. snd_hda_codec_write(codec, 0x1e, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  1894. /* external mic, port B */
  1895. snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1896. spec->ext_mic_present ? CXT5066_OLPC_EXT_MIC_BIAS : 0);
  1897. /* internal mic, port C */
  1898. snd_hda_codec_write(codec, 0x1b, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
  1899. spec->ext_mic_present ? 0 : PIN_VREF80);
  1900. }
  1901. /* toggle input of built-in and mic jack appropriately */
  1902. static void cxt5066_olpc_automic(struct hda_codec *codec)
  1903. {
  1904. struct conexant_spec *spec = codec->spec;
  1905. unsigned int present;
  1906. if (spec->dc_enable) /* don't do presence detection in DC mode */
  1907. return;
  1908. present = snd_hda_codec_read(codec, 0x1a, 0,
  1909. AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
  1910. if (present)
  1911. snd_printdd("CXT5066: external microphone detected\n");
  1912. else
  1913. snd_printdd("CXT5066: external microphone absent\n");
  1914. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1915. present ? 0 : 1);
  1916. spec->ext_mic_present = !!present;
  1917. cxt5066_olpc_select_mic(codec);
  1918. }
  1919. /* toggle input of built-in digital mic and mic jack appropriately */
  1920. static void cxt5066_vostro_automic(struct hda_codec *codec)
  1921. {
  1922. unsigned int present;
  1923. struct hda_verb ext_mic_present[] = {
  1924. /* enable external mic, port B */
  1925. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1926. /* switch to external mic input */
  1927. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  1928. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1929. /* disable internal digital mic */
  1930. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1931. {}
  1932. };
  1933. static const struct hda_verb ext_mic_absent[] = {
  1934. /* enable internal mic, port C */
  1935. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1936. /* switch to internal mic input */
  1937. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1938. /* disable external mic, port B */
  1939. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1940. {}
  1941. };
  1942. present = snd_hda_jack_detect(codec, 0x1a);
  1943. if (present) {
  1944. snd_printdd("CXT5066: external microphone detected\n");
  1945. snd_hda_sequence_write(codec, ext_mic_present);
  1946. } else {
  1947. snd_printdd("CXT5066: external microphone absent\n");
  1948. snd_hda_sequence_write(codec, ext_mic_absent);
  1949. }
  1950. }
  1951. /* toggle input of built-in digital mic and mic jack appropriately */
  1952. static void cxt5066_ideapad_automic(struct hda_codec *codec)
  1953. {
  1954. unsigned int present;
  1955. struct hda_verb ext_mic_present[] = {
  1956. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  1957. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  1958. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1959. {}
  1960. };
  1961. static const struct hda_verb ext_mic_absent[] = {
  1962. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  1963. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  1964. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  1965. {}
  1966. };
  1967. present = snd_hda_jack_detect(codec, 0x1b);
  1968. if (present) {
  1969. snd_printdd("CXT5066: external microphone detected\n");
  1970. snd_hda_sequence_write(codec, ext_mic_present);
  1971. } else {
  1972. snd_printdd("CXT5066: external microphone absent\n");
  1973. snd_hda_sequence_write(codec, ext_mic_absent);
  1974. }
  1975. }
  1976. /* toggle input of built-in digital mic and mic jack appropriately */
  1977. static void cxt5066_asus_automic(struct hda_codec *codec)
  1978. {
  1979. unsigned int present;
  1980. present = snd_hda_jack_detect(codec, 0x1b);
  1981. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1982. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1983. present ? 1 : 0);
  1984. }
  1985. /* toggle input of built-in digital mic and mic jack appropriately */
  1986. static void cxt5066_hp_laptop_automic(struct hda_codec *codec)
  1987. {
  1988. unsigned int present;
  1989. present = snd_hda_jack_detect(codec, 0x1b);
  1990. snd_printdd("CXT5066: external microphone present=%d\n", present);
  1991. snd_hda_codec_write(codec, 0x17, 0, AC_VERB_SET_CONNECT_SEL,
  1992. present ? 1 : 3);
  1993. }
  1994. /* toggle input of built-in digital mic and mic jack appropriately
  1995. order is: external mic -> dock mic -> interal mic */
  1996. static void cxt5066_thinkpad_automic(struct hda_codec *codec)
  1997. {
  1998. unsigned int ext_present, dock_present;
  1999. static const struct hda_verb ext_mic_present[] = {
  2000. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2001. {0x17, AC_VERB_SET_CONNECT_SEL, 1},
  2002. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2003. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2004. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2005. {}
  2006. };
  2007. static const struct hda_verb dock_mic_present[] = {
  2008. {0x14, AC_VERB_SET_CONNECT_SEL, 0},
  2009. {0x17, AC_VERB_SET_CONNECT_SEL, 0},
  2010. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
  2011. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2012. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2013. {}
  2014. };
  2015. static const struct hda_verb ext_mic_absent[] = {
  2016. {0x14, AC_VERB_SET_CONNECT_SEL, 2},
  2017. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2018. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2019. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2020. {}
  2021. };
  2022. ext_present = snd_hda_jack_detect(codec, 0x1b);
  2023. dock_present = snd_hda_jack_detect(codec, 0x1a);
  2024. if (ext_present) {
  2025. snd_printdd("CXT5066: external microphone detected\n");
  2026. snd_hda_sequence_write(codec, ext_mic_present);
  2027. } else if (dock_present) {
  2028. snd_printdd("CXT5066: dock microphone detected\n");
  2029. snd_hda_sequence_write(codec, dock_mic_present);
  2030. } else {
  2031. snd_printdd("CXT5066: external microphone absent\n");
  2032. snd_hda_sequence_write(codec, ext_mic_absent);
  2033. }
  2034. }
  2035. /* mute internal speaker if HP is plugged */
  2036. static void cxt5066_hp_automute(struct hda_codec *codec)
  2037. {
  2038. struct conexant_spec *spec = codec->spec;
  2039. unsigned int portA, portD;
  2040. /* Port A */
  2041. portA = snd_hda_jack_detect(codec, 0x19);
  2042. /* Port D */
  2043. portD = snd_hda_jack_detect(codec, 0x1c);
  2044. spec->hp_present = portA ? HP_PRESENT_PORT_A : 0;
  2045. spec->hp_present |= portD ? HP_PRESENT_PORT_D : 0;
  2046. snd_printdd("CXT5066: hp automute portA=%x portD=%x present=%d\n",
  2047. portA, portD, spec->hp_present);
  2048. cxt5066_update_speaker(codec);
  2049. }
  2050. /* Dispatch the right mic autoswitch function */
  2051. static void cxt5066_automic(struct hda_codec *codec)
  2052. {
  2053. struct conexant_spec *spec = codec->spec;
  2054. if (spec->dell_vostro)
  2055. cxt5066_vostro_automic(codec);
  2056. else if (spec->ideapad)
  2057. cxt5066_ideapad_automic(codec);
  2058. else if (spec->thinkpad)
  2059. cxt5066_thinkpad_automic(codec);
  2060. else if (spec->hp_laptop)
  2061. cxt5066_hp_laptop_automic(codec);
  2062. else if (spec->asus)
  2063. cxt5066_asus_automic(codec);
  2064. }
  2065. /* unsolicited event for jack sensing */
  2066. static void cxt5066_olpc_unsol_event(struct hda_codec *codec, unsigned int res)
  2067. {
  2068. struct conexant_spec *spec = codec->spec;
  2069. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2070. switch (res >> 26) {
  2071. case CONEXANT_HP_EVENT:
  2072. cxt5066_hp_automute(codec);
  2073. break;
  2074. case CONEXANT_MIC_EVENT:
  2075. /* ignore mic events in DC mode; we're always using the jack */
  2076. if (!spec->dc_enable)
  2077. cxt5066_olpc_automic(codec);
  2078. break;
  2079. }
  2080. }
  2081. /* unsolicited event for jack sensing */
  2082. static void cxt5066_unsol_event(struct hda_codec *codec, unsigned int res)
  2083. {
  2084. snd_printdd("CXT5066: unsol event %x (%x)\n", res, res >> 26);
  2085. switch (res >> 26) {
  2086. case CONEXANT_HP_EVENT:
  2087. cxt5066_hp_automute(codec);
  2088. break;
  2089. case CONEXANT_MIC_EVENT:
  2090. cxt5066_automic(codec);
  2091. break;
  2092. }
  2093. }
  2094. static const struct hda_input_mux cxt5066_analog_mic_boost = {
  2095. .num_items = 5,
  2096. .items = {
  2097. { "0dB", 0 },
  2098. { "10dB", 1 },
  2099. { "20dB", 2 },
  2100. { "30dB", 3 },
  2101. { "40dB", 4 },
  2102. },
  2103. };
  2104. static void cxt5066_set_mic_boost(struct hda_codec *codec)
  2105. {
  2106. struct conexant_spec *spec = codec->spec;
  2107. snd_hda_codec_write_cache(codec, 0x17, 0,
  2108. AC_VERB_SET_AMP_GAIN_MUTE,
  2109. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_OUTPUT |
  2110. cxt5066_analog_mic_boost.items[spec->mic_boost].index);
  2111. if (spec->ideapad || spec->thinkpad) {
  2112. /* adjust the internal mic as well...it is not through 0x17 */
  2113. snd_hda_codec_write_cache(codec, 0x23, 0,
  2114. AC_VERB_SET_AMP_GAIN_MUTE,
  2115. AC_AMP_SET_RIGHT | AC_AMP_SET_LEFT | AC_AMP_SET_INPUT |
  2116. cxt5066_analog_mic_boost.
  2117. items[spec->mic_boost].index);
  2118. }
  2119. }
  2120. static int cxt5066_mic_boost_mux_enum_info(struct snd_kcontrol *kcontrol,
  2121. struct snd_ctl_elem_info *uinfo)
  2122. {
  2123. return snd_hda_input_mux_info(&cxt5066_analog_mic_boost, uinfo);
  2124. }
  2125. static int cxt5066_mic_boost_mux_enum_get(struct snd_kcontrol *kcontrol,
  2126. struct snd_ctl_elem_value *ucontrol)
  2127. {
  2128. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2129. struct conexant_spec *spec = codec->spec;
  2130. ucontrol->value.enumerated.item[0] = spec->mic_boost;
  2131. return 0;
  2132. }
  2133. static int cxt5066_mic_boost_mux_enum_put(struct snd_kcontrol *kcontrol,
  2134. struct snd_ctl_elem_value *ucontrol)
  2135. {
  2136. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2137. struct conexant_spec *spec = codec->spec;
  2138. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2139. unsigned int idx;
  2140. idx = ucontrol->value.enumerated.item[0];
  2141. if (idx >= imux->num_items)
  2142. idx = imux->num_items - 1;
  2143. spec->mic_boost = idx;
  2144. if (!spec->dc_enable)
  2145. cxt5066_set_mic_boost(codec);
  2146. return 1;
  2147. }
  2148. static void cxt5066_enable_dc(struct hda_codec *codec)
  2149. {
  2150. const struct hda_verb enable_dc_mode[] = {
  2151. /* disable gain */
  2152. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2153. /* switch to DC input */
  2154. {0x17, AC_VERB_SET_CONNECT_SEL, 3},
  2155. {}
  2156. };
  2157. /* configure as input source */
  2158. snd_hda_sequence_write(codec, enable_dc_mode);
  2159. cxt5066_olpc_select_mic(codec); /* also sets configured bias */
  2160. }
  2161. static void cxt5066_disable_dc(struct hda_codec *codec)
  2162. {
  2163. /* reconfigure input source */
  2164. cxt5066_set_mic_boost(codec);
  2165. /* automic also selects the right mic if we're recording */
  2166. cxt5066_olpc_automic(codec);
  2167. }
  2168. static int cxt5066_olpc_dc_get(struct snd_kcontrol *kcontrol,
  2169. struct snd_ctl_elem_value *ucontrol)
  2170. {
  2171. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2172. struct conexant_spec *spec = codec->spec;
  2173. ucontrol->value.integer.value[0] = spec->dc_enable;
  2174. return 0;
  2175. }
  2176. static int cxt5066_olpc_dc_put(struct snd_kcontrol *kcontrol,
  2177. struct snd_ctl_elem_value *ucontrol)
  2178. {
  2179. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2180. struct conexant_spec *spec = codec->spec;
  2181. int dc_enable = !!ucontrol->value.integer.value[0];
  2182. if (dc_enable == spec->dc_enable)
  2183. return 0;
  2184. spec->dc_enable = dc_enable;
  2185. if (dc_enable)
  2186. cxt5066_enable_dc(codec);
  2187. else
  2188. cxt5066_disable_dc(codec);
  2189. return 1;
  2190. }
  2191. static int cxt5066_olpc_dc_bias_enum_info(struct snd_kcontrol *kcontrol,
  2192. struct snd_ctl_elem_info *uinfo)
  2193. {
  2194. return snd_hda_input_mux_info(&cxt5066_olpc_dc_bias, uinfo);
  2195. }
  2196. static int cxt5066_olpc_dc_bias_enum_get(struct snd_kcontrol *kcontrol,
  2197. struct snd_ctl_elem_value *ucontrol)
  2198. {
  2199. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2200. struct conexant_spec *spec = codec->spec;
  2201. ucontrol->value.enumerated.item[0] = spec->dc_input_bias;
  2202. return 0;
  2203. }
  2204. static int cxt5066_olpc_dc_bias_enum_put(struct snd_kcontrol *kcontrol,
  2205. struct snd_ctl_elem_value *ucontrol)
  2206. {
  2207. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  2208. struct conexant_spec *spec = codec->spec;
  2209. const struct hda_input_mux *imux = &cxt5066_analog_mic_boost;
  2210. unsigned int idx;
  2211. idx = ucontrol->value.enumerated.item[0];
  2212. if (idx >= imux->num_items)
  2213. idx = imux->num_items - 1;
  2214. spec->dc_input_bias = idx;
  2215. if (spec->dc_enable)
  2216. cxt5066_set_olpc_dc_bias(codec);
  2217. return 1;
  2218. }
  2219. static void cxt5066_olpc_capture_prepare(struct hda_codec *codec)
  2220. {
  2221. struct conexant_spec *spec = codec->spec;
  2222. /* mark as recording and configure the microphone widget so that the
  2223. * recording LED comes on. */
  2224. spec->recording = 1;
  2225. cxt5066_olpc_select_mic(codec);
  2226. }
  2227. static void cxt5066_olpc_capture_cleanup(struct hda_codec *codec)
  2228. {
  2229. struct conexant_spec *spec = codec->spec;
  2230. const struct hda_verb disable_mics[] = {
  2231. /* disable external mic, port B */
  2232. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2233. /* disble internal mic, port C */
  2234. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2235. /* disable DC capture, port F */
  2236. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2237. {},
  2238. };
  2239. snd_hda_sequence_write(codec, disable_mics);
  2240. spec->recording = 0;
  2241. }
  2242. static void conexant_check_dig_outs(struct hda_codec *codec,
  2243. const hda_nid_t *dig_pins,
  2244. int num_pins)
  2245. {
  2246. struct conexant_spec *spec = codec->spec;
  2247. hda_nid_t *nid_loc = &spec->multiout.dig_out_nid;
  2248. int i;
  2249. for (i = 0; i < num_pins; i++, dig_pins++) {
  2250. unsigned int cfg = snd_hda_codec_get_pincfg(codec, *dig_pins);
  2251. if (get_defcfg_connect(cfg) == AC_JACK_PORT_NONE)
  2252. continue;
  2253. if (snd_hda_get_connections(codec, *dig_pins, nid_loc, 1) != 1)
  2254. continue;
  2255. if (spec->slave_dig_outs[0])
  2256. nid_loc++;
  2257. else
  2258. nid_loc = spec->slave_dig_outs;
  2259. }
  2260. }
  2261. static const struct hda_input_mux cxt5066_capture_source = {
  2262. .num_items = 4,
  2263. .items = {
  2264. { "Mic B", 0 },
  2265. { "Mic C", 1 },
  2266. { "Mic E", 2 },
  2267. { "Mic F", 3 },
  2268. },
  2269. };
  2270. static const struct hda_bind_ctls cxt5066_bind_capture_vol_others = {
  2271. .ops = &snd_hda_bind_vol,
  2272. .values = {
  2273. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2274. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2275. 0
  2276. },
  2277. };
  2278. static const struct hda_bind_ctls cxt5066_bind_capture_sw_others = {
  2279. .ops = &snd_hda_bind_sw,
  2280. .values = {
  2281. HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_INPUT),
  2282. HDA_COMPOSE_AMP_VAL(0x14, 3, 2, HDA_INPUT),
  2283. 0
  2284. },
  2285. };
  2286. static const struct snd_kcontrol_new cxt5066_mixer_master[] = {
  2287. HDA_CODEC_VOLUME("Master Playback Volume", 0x10, 0x00, HDA_OUTPUT),
  2288. {}
  2289. };
  2290. static const struct snd_kcontrol_new cxt5066_mixer_master_olpc[] = {
  2291. {
  2292. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2293. .name = "Master Playback Volume",
  2294. .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
  2295. SNDRV_CTL_ELEM_ACCESS_TLV_READ |
  2296. SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK,
  2297. .subdevice = HDA_SUBDEV_AMP_FLAG,
  2298. .info = snd_hda_mixer_amp_volume_info,
  2299. .get = snd_hda_mixer_amp_volume_get,
  2300. .put = snd_hda_mixer_amp_volume_put,
  2301. .tlv = { .c = snd_hda_mixer_amp_tlv },
  2302. /* offset by 28 volume steps to limit minimum gain to -46dB */
  2303. .private_value =
  2304. HDA_COMPOSE_AMP_VAL_OFS(0x10, 3, 0, HDA_OUTPUT, 28),
  2305. },
  2306. {}
  2307. };
  2308. static const struct snd_kcontrol_new cxt5066_mixer_olpc_dc[] = {
  2309. {
  2310. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2311. .name = "DC Mode Enable Switch",
  2312. .info = snd_ctl_boolean_mono_info,
  2313. .get = cxt5066_olpc_dc_get,
  2314. .put = cxt5066_olpc_dc_put,
  2315. },
  2316. {
  2317. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2318. .name = "DC Input Bias Enum",
  2319. .info = cxt5066_olpc_dc_bias_enum_info,
  2320. .get = cxt5066_olpc_dc_bias_enum_get,
  2321. .put = cxt5066_olpc_dc_bias_enum_put,
  2322. },
  2323. {}
  2324. };
  2325. static const struct snd_kcontrol_new cxt5066_mixers[] = {
  2326. {
  2327. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2328. .name = "Master Playback Switch",
  2329. .info = cxt_eapd_info,
  2330. .get = cxt_eapd_get,
  2331. .put = cxt5066_hp_master_sw_put,
  2332. .private_value = 0x1d,
  2333. },
  2334. {
  2335. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2336. .name = "Analog Mic Boost Capture Enum",
  2337. .info = cxt5066_mic_boost_mux_enum_info,
  2338. .get = cxt5066_mic_boost_mux_enum_get,
  2339. .put = cxt5066_mic_boost_mux_enum_put,
  2340. },
  2341. HDA_BIND_VOL("Capture Volume", &cxt5066_bind_capture_vol_others),
  2342. HDA_BIND_SW("Capture Switch", &cxt5066_bind_capture_sw_others),
  2343. {}
  2344. };
  2345. static const struct snd_kcontrol_new cxt5066_vostro_mixers[] = {
  2346. {
  2347. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2348. .name = "Internal Mic Boost Capture Enum",
  2349. .info = cxt5066_mic_boost_mux_enum_info,
  2350. .get = cxt5066_mic_boost_mux_enum_get,
  2351. .put = cxt5066_mic_boost_mux_enum_put,
  2352. .private_value = 0x23 | 0x100,
  2353. },
  2354. {}
  2355. };
  2356. static const struct hda_verb cxt5066_init_verbs[] = {
  2357. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2358. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2359. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2360. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2361. /* Speakers */
  2362. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2363. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2364. /* HP, Amp */
  2365. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2366. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2367. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2368. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2369. /* DAC1 */
  2370. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2371. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2372. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2373. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2374. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2375. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2376. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2377. /* no digital microphone support yet */
  2378. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2379. /* Audio input selector */
  2380. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2381. /* SPDIF route: PCM */
  2382. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2383. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2384. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2385. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2386. /* EAPD */
  2387. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2388. /* not handling these yet */
  2389. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2390. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2391. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2392. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2393. {0x1d, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2394. {0x1e, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2395. {0x20, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2396. {0x22, AC_VERB_SET_UNSOLICITED_ENABLE, 0},
  2397. { } /* end */
  2398. };
  2399. static const struct hda_verb cxt5066_init_verbs_olpc[] = {
  2400. /* Port A: headphones */
  2401. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2402. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2403. /* Port B: external microphone */
  2404. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2405. /* Port C: internal microphone */
  2406. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2407. /* Port D: unused */
  2408. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2409. /* Port E: unused, but has primary EAPD */
  2410. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2411. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2412. /* Port F: external DC input through microphone port */
  2413. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2414. /* Port G: internal speakers */
  2415. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2416. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2417. /* DAC1 */
  2418. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2419. /* DAC2: unused */
  2420. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2421. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2422. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2423. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2424. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2425. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2426. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2427. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2428. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2429. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2430. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2431. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2432. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2433. /* Disable digital microphone port */
  2434. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2435. /* Audio input selectors */
  2436. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2437. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2438. /* Disable SPDIF */
  2439. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2440. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2441. /* enable unsolicited events for Port A and B */
  2442. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2443. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2444. { } /* end */
  2445. };
  2446. static const struct hda_verb cxt5066_init_verbs_vostro[] = {
  2447. /* Port A: headphones */
  2448. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2449. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2450. /* Port B: external microphone */
  2451. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2452. /* Port C: unused */
  2453. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2454. /* Port D: unused */
  2455. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2456. /* Port E: unused, but has primary EAPD */
  2457. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2458. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2459. /* Port F: unused */
  2460. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2461. /* Port G: internal speakers */
  2462. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2463. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2464. /* DAC1 */
  2465. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2466. /* DAC2: unused */
  2467. {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
  2468. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2469. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2470. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2471. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2472. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2473. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2474. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2475. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2476. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
  2477. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2478. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
  2479. {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2480. /* Digital microphone port */
  2481. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
  2482. /* Audio input selectors */
  2483. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x3},
  2484. {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
  2485. /* Disable SPDIF */
  2486. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2487. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2488. /* enable unsolicited events for Port A and B */
  2489. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2490. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2491. { } /* end */
  2492. };
  2493. static const struct hda_verb cxt5066_init_verbs_ideapad[] = {
  2494. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port B */
  2495. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, /* Port C */
  2496. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2497. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2498. /* Speakers */
  2499. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2500. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2501. /* HP, Amp */
  2502. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2503. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2504. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
  2505. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2506. /* DAC1 */
  2507. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2508. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2509. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2510. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2511. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2512. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2513. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2514. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2515. /* Audio input selector */
  2516. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2517. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2518. /* SPDIF route: PCM */
  2519. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2520. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2521. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2522. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2523. /* internal microphone */
  2524. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2525. /* EAPD */
  2526. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2527. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2528. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2529. { } /* end */
  2530. };
  2531. static const struct hda_verb cxt5066_init_verbs_thinkpad[] = {
  2532. {0x1e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port F */
  2533. {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* Port E */
  2534. /* Port G: internal speakers */
  2535. {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2536. {0x1f, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2537. /* Port A: HP, Amp */
  2538. {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2539. {0x19, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2540. /* Port B: Mic Dock */
  2541. {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2542. /* Port C: Mic */
  2543. {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2544. /* Port D: HP Dock, Amp */
  2545. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0},
  2546. {0x1c, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC1 */
  2547. /* DAC1 */
  2548. {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
  2549. /* Node 14 connections: 0x17 0x18 0x23 0x24 0x27 */
  2550. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x50},
  2551. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
  2552. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2) | 0x50},
  2553. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
  2554. {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
  2555. {0x14, AC_VERB_SET_CONNECT_SEL, 2}, /* default to internal mic */
  2556. /* Audio input selector */
  2557. {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x2},
  2558. {0x17, AC_VERB_SET_CONNECT_SEL, 1}, /* route ext mic */
  2559. /* SPDIF route: PCM */
  2560. {0x20, AC_VERB_SET_CONNECT_SEL, 0x0},
  2561. {0x22, AC_VERB_SET_CONNECT_SEL, 0x0},
  2562. {0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2563. {0x22, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2564. /* internal microphone */
  2565. {0x23, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* enable internal mic */
  2566. /* EAPD */
  2567. {0x1d, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
  2568. /* enable unsolicited events for Port A, B, C and D */
  2569. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2570. {0x1c, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2571. {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2572. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2573. { } /* end */
  2574. };
  2575. static const struct hda_verb cxt5066_init_verbs_portd_lo[] = {
  2576. {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  2577. { } /* end */
  2578. };
  2579. static const struct hda_verb cxt5066_init_verbs_hp_laptop[] = {
  2580. {0x14, AC_VERB_SET_CONNECT_SEL, 0x0},
  2581. {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_HP_EVENT},
  2582. {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | CONEXANT_MIC_EVENT},
  2583. { } /* end */
  2584. };
  2585. /* initialize jack-sensing, too */
  2586. static int cxt5066_init(struct hda_codec *codec)
  2587. {
  2588. snd_printdd("CXT5066: init\n");
  2589. conexant_init(codec);
  2590. if (codec->patch_ops.unsol_event) {
  2591. cxt5066_hp_automute(codec);
  2592. cxt5066_automic(codec);
  2593. }
  2594. cxt5066_set_mic_boost(codec);
  2595. return 0;
  2596. }
  2597. static int cxt5066_olpc_init(struct hda_codec *codec)
  2598. {
  2599. struct conexant_spec *spec = codec->spec;
  2600. snd_printdd("CXT5066: init\n");
  2601. conexant_init(codec);
  2602. cxt5066_hp_automute(codec);
  2603. if (!spec->dc_enable) {
  2604. cxt5066_set_mic_boost(codec);
  2605. cxt5066_olpc_automic(codec);
  2606. } else {
  2607. cxt5066_enable_dc(codec);
  2608. }
  2609. return 0;
  2610. }
  2611. enum {
  2612. CXT5066_LAPTOP, /* Laptops w/ EAPD support */
  2613. CXT5066_DELL_LAPTOP, /* Dell Laptop */
  2614. CXT5066_OLPC_XO_1_5, /* OLPC XO 1.5 */
  2615. CXT5066_DELL_VOSTRO, /* Dell Vostro 1015i */
  2616. CXT5066_IDEAPAD, /* Lenovo IdeaPad U150 */
  2617. CXT5066_THINKPAD, /* Lenovo ThinkPad T410s, others? */
  2618. CXT5066_ASUS, /* Asus K52JU, Lenovo G560 - Int mic at 0x1a and Ext mic at 0x1b */
  2619. CXT5066_HP_LAPTOP, /* HP Laptop */
  2620. CXT5066_AUTO, /* BIOS auto-parser */
  2621. CXT5066_MODELS
  2622. };
  2623. static const char * const cxt5066_models[CXT5066_MODELS] = {
  2624. [CXT5066_LAPTOP] = "laptop",
  2625. [CXT5066_DELL_LAPTOP] = "dell-laptop",
  2626. [CXT5066_OLPC_XO_1_5] = "olpc-xo-1_5",
  2627. [CXT5066_DELL_VOSTRO] = "dell-vostro",
  2628. [CXT5066_IDEAPAD] = "ideapad",
  2629. [CXT5066_THINKPAD] = "thinkpad",
  2630. [CXT5066_ASUS] = "asus",
  2631. [CXT5066_HP_LAPTOP] = "hp-laptop",
  2632. [CXT5066_AUTO] = "auto",
  2633. };
  2634. static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
  2635. SND_PCI_QUIRK(0x1025, 0x054c, "Acer Aspire 3830TG", CXT5066_AUTO),
  2636. SND_PCI_QUIRK_MASK(0x1025, 0xff00, 0x0400, "Acer", CXT5066_IDEAPAD),
  2637. SND_PCI_QUIRK(0x1028, 0x02d8, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2638. SND_PCI_QUIRK(0x1028, 0x02f5, "Dell Vostro 320", CXT5066_IDEAPAD),
  2639. SND_PCI_QUIRK(0x1028, 0x0401, "Dell Vostro 1014", CXT5066_DELL_VOSTRO),
  2640. SND_PCI_QUIRK(0x1028, 0x0402, "Dell Vostro", CXT5066_DELL_VOSTRO),
  2641. SND_PCI_QUIRK(0x1028, 0x0408, "Dell Inspiron One 19T", CXT5066_IDEAPAD),
  2642. SND_PCI_QUIRK(0x1028, 0x050f, "Dell Inspiron", CXT5066_IDEAPAD),
  2643. SND_PCI_QUIRK(0x1028, 0x0510, "Dell Vostro", CXT5066_IDEAPAD),
  2644. SND_PCI_QUIRK(0x103c, 0x360b, "HP G60", CXT5066_HP_LAPTOP),
  2645. SND_PCI_QUIRK(0x1043, 0x13f3, "Asus A52J", CXT5066_ASUS),
  2646. SND_PCI_QUIRK(0x1043, 0x1643, "Asus K52JU", CXT5066_ASUS),
  2647. SND_PCI_QUIRK(0x1043, 0x1993, "Asus U50F", CXT5066_ASUS),
  2648. SND_PCI_QUIRK(0x1179, 0xff1e, "Toshiba Satellite C650D", CXT5066_IDEAPAD),
  2649. SND_PCI_QUIRK(0x1179, 0xff50, "Toshiba Satellite P500-PSPGSC-01800T", CXT5066_OLPC_XO_1_5),
  2650. SND_PCI_QUIRK(0x1179, 0xffe0, "Toshiba Satellite Pro T130-15F", 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)