patch_conexant.c 116 KB

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