patch_conexant.c 116 KB

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