patch_conexant.c 116 KB

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