patch_conexant.c 135 KB

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