patch_sigmatel.c 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163
  1. /*
  2. * Universal Interface for Intel High Definition Audio Codec
  3. *
  4. * HD audio interface patch for SigmaTel STAC92xx
  5. *
  6. * Copyright (c) 2005 Embedded Alley Solutions, Inc.
  7. * Matt Porter <mporter@embeddedalley.com>
  8. *
  9. * Based on patch_cmedia.c and patch_realtek.c
  10. * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
  11. *
  12. * This driver is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This driver is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <sound/driver.h>
  27. #include <linux/init.h>
  28. #include <linux/delay.h>
  29. #include <linux/slab.h>
  30. #include <linux/pci.h>
  31. #include <sound/core.h>
  32. #include <sound/asoundef.h>
  33. #include "hda_codec.h"
  34. #include "hda_local.h"
  35. #define NUM_CONTROL_ALLOC 32
  36. #define STAC_HP_EVENT 0x37
  37. enum {
  38. STAC_REF,
  39. STAC_9200_DELL_D21,
  40. STAC_9200_DELL_D22,
  41. STAC_9200_DELL_D23,
  42. STAC_9200_DELL_M21,
  43. STAC_9200_DELL_M22,
  44. STAC_9200_DELL_M23,
  45. STAC_9200_DELL_M24,
  46. STAC_9200_DELL_M25,
  47. STAC_9200_DELL_M26,
  48. STAC_9200_DELL_M27,
  49. STAC_9200_GATEWAY,
  50. STAC_9200_MODELS
  51. };
  52. enum {
  53. STAC_9205_REF,
  54. STAC_9205_DELL_M42,
  55. STAC_9205_DELL_M43,
  56. STAC_9205_DELL_M44,
  57. STAC_9205_MODELS
  58. };
  59. enum {
  60. STAC_925x_REF,
  61. STAC_M2_2,
  62. STAC_MA6,
  63. STAC_PA6,
  64. STAC_925x_MODELS
  65. };
  66. enum {
  67. STAC_D945_REF,
  68. STAC_D945GTP3,
  69. STAC_D945GTP5,
  70. STAC_INTEL_MAC_V1,
  71. STAC_INTEL_MAC_V2,
  72. STAC_INTEL_MAC_V3,
  73. STAC_INTEL_MAC_V4,
  74. STAC_INTEL_MAC_V5,
  75. /* for backward compatibility */
  76. STAC_MACMINI,
  77. STAC_MACBOOK,
  78. STAC_MACBOOK_PRO_V1,
  79. STAC_MACBOOK_PRO_V2,
  80. STAC_IMAC_INTEL,
  81. STAC_IMAC_INTEL_20,
  82. STAC_922X_DELL_D81,
  83. STAC_922X_DELL_D82,
  84. STAC_922X_DELL_M81,
  85. STAC_922X_DELL_M82,
  86. STAC_922X_MODELS
  87. };
  88. enum {
  89. STAC_D965_REF,
  90. STAC_D965_3ST,
  91. STAC_D965_5ST,
  92. STAC_DELL_3ST,
  93. STAC_927X_MODELS
  94. };
  95. struct sigmatel_spec {
  96. struct snd_kcontrol_new *mixers[4];
  97. unsigned int num_mixers;
  98. int board_config;
  99. unsigned int surr_switch: 1;
  100. unsigned int line_switch: 1;
  101. unsigned int mic_switch: 1;
  102. unsigned int alt_switch: 1;
  103. unsigned int hp_detect: 1;
  104. unsigned int gpio_mute: 1;
  105. unsigned int no_vol_knob :1;
  106. unsigned int gpio_mask, gpio_data;
  107. /* playback */
  108. struct hda_multi_out multiout;
  109. hda_nid_t dac_nids[5];
  110. /* capture */
  111. hda_nid_t *adc_nids;
  112. unsigned int num_adcs;
  113. hda_nid_t *mux_nids;
  114. unsigned int num_muxes;
  115. hda_nid_t *dmic_nids;
  116. unsigned int num_dmics;
  117. hda_nid_t dmux_nid;
  118. hda_nid_t dig_in_nid;
  119. /* pin widgets */
  120. hda_nid_t *pin_nids;
  121. unsigned int num_pins;
  122. unsigned int *pin_configs;
  123. unsigned int *bios_pin_configs;
  124. /* codec specific stuff */
  125. struct hda_verb *init;
  126. struct snd_kcontrol_new *mixer;
  127. /* capture source */
  128. struct hda_input_mux *dinput_mux;
  129. unsigned int cur_dmux;
  130. struct hda_input_mux *input_mux;
  131. unsigned int cur_mux[3];
  132. /* i/o switches */
  133. unsigned int io_switch[2];
  134. unsigned int clfe_swap;
  135. unsigned int aloopback;
  136. struct hda_pcm pcm_rec[2]; /* PCM information */
  137. /* dynamic controls and input_mux */
  138. struct auto_pin_cfg autocfg;
  139. unsigned int num_kctl_alloc, num_kctl_used;
  140. struct snd_kcontrol_new *kctl_alloc;
  141. struct hda_input_mux private_dimux;
  142. struct hda_input_mux private_imux;
  143. };
  144. static hda_nid_t stac9200_adc_nids[1] = {
  145. 0x03,
  146. };
  147. static hda_nid_t stac9200_mux_nids[1] = {
  148. 0x0c,
  149. };
  150. static hda_nid_t stac9200_dac_nids[1] = {
  151. 0x02,
  152. };
  153. static hda_nid_t stac925x_adc_nids[1] = {
  154. 0x03,
  155. };
  156. static hda_nid_t stac925x_mux_nids[1] = {
  157. 0x0f,
  158. };
  159. static hda_nid_t stac925x_dac_nids[1] = {
  160. 0x02,
  161. };
  162. #define STAC925X_NUM_DMICS 1
  163. static hda_nid_t stac925x_dmic_nids[STAC925X_NUM_DMICS + 1] = {
  164. 0x15, 0
  165. };
  166. static hda_nid_t stac922x_adc_nids[2] = {
  167. 0x06, 0x07,
  168. };
  169. static hda_nid_t stac922x_mux_nids[2] = {
  170. 0x12, 0x13,
  171. };
  172. static hda_nid_t stac927x_adc_nids[3] = {
  173. 0x07, 0x08, 0x09
  174. };
  175. static hda_nid_t stac927x_mux_nids[3] = {
  176. 0x15, 0x16, 0x17
  177. };
  178. static hda_nid_t stac9205_adc_nids[2] = {
  179. 0x12, 0x13
  180. };
  181. static hda_nid_t stac9205_mux_nids[2] = {
  182. 0x19, 0x1a
  183. };
  184. #define STAC9205_NUM_DMICS 2
  185. static hda_nid_t stac9205_dmic_nids[STAC9205_NUM_DMICS + 1] = {
  186. 0x17, 0x18, 0
  187. };
  188. static hda_nid_t stac9200_pin_nids[8] = {
  189. 0x08, 0x09, 0x0d, 0x0e,
  190. 0x0f, 0x10, 0x11, 0x12,
  191. };
  192. static hda_nid_t stac925x_pin_nids[8] = {
  193. 0x07, 0x08, 0x0a, 0x0b,
  194. 0x0c, 0x0d, 0x10, 0x11,
  195. };
  196. static hda_nid_t stac922x_pin_nids[10] = {
  197. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  198. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  199. };
  200. static hda_nid_t stac927x_pin_nids[14] = {
  201. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  202. 0x0f, 0x10, 0x11, 0x12, 0x13,
  203. 0x14, 0x21, 0x22, 0x23,
  204. };
  205. static hda_nid_t stac9205_pin_nids[12] = {
  206. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  207. 0x0f, 0x14, 0x16, 0x17, 0x18,
  208. 0x21, 0x22,
  209. };
  210. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  211. struct snd_ctl_elem_info *uinfo)
  212. {
  213. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  214. struct sigmatel_spec *spec = codec->spec;
  215. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  216. }
  217. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  218. struct snd_ctl_elem_value *ucontrol)
  219. {
  220. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  221. struct sigmatel_spec *spec = codec->spec;
  222. ucontrol->value.enumerated.item[0] = spec->cur_dmux;
  223. return 0;
  224. }
  225. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  226. struct snd_ctl_elem_value *ucontrol)
  227. {
  228. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  229. struct sigmatel_spec *spec = codec->spec;
  230. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  231. spec->dmux_nid, &spec->cur_dmux);
  232. }
  233. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  234. {
  235. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  236. struct sigmatel_spec *spec = codec->spec;
  237. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  238. }
  239. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  240. {
  241. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  242. struct sigmatel_spec *spec = codec->spec;
  243. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  244. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  245. return 0;
  246. }
  247. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  248. {
  249. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  250. struct sigmatel_spec *spec = codec->spec;
  251. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  252. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  253. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  254. }
  255. #define stac92xx_aloopback_info snd_ctl_boolean_mono_info
  256. static int stac92xx_aloopback_get(struct snd_kcontrol *kcontrol,
  257. struct snd_ctl_elem_value *ucontrol)
  258. {
  259. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  260. struct sigmatel_spec *spec = codec->spec;
  261. ucontrol->value.integer.value[0] = spec->aloopback;
  262. return 0;
  263. }
  264. static int stac92xx_aloopback_put(struct snd_kcontrol *kcontrol,
  265. struct snd_ctl_elem_value *ucontrol)
  266. {
  267. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  268. struct sigmatel_spec *spec = codec->spec;
  269. unsigned int dac_mode;
  270. if (spec->aloopback == ucontrol->value.integer.value[0])
  271. return 0;
  272. spec->aloopback = ucontrol->value.integer.value[0];
  273. dac_mode = snd_hda_codec_read(codec, codec->afg, 0,
  274. kcontrol->private_value & 0xFFFF, 0x0);
  275. if (spec->aloopback) {
  276. snd_hda_power_up(codec);
  277. dac_mode |= 0x40;
  278. } else {
  279. snd_hda_power_down(codec);
  280. dac_mode &= ~0x40;
  281. }
  282. snd_hda_codec_write_cache(codec, codec->afg, 0,
  283. kcontrol->private_value >> 16, dac_mode);
  284. return 1;
  285. }
  286. static int stac92xx_volknob_info(struct snd_kcontrol *kcontrol,
  287. struct snd_ctl_elem_info *uinfo)
  288. {
  289. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  290. uinfo->count = 1;
  291. uinfo->value.integer.min = 0;
  292. uinfo->value.integer.max = 127;
  293. return 0;
  294. }
  295. static int stac92xx_volknob_get(struct snd_kcontrol *kcontrol,
  296. struct snd_ctl_elem_value *ucontrol)
  297. {
  298. ucontrol->value.integer.value[0] = kcontrol->private_value & 0xff;
  299. return 0;
  300. }
  301. static int stac92xx_volknob_put(struct snd_kcontrol *kcontrol,
  302. struct snd_ctl_elem_value *ucontrol)
  303. {
  304. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  305. unsigned int val = kcontrol->private_value & 0xff;
  306. if (val == ucontrol->value.integer.value[0])
  307. return 0;
  308. val = ucontrol->value.integer.value[0];
  309. kcontrol->private_value &= ~0xff;
  310. kcontrol->private_value |= val;
  311. snd_hda_codec_write_cache(codec, kcontrol->private_value >> 16, 0,
  312. AC_VERB_SET_VOLUME_KNOB_CONTROL, val | 0x80);
  313. return 1;
  314. }
  315. static struct hda_verb stac9200_core_init[] = {
  316. /* set dac0mux for dac converter */
  317. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  318. {}
  319. };
  320. static struct hda_verb stac9200_eapd_init[] = {
  321. /* set dac0mux for dac converter */
  322. {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  323. {0x08, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
  324. {}
  325. };
  326. static struct hda_verb stac925x_core_init[] = {
  327. /* set dac0mux for dac converter */
  328. { 0x06, AC_VERB_SET_CONNECT_SEL, 0x00},
  329. {}
  330. };
  331. static struct hda_verb stac922x_core_init[] = {
  332. /* set master volume and direct control */
  333. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  334. {}
  335. };
  336. static struct hda_verb d965_core_init[] = {
  337. /* set master volume and direct control */
  338. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  339. /* unmute node 0x1b */
  340. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  341. /* select node 0x03 as DAC */
  342. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  343. {}
  344. };
  345. static struct hda_verb stac927x_core_init[] = {
  346. /* set master volume and direct control */
  347. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  348. {}
  349. };
  350. static struct hda_verb stac9205_core_init[] = {
  351. /* set master volume and direct control */
  352. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  353. {}
  354. };
  355. #define STAC_INPUT_SOURCE(cnt) \
  356. { \
  357. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  358. .name = "Input Source", \
  359. .count = cnt, \
  360. .info = stac92xx_mux_enum_info, \
  361. .get = stac92xx_mux_enum_get, \
  362. .put = stac92xx_mux_enum_put, \
  363. }
  364. #define STAC_ANALOG_LOOPBACK(verb_read,verb_write) \
  365. { \
  366. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  367. .name = "Analog Loopback", \
  368. .count = 1, \
  369. .info = stac92xx_aloopback_info, \
  370. .get = stac92xx_aloopback_get, \
  371. .put = stac92xx_aloopback_put, \
  372. .private_value = verb_read | (verb_write << 16), \
  373. }
  374. #define STAC_VOLKNOB(knob_nid) \
  375. { \
  376. .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  377. .name = "Master Playback Volume", \
  378. .count = 1, \
  379. .info = stac92xx_volknob_info, \
  380. .get = stac92xx_volknob_get, \
  381. .put = stac92xx_volknob_put, \
  382. .private_value = 127 | (knob_nid << 16), \
  383. }
  384. static struct snd_kcontrol_new stac9200_mixer[] = {
  385. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  386. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  387. STAC_INPUT_SOURCE(1),
  388. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  389. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  390. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  391. { } /* end */
  392. };
  393. static struct snd_kcontrol_new stac925x_mixer[] = {
  394. STAC_INPUT_SOURCE(1),
  395. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_OUTPUT),
  396. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_OUTPUT),
  397. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0f, 0, HDA_OUTPUT),
  398. { } /* end */
  399. };
  400. static struct snd_kcontrol_new stac9205_mixer[] = {
  401. {
  402. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  403. .name = "Digital Input Source",
  404. .count = 1,
  405. .info = stac92xx_dmux_enum_info,
  406. .get = stac92xx_dmux_enum_get,
  407. .put = stac92xx_dmux_enum_put,
  408. },
  409. STAC_INPUT_SOURCE(2),
  410. STAC_ANALOG_LOOPBACK(0xFE0, 0x7E0),
  411. STAC_VOLKNOB(0x24),
  412. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x1b, 0x0, HDA_INPUT),
  413. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1d, 0x0, HDA_OUTPUT),
  414. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x19, 0x0, HDA_OUTPUT),
  415. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x1c, 0x0, HDA_INPUT),
  416. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1e, 0x0, HDA_OUTPUT),
  417. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x1A, 0x0, HDA_OUTPUT),
  418. { } /* end */
  419. };
  420. /* This needs to be generated dynamically based on sequence */
  421. static struct snd_kcontrol_new stac922x_mixer[] = {
  422. STAC_INPUT_SOURCE(2),
  423. STAC_VOLKNOB(0x16),
  424. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x17, 0x0, HDA_INPUT),
  425. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x17, 0x0, HDA_INPUT),
  426. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x12, 0x0, HDA_OUTPUT),
  427. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x18, 0x0, HDA_INPUT),
  428. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x18, 0x0, HDA_INPUT),
  429. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x13, 0x0, HDA_OUTPUT),
  430. { } /* end */
  431. };
  432. static struct snd_kcontrol_new stac927x_mixer[] = {
  433. STAC_INPUT_SOURCE(3),
  434. STAC_VOLKNOB(0x24),
  435. STAC_ANALOG_LOOPBACK(0xFEB, 0x7EB),
  436. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x0, 0x18, 0x0, HDA_INPUT),
  437. HDA_CODEC_MUTE_IDX("Capture Switch", 0x0, 0x1b, 0x0, HDA_OUTPUT),
  438. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x0, 0x15, 0x0, HDA_OUTPUT),
  439. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x1, 0x19, 0x0, HDA_INPUT),
  440. HDA_CODEC_MUTE_IDX("Capture Switch", 0x1, 0x1c, 0x0, HDA_OUTPUT),
  441. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x1, 0x16, 0x0, HDA_OUTPUT),
  442. HDA_CODEC_VOLUME_IDX("Capture Volume", 0x2, 0x1A, 0x0, HDA_INPUT),
  443. HDA_CODEC_MUTE_IDX("Capture Switch", 0x2, 0x1d, 0x0, HDA_OUTPUT),
  444. HDA_CODEC_VOLUME_IDX("Mux Capture Volume", 0x2, 0x17, 0x0, HDA_OUTPUT),
  445. { } /* end */
  446. };
  447. static int stac92xx_build_controls(struct hda_codec *codec)
  448. {
  449. struct sigmatel_spec *spec = codec->spec;
  450. int err;
  451. int i;
  452. err = snd_hda_add_new_ctls(codec, spec->mixer);
  453. if (err < 0)
  454. return err;
  455. for (i = 0; i < spec->num_mixers; i++) {
  456. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  457. if (err < 0)
  458. return err;
  459. }
  460. if (spec->multiout.dig_out_nid) {
  461. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  462. if (err < 0)
  463. return err;
  464. }
  465. if (spec->dig_in_nid) {
  466. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  467. if (err < 0)
  468. return err;
  469. }
  470. return 0;
  471. }
  472. static unsigned int ref9200_pin_configs[8] = {
  473. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  474. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  475. };
  476. /*
  477. STAC 9200 pin configs for
  478. 102801A8
  479. 102801DE
  480. 102801E8
  481. */
  482. static unsigned int dell9200_d21_pin_configs[8] = {
  483. 0x400001f0, 0x400001f1, 0x02214030, 0x01014010,
  484. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  485. };
  486. /*
  487. STAC 9200 pin configs for
  488. 102801C0
  489. 102801C1
  490. */
  491. static unsigned int dell9200_d22_pin_configs[8] = {
  492. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  493. 0x01813020, 0x02a19021, 0x90100140, 0x400001f2,
  494. };
  495. /*
  496. STAC 9200 pin configs for
  497. 102801C4 (Dell Dimension E310)
  498. 102801C5
  499. 102801C7
  500. 102801D9
  501. 102801DA
  502. 102801E3
  503. */
  504. static unsigned int dell9200_d23_pin_configs[8] = {
  505. 0x400001f0, 0x400001f1, 0x0221401f, 0x01014010,
  506. 0x01813020, 0x01a19021, 0x90100140, 0x400001f2,
  507. };
  508. /*
  509. STAC 9200-32 pin configs for
  510. 102801B5 (Dell Inspiron 630m)
  511. 102801D8 (Dell Inspiron 640m)
  512. */
  513. static unsigned int dell9200_m21_pin_configs[8] = {
  514. 0x40c003fa, 0x03441340, 0x0321121f, 0x90170310,
  515. 0x408003fb, 0x03a11020, 0x401003fc, 0x403003fd,
  516. };
  517. /*
  518. STAC 9200-32 pin configs for
  519. 102801C2 (Dell Latitude D620)
  520. 102801C8
  521. 102801CC (Dell Latitude D820)
  522. 102801D4
  523. 102801D6
  524. */
  525. static unsigned int dell9200_m22_pin_configs[8] = {
  526. 0x40c003fa, 0x0144131f, 0x0321121f, 0x90170310,
  527. 0x90a70321, 0x03a11020, 0x401003fb, 0x40f000fc,
  528. };
  529. /*
  530. STAC 9200-32 pin configs for
  531. 102801CE (Dell XPS M1710)
  532. 102801CF (Dell Precision M90)
  533. */
  534. static unsigned int dell9200_m23_pin_configs[8] = {
  535. 0x40c003fa, 0x01441340, 0x0421421f, 0x90170310,
  536. 0x408003fb, 0x04a1102e, 0x90170311, 0x403003fc,
  537. };
  538. /*
  539. STAC 9200-32 pin configs for
  540. 102801C9
  541. 102801CA
  542. 102801CB (Dell Latitude 120L)
  543. 102801D3
  544. */
  545. static unsigned int dell9200_m24_pin_configs[8] = {
  546. 0x40c003fa, 0x404003fb, 0x0321121f, 0x90170310,
  547. 0x408003fc, 0x03a11020, 0x401003fd, 0x403003fe,
  548. };
  549. /*
  550. STAC 9200-32 pin configs for
  551. 102801BD (Dell Inspiron E1505n)
  552. 102801EE
  553. 102801EF
  554. */
  555. static unsigned int dell9200_m25_pin_configs[8] = {
  556. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  557. 0x408003fb, 0x04a11020, 0x401003fc, 0x403003fd,
  558. };
  559. /*
  560. STAC 9200-32 pin configs for
  561. 102801F5 (Dell Inspiron 1501)
  562. 102801F6
  563. */
  564. static unsigned int dell9200_m26_pin_configs[8] = {
  565. 0x40c003fa, 0x404003fb, 0x0421121f, 0x90170310,
  566. 0x408003fc, 0x04a11020, 0x401003fd, 0x403003fe,
  567. };
  568. /*
  569. STAC 9200-32
  570. 102801CD (Dell Inspiron E1705/9400)
  571. */
  572. static unsigned int dell9200_m27_pin_configs[8] = {
  573. 0x40c003fa, 0x01441340, 0x0421121f, 0x90170310,
  574. 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
  575. };
  576. static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
  577. [STAC_REF] = ref9200_pin_configs,
  578. [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
  579. [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
  580. [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
  581. [STAC_9200_DELL_M21] = dell9200_m21_pin_configs,
  582. [STAC_9200_DELL_M22] = dell9200_m22_pin_configs,
  583. [STAC_9200_DELL_M23] = dell9200_m23_pin_configs,
  584. [STAC_9200_DELL_M24] = dell9200_m24_pin_configs,
  585. [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
  586. [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
  587. [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
  588. };
  589. static const char *stac9200_models[STAC_9200_MODELS] = {
  590. [STAC_REF] = "ref",
  591. [STAC_9200_DELL_D21] = "dell-d21",
  592. [STAC_9200_DELL_D22] = "dell-d22",
  593. [STAC_9200_DELL_D23] = "dell-d23",
  594. [STAC_9200_DELL_M21] = "dell-m21",
  595. [STAC_9200_DELL_M22] = "dell-m22",
  596. [STAC_9200_DELL_M23] = "dell-m23",
  597. [STAC_9200_DELL_M24] = "dell-m24",
  598. [STAC_9200_DELL_M25] = "dell-m25",
  599. [STAC_9200_DELL_M26] = "dell-m26",
  600. [STAC_9200_DELL_M27] = "dell-m27",
  601. [STAC_9200_GATEWAY] = "gateway",
  602. };
  603. static struct snd_pci_quirk stac9200_cfg_tbl[] = {
  604. /* SigmaTel reference board */
  605. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  606. "DFI LanParty", STAC_REF),
  607. /* Dell laptops have BIOS problem */
  608. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a8,
  609. "unknown Dell", STAC_9200_DELL_D21),
  610. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01b5,
  611. "Dell Inspiron 630m", STAC_9200_DELL_M21),
  612. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bd,
  613. "Dell Inspiron E1505n", STAC_9200_DELL_M25),
  614. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c0,
  615. "unknown Dell", STAC_9200_DELL_D22),
  616. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c1,
  617. "unknown Dell", STAC_9200_DELL_D22),
  618. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c2,
  619. "Dell Latitude D620", STAC_9200_DELL_M22),
  620. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c5,
  621. "unknown Dell", STAC_9200_DELL_D23),
  622. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c7,
  623. "unknown Dell", STAC_9200_DELL_D23),
  624. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c8,
  625. "unknown Dell", STAC_9200_DELL_M22),
  626. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01c9,
  627. "unknown Dell", STAC_9200_DELL_M24),
  628. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ca,
  629. "unknown Dell", STAC_9200_DELL_M24),
  630. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cb,
  631. "Dell Latitude 120L", STAC_9200_DELL_M24),
  632. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cc,
  633. "Dell Latitude D820", STAC_9200_DELL_M22),
  634. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cd,
  635. "Dell Inspiron E1705/9400", STAC_9200_DELL_M27),
  636. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ce,
  637. "Dell XPS M1710", STAC_9200_DELL_M23),
  638. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01cf,
  639. "Dell Precision M90", STAC_9200_DELL_M23),
  640. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d3,
  641. "unknown Dell", STAC_9200_DELL_M22),
  642. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d4,
  643. "unknown Dell", STAC_9200_DELL_M22),
  644. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d6,
  645. "unknown Dell", STAC_9200_DELL_M22),
  646. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d8,
  647. "Dell Inspiron 640m", STAC_9200_DELL_M21),
  648. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d9,
  649. "unknown Dell", STAC_9200_DELL_D23),
  650. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01da,
  651. "unknown Dell", STAC_9200_DELL_D23),
  652. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01de,
  653. "unknown Dell", STAC_9200_DELL_D21),
  654. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e3,
  655. "unknown Dell", STAC_9200_DELL_D23),
  656. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01e8,
  657. "unknown Dell", STAC_9200_DELL_D21),
  658. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ee,
  659. "unknown Dell", STAC_9200_DELL_M25),
  660. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ef,
  661. "unknown Dell", STAC_9200_DELL_M25),
  662. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f5,
  663. "Dell Inspiron 1501", STAC_9200_DELL_M26),
  664. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
  665. "unknown Dell", STAC_9200_DELL_M26),
  666. /* Panasonic */
  667. SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF),
  668. /* Gateway machines needs EAPD to be set on resume */
  669. SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
  670. SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
  671. STAC_9200_GATEWAY),
  672. SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
  673. STAC_9200_GATEWAY),
  674. {} /* terminator */
  675. };
  676. static unsigned int ref925x_pin_configs[8] = {
  677. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  678. 0x90a70320, 0x02214210, 0x400003f1, 0x9033032e,
  679. };
  680. static unsigned int stac925x_MA6_pin_configs[8] = {
  681. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  682. 0x90a70320, 0x90100211, 0x400003f1, 0x9033032e,
  683. };
  684. static unsigned int stac925x_PA6_pin_configs[8] = {
  685. 0x40c003f0, 0x424503f2, 0x01813022, 0x02a19021,
  686. 0x50a103f0, 0x90100211, 0x400003f1, 0x9033032e,
  687. };
  688. static unsigned int stac925xM2_2_pin_configs[8] = {
  689. 0x40c003f3, 0x424503f2, 0x04180011, 0x02a19020,
  690. 0x50a103f0, 0x90100212, 0x400003f1, 0x9033032e,
  691. };
  692. static unsigned int *stac925x_brd_tbl[STAC_925x_MODELS] = {
  693. [STAC_REF] = ref925x_pin_configs,
  694. [STAC_M2_2] = stac925xM2_2_pin_configs,
  695. [STAC_MA6] = stac925x_MA6_pin_configs,
  696. [STAC_PA6] = stac925x_PA6_pin_configs,
  697. };
  698. static const char *stac925x_models[STAC_925x_MODELS] = {
  699. [STAC_REF] = "ref",
  700. [STAC_M2_2] = "m2-2",
  701. [STAC_MA6] = "m6",
  702. [STAC_PA6] = "pa6",
  703. };
  704. static struct snd_pci_quirk stac925x_cfg_tbl[] = {
  705. /* SigmaTel reference board */
  706. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, "DFI LanParty", STAC_REF),
  707. SND_PCI_QUIRK(0x8384, 0x7632, "Stac9202 Reference Board", STAC_REF),
  708. SND_PCI_QUIRK(0x107b, 0x0316, "Gateway M255", STAC_REF),
  709. SND_PCI_QUIRK(0x107b, 0x0366, "Gateway MP6954", STAC_REF),
  710. SND_PCI_QUIRK(0x107b, 0x0461, "Gateway NX560XL", STAC_MA6),
  711. SND_PCI_QUIRK(0x107b, 0x0681, "Gateway NX860", STAC_PA6),
  712. SND_PCI_QUIRK(0x1002, 0x437b, "Gateway MX6453", STAC_M2_2),
  713. {} /* terminator */
  714. };
  715. static unsigned int ref922x_pin_configs[10] = {
  716. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  717. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  718. 0x40000100, 0x40000100,
  719. };
  720. /*
  721. STAC 922X pin configs for
  722. 102801A7
  723. 102801AB
  724. 102801A9
  725. 102801D1
  726. 102801D2
  727. */
  728. static unsigned int dell_922x_d81_pin_configs[10] = {
  729. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  730. 0x02a19020, 0x01117011, 0x400001f0, 0x400001f1,
  731. 0x01813122, 0x400001f2,
  732. };
  733. /*
  734. STAC 922X pin configs for
  735. 102801AC
  736. 102801D0
  737. */
  738. static unsigned int dell_922x_d82_pin_configs[10] = {
  739. 0x02214030, 0x01a19021, 0x01111012, 0x01114010,
  740. 0x02a19020, 0x01117011, 0x01451140, 0x400001f0,
  741. 0x01813122, 0x400001f1,
  742. };
  743. /*
  744. STAC 922X pin configs for
  745. 102801BF
  746. */
  747. static unsigned int dell_922x_m81_pin_configs[10] = {
  748. 0x0321101f, 0x01112024, 0x01111222, 0x91174220,
  749. 0x03a11050, 0x01116221, 0x90a70330, 0x01452340,
  750. 0x40C003f1, 0x405003f0,
  751. };
  752. /*
  753. STAC 9221 A1 pin configs for
  754. 102801D7 (Dell XPS M1210)
  755. */
  756. static unsigned int dell_922x_m82_pin_configs[10] = {
  757. 0x0221121f, 0x408103ff, 0x02111212, 0x90100310,
  758. 0x408003f1, 0x02111211, 0x03451340, 0x40c003f2,
  759. 0x508003f3, 0x405003f4,
  760. };
  761. static unsigned int d945gtp3_pin_configs[10] = {
  762. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  763. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  764. 0x02a19120, 0x40000100,
  765. };
  766. static unsigned int d945gtp5_pin_configs[10] = {
  767. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  768. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  769. 0x02a19320, 0x40000100,
  770. };
  771. static unsigned int intel_mac_v1_pin_configs[10] = {
  772. 0x0121e21f, 0x400000ff, 0x9017e110, 0x400000fd,
  773. 0x400000fe, 0x0181e020, 0x1145e030, 0x11c5e240,
  774. 0x400000fc, 0x400000fb,
  775. };
  776. static unsigned int intel_mac_v2_pin_configs[10] = {
  777. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  778. 0x400000fe, 0x0181e020, 0x1145e230, 0x500000fa,
  779. 0x400000fc, 0x400000fb,
  780. };
  781. static unsigned int intel_mac_v3_pin_configs[10] = {
  782. 0x0121e21f, 0x90a7012e, 0x9017e110, 0x400000fd,
  783. 0x400000fe, 0x0181e020, 0x1145e230, 0x11c5e240,
  784. 0x400000fc, 0x400000fb,
  785. };
  786. static unsigned int intel_mac_v4_pin_configs[10] = {
  787. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  788. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  789. 0x400000fc, 0x400000fb,
  790. };
  791. static unsigned int intel_mac_v5_pin_configs[10] = {
  792. 0x0321e21f, 0x03a1e02e, 0x9017e110, 0x9017e11f,
  793. 0x400000fe, 0x0381e020, 0x1345e230, 0x13c5e240,
  794. 0x400000fc, 0x400000fb,
  795. };
  796. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  797. [STAC_D945_REF] = ref922x_pin_configs,
  798. [STAC_D945GTP3] = d945gtp3_pin_configs,
  799. [STAC_D945GTP5] = d945gtp5_pin_configs,
  800. [STAC_INTEL_MAC_V1] = intel_mac_v1_pin_configs,
  801. [STAC_INTEL_MAC_V2] = intel_mac_v2_pin_configs,
  802. [STAC_INTEL_MAC_V3] = intel_mac_v3_pin_configs,
  803. [STAC_INTEL_MAC_V4] = intel_mac_v4_pin_configs,
  804. [STAC_INTEL_MAC_V5] = intel_mac_v5_pin_configs,
  805. /* for backward compatibility */
  806. [STAC_MACMINI] = intel_mac_v3_pin_configs,
  807. [STAC_MACBOOK] = intel_mac_v5_pin_configs,
  808. [STAC_MACBOOK_PRO_V1] = intel_mac_v3_pin_configs,
  809. [STAC_MACBOOK_PRO_V2] = intel_mac_v3_pin_configs,
  810. [STAC_IMAC_INTEL] = intel_mac_v2_pin_configs,
  811. [STAC_IMAC_INTEL_20] = intel_mac_v3_pin_configs,
  812. [STAC_922X_DELL_D81] = dell_922x_d81_pin_configs,
  813. [STAC_922X_DELL_D82] = dell_922x_d82_pin_configs,
  814. [STAC_922X_DELL_M81] = dell_922x_m81_pin_configs,
  815. [STAC_922X_DELL_M82] = dell_922x_m82_pin_configs,
  816. };
  817. static const char *stac922x_models[STAC_922X_MODELS] = {
  818. [STAC_D945_REF] = "ref",
  819. [STAC_D945GTP5] = "5stack",
  820. [STAC_D945GTP3] = "3stack",
  821. [STAC_INTEL_MAC_V1] = "intel-mac-v1",
  822. [STAC_INTEL_MAC_V2] = "intel-mac-v2",
  823. [STAC_INTEL_MAC_V3] = "intel-mac-v3",
  824. [STAC_INTEL_MAC_V4] = "intel-mac-v4",
  825. [STAC_INTEL_MAC_V5] = "intel-mac-v5",
  826. /* for backward compatibility */
  827. [STAC_MACMINI] = "macmini",
  828. [STAC_MACBOOK] = "macbook",
  829. [STAC_MACBOOK_PRO_V1] = "macbook-pro-v1",
  830. [STAC_MACBOOK_PRO_V2] = "macbook-pro",
  831. [STAC_IMAC_INTEL] = "imac-intel",
  832. [STAC_IMAC_INTEL_20] = "imac-intel-20",
  833. [STAC_922X_DELL_D81] = "dell-d81",
  834. [STAC_922X_DELL_D82] = "dell-d82",
  835. [STAC_922X_DELL_M81] = "dell-m81",
  836. [STAC_922X_DELL_M82] = "dell-m82",
  837. };
  838. static struct snd_pci_quirk stac922x_cfg_tbl[] = {
  839. /* SigmaTel reference board */
  840. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  841. "DFI LanParty", STAC_D945_REF),
  842. /* Intel 945G based systems */
  843. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0101,
  844. "Intel D945G", STAC_D945GTP3),
  845. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0202,
  846. "Intel D945G", STAC_D945GTP3),
  847. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0606,
  848. "Intel D945G", STAC_D945GTP3),
  849. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0601,
  850. "Intel D945G", STAC_D945GTP3),
  851. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0111,
  852. "Intel D945G", STAC_D945GTP3),
  853. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1115,
  854. "Intel D945G", STAC_D945GTP3),
  855. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1116,
  856. "Intel D945G", STAC_D945GTP3),
  857. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1117,
  858. "Intel D945G", STAC_D945GTP3),
  859. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1118,
  860. "Intel D945G", STAC_D945GTP3),
  861. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x1119,
  862. "Intel D945G", STAC_D945GTP3),
  863. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x8826,
  864. "Intel D945G", STAC_D945GTP3),
  865. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5049,
  866. "Intel D945G", STAC_D945GTP3),
  867. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5055,
  868. "Intel D945G", STAC_D945GTP3),
  869. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x5048,
  870. "Intel D945G", STAC_D945GTP3),
  871. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0110,
  872. "Intel D945G", STAC_D945GTP3),
  873. /* Intel D945G 5-stack systems */
  874. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0404,
  875. "Intel D945G", STAC_D945GTP5),
  876. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0303,
  877. "Intel D945G", STAC_D945GTP5),
  878. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0013,
  879. "Intel D945G", STAC_D945GTP5),
  880. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0417,
  881. "Intel D945G", STAC_D945GTP5),
  882. /* Intel 945P based systems */
  883. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0b0b,
  884. "Intel D945P", STAC_D945GTP3),
  885. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0112,
  886. "Intel D945P", STAC_D945GTP3),
  887. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0d0d,
  888. "Intel D945P", STAC_D945GTP3),
  889. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0909,
  890. "Intel D945P", STAC_D945GTP3),
  891. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0505,
  892. "Intel D945P", STAC_D945GTP3),
  893. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x0707,
  894. "Intel D945P", STAC_D945GTP5),
  895. /* other systems */
  896. /* Apple Mac Mini (early 2006) */
  897. SND_PCI_QUIRK(0x8384, 0x7680,
  898. "Mac Mini", STAC_INTEL_MAC_V3),
  899. /* Dell systems */
  900. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a7,
  901. "unknown Dell", STAC_922X_DELL_D81),
  902. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01a9,
  903. "unknown Dell", STAC_922X_DELL_D81),
  904. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ab,
  905. "unknown Dell", STAC_922X_DELL_D81),
  906. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ac,
  907. "unknown Dell", STAC_922X_DELL_D82),
  908. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01bf,
  909. "unknown Dell", STAC_922X_DELL_M81),
  910. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d0,
  911. "unknown Dell", STAC_922X_DELL_D82),
  912. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d1,
  913. "unknown Dell", STAC_922X_DELL_D81),
  914. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d2,
  915. "unknown Dell", STAC_922X_DELL_D81),
  916. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01d7,
  917. "Dell XPS M1210", STAC_922X_DELL_M82),
  918. {} /* terminator */
  919. };
  920. static unsigned int ref927x_pin_configs[14] = {
  921. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  922. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  923. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  924. 0x01c42190, 0x40000100,
  925. };
  926. static unsigned int d965_3st_pin_configs[14] = {
  927. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  928. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  929. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  930. 0x40000100, 0x40000100
  931. };
  932. static unsigned int d965_5st_pin_configs[14] = {
  933. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  934. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  935. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  936. 0x40000100, 0x40000100
  937. };
  938. static unsigned int dell_3st_pin_configs[14] = {
  939. 0x02211230, 0x02a11220, 0x01a19040, 0x01114210,
  940. 0x01111212, 0x01116211, 0x01813050, 0x01112214,
  941. 0x403003fa, 0x40000100, 0x40000100, 0x404003fb,
  942. 0x40c003fc, 0x40000100
  943. };
  944. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  945. [STAC_D965_REF] = ref927x_pin_configs,
  946. [STAC_D965_3ST] = d965_3st_pin_configs,
  947. [STAC_D965_5ST] = d965_5st_pin_configs,
  948. [STAC_DELL_3ST] = dell_3st_pin_configs,
  949. };
  950. static const char *stac927x_models[STAC_927X_MODELS] = {
  951. [STAC_D965_REF] = "ref",
  952. [STAC_D965_3ST] = "3stack",
  953. [STAC_D965_5ST] = "5stack",
  954. [STAC_DELL_3ST] = "dell-3stack",
  955. };
  956. static struct snd_pci_quirk stac927x_cfg_tbl[] = {
  957. /* SigmaTel reference board */
  958. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  959. "DFI LanParty", STAC_D965_REF),
  960. /* Intel 946 based systems */
  961. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x3d01, "Intel D946", STAC_D965_3ST),
  962. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0xa301, "Intel D946", STAC_D965_3ST),
  963. /* 965 based 3 stack systems */
  964. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2116, "Intel D965", STAC_D965_3ST),
  965. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2115, "Intel D965", STAC_D965_3ST),
  966. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2114, "Intel D965", STAC_D965_3ST),
  967. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2113, "Intel D965", STAC_D965_3ST),
  968. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2112, "Intel D965", STAC_D965_3ST),
  969. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2111, "Intel D965", STAC_D965_3ST),
  970. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2110, "Intel D965", STAC_D965_3ST),
  971. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2009, "Intel D965", STAC_D965_3ST),
  972. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2008, "Intel D965", STAC_D965_3ST),
  973. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2007, "Intel D965", STAC_D965_3ST),
  974. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2006, "Intel D965", STAC_D965_3ST),
  975. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2005, "Intel D965", STAC_D965_3ST),
  976. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2004, "Intel D965", STAC_D965_3ST),
  977. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2003, "Intel D965", STAC_D965_3ST),
  978. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2002, "Intel D965", STAC_D965_3ST),
  979. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2001, "Intel D965", STAC_D965_3ST),
  980. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f3, "Dell Inspiron 1420", STAC_D965_3ST),
  981. /* Dell 3 stack systems */
  982. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01dd, "Dell Dimension E520", STAC_DELL_3ST),
  983. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ed, "Dell ", STAC_DELL_3ST),
  984. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f4, "Dell ", STAC_DELL_3ST),
  985. /* 965 based 5 stack systems */
  986. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0209, "Dell XPS 1330", STAC_D965_5ST),
  987. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2301, "Intel D965", STAC_D965_5ST),
  988. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2302, "Intel D965", STAC_D965_5ST),
  989. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2303, "Intel D965", STAC_D965_5ST),
  990. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2304, "Intel D965", STAC_D965_5ST),
  991. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2305, "Intel D965", STAC_D965_5ST),
  992. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2501, "Intel D965", STAC_D965_5ST),
  993. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2502, "Intel D965", STAC_D965_5ST),
  994. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2503, "Intel D965", STAC_D965_5ST),
  995. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2504, "Intel D965", STAC_D965_5ST),
  996. {} /* terminator */
  997. };
  998. static unsigned int ref9205_pin_configs[12] = {
  999. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  1000. 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
  1001. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  1002. };
  1003. /*
  1004. STAC 9205 pin configs for
  1005. 102801F1
  1006. 102801F2
  1007. 102801FC
  1008. 102801FD
  1009. 10280204
  1010. 1028021F
  1011. */
  1012. static unsigned int dell_9205_m42_pin_configs[12] = {
  1013. 0x0321101F, 0x03A11020, 0x400003FA, 0x90170310,
  1014. 0x400003FB, 0x400003FC, 0x400003FD, 0x40F000F9,
  1015. 0x90A60330, 0x400003FF, 0x0144131F, 0x40C003FE,
  1016. };
  1017. /*
  1018. STAC 9205 pin configs for
  1019. 102801F9
  1020. 102801FA
  1021. 102801FE
  1022. 102801FF (Dell Precision M4300)
  1023. 10280206
  1024. 10280200
  1025. 10280201
  1026. */
  1027. static unsigned int dell_9205_m43_pin_configs[12] = {
  1028. 0x0321101f, 0x03a11020, 0x90a70330, 0x90170310,
  1029. 0x400000fe, 0x400000ff, 0x400000fd, 0x40f000f9,
  1030. 0x400000fa, 0x400000fc, 0x0144131f, 0x40c003f8,
  1031. };
  1032. static unsigned int dell_9205_m44_pin_configs[12] = {
  1033. 0x0421101f, 0x04a11020, 0x400003fa, 0x90170310,
  1034. 0x400003fb, 0x400003fc, 0x400003fd, 0x400003f9,
  1035. 0x90a60330, 0x400003ff, 0x01441340, 0x40c003fe,
  1036. };
  1037. static unsigned int *stac9205_brd_tbl[STAC_9205_MODELS] = {
  1038. [STAC_9205_REF] = ref9205_pin_configs,
  1039. [STAC_9205_DELL_M42] = dell_9205_m42_pin_configs,
  1040. [STAC_9205_DELL_M43] = dell_9205_m43_pin_configs,
  1041. [STAC_9205_DELL_M44] = dell_9205_m44_pin_configs,
  1042. };
  1043. static const char *stac9205_models[STAC_9205_MODELS] = {
  1044. [STAC_9205_REF] = "ref",
  1045. [STAC_9205_DELL_M42] = "dell-m42",
  1046. [STAC_9205_DELL_M43] = "dell-m43",
  1047. [STAC_9205_DELL_M44] = "dell-m44",
  1048. };
  1049. static struct snd_pci_quirk stac9205_cfg_tbl[] = {
  1050. /* SigmaTel reference board */
  1051. SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
  1052. "DFI LanParty", STAC_9205_REF),
  1053. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1054. "unknown Dell", STAC_9205_DELL_M42),
  1055. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1056. "unknown Dell", STAC_9205_DELL_M42),
  1057. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f8,
  1058. "Dell Precision", STAC_9205_DELL_M43),
  1059. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021c,
  1060. "Dell Precision", STAC_9205_DELL_M43),
  1061. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f9,
  1062. "Dell Precision", STAC_9205_DELL_M43),
  1063. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021b,
  1064. "Dell Precision", STAC_9205_DELL_M43),
  1065. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fa,
  1066. "Dell Precision", STAC_9205_DELL_M43),
  1067. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1068. "unknown Dell", STAC_9205_DELL_M42),
  1069. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1070. "unknown Dell", STAC_9205_DELL_M42),
  1071. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fe,
  1072. "Dell Precision", STAC_9205_DELL_M43),
  1073. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01ff,
  1074. "Dell Precision M4300", STAC_9205_DELL_M43),
  1075. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0206,
  1076. "Dell Precision", STAC_9205_DELL_M43),
  1077. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f1,
  1078. "Dell Inspiron", STAC_9205_DELL_M44),
  1079. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f2,
  1080. "Dell Inspiron", STAC_9205_DELL_M44),
  1081. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fc,
  1082. "Dell Inspiron", STAC_9205_DELL_M44),
  1083. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01fd,
  1084. "Dell Inspiron", STAC_9205_DELL_M44),
  1085. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0204,
  1086. "unknown Dell", STAC_9205_DELL_M42),
  1087. SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x021f,
  1088. "Dell Inspiron", STAC_9205_DELL_M44),
  1089. {} /* terminator */
  1090. };
  1091. static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
  1092. {
  1093. int i;
  1094. struct sigmatel_spec *spec = codec->spec;
  1095. if (! spec->bios_pin_configs) {
  1096. spec->bios_pin_configs = kcalloc(spec->num_pins,
  1097. sizeof(*spec->bios_pin_configs), GFP_KERNEL);
  1098. if (! spec->bios_pin_configs)
  1099. return -ENOMEM;
  1100. }
  1101. for (i = 0; i < spec->num_pins; i++) {
  1102. hda_nid_t nid = spec->pin_nids[i];
  1103. unsigned int pin_cfg;
  1104. pin_cfg = snd_hda_codec_read(codec, nid, 0,
  1105. AC_VERB_GET_CONFIG_DEFAULT, 0x00);
  1106. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
  1107. nid, pin_cfg);
  1108. spec->bios_pin_configs[i] = pin_cfg;
  1109. }
  1110. return 0;
  1111. }
  1112. static void stac92xx_set_config_reg(struct hda_codec *codec,
  1113. hda_nid_t pin_nid, unsigned int pin_config)
  1114. {
  1115. int i;
  1116. snd_hda_codec_write(codec, pin_nid, 0,
  1117. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  1118. pin_config & 0x000000ff);
  1119. snd_hda_codec_write(codec, pin_nid, 0,
  1120. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  1121. (pin_config & 0x0000ff00) >> 8);
  1122. snd_hda_codec_write(codec, pin_nid, 0,
  1123. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  1124. (pin_config & 0x00ff0000) >> 16);
  1125. snd_hda_codec_write(codec, pin_nid, 0,
  1126. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  1127. pin_config >> 24);
  1128. i = snd_hda_codec_read(codec, pin_nid, 0,
  1129. AC_VERB_GET_CONFIG_DEFAULT,
  1130. 0x00);
  1131. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n",
  1132. pin_nid, i);
  1133. }
  1134. static void stac92xx_set_config_regs(struct hda_codec *codec)
  1135. {
  1136. int i;
  1137. struct sigmatel_spec *spec = codec->spec;
  1138. if (!spec->pin_configs)
  1139. return;
  1140. for (i = 0; i < spec->num_pins; i++)
  1141. stac92xx_set_config_reg(codec, spec->pin_nids[i],
  1142. spec->pin_configs[i]);
  1143. }
  1144. static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
  1145. {
  1146. struct sigmatel_spec *spec = codec->spec;
  1147. /* Configure GPIOx as output */
  1148. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1149. AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
  1150. /* Configure GPIOx as CMOS */
  1151. snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
  1152. /* Assert GPIOx */
  1153. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1154. AC_VERB_SET_GPIO_DATA, spec->gpio_data);
  1155. /* Enable GPIOx */
  1156. snd_hda_codec_write_cache(codec, codec->afg, 0,
  1157. AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
  1158. }
  1159. /*
  1160. * Analog playback callbacks
  1161. */
  1162. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1163. struct hda_codec *codec,
  1164. struct snd_pcm_substream *substream)
  1165. {
  1166. struct sigmatel_spec *spec = codec->spec;
  1167. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  1168. }
  1169. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1170. struct hda_codec *codec,
  1171. unsigned int stream_tag,
  1172. unsigned int format,
  1173. struct snd_pcm_substream *substream)
  1174. {
  1175. struct sigmatel_spec *spec = codec->spec;
  1176. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  1177. }
  1178. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1179. struct hda_codec *codec,
  1180. struct snd_pcm_substream *substream)
  1181. {
  1182. struct sigmatel_spec *spec = codec->spec;
  1183. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  1184. }
  1185. /*
  1186. * Digital playback callbacks
  1187. */
  1188. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1189. struct hda_codec *codec,
  1190. struct snd_pcm_substream *substream)
  1191. {
  1192. struct sigmatel_spec *spec = codec->spec;
  1193. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1194. }
  1195. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1196. struct hda_codec *codec,
  1197. struct snd_pcm_substream *substream)
  1198. {
  1199. struct sigmatel_spec *spec = codec->spec;
  1200. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1201. }
  1202. static int stac92xx_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1203. struct hda_codec *codec,
  1204. unsigned int stream_tag,
  1205. unsigned int format,
  1206. struct snd_pcm_substream *substream)
  1207. {
  1208. struct sigmatel_spec *spec = codec->spec;
  1209. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1210. stream_tag, format, substream);
  1211. }
  1212. /*
  1213. * Analog capture callbacks
  1214. */
  1215. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  1216. struct hda_codec *codec,
  1217. unsigned int stream_tag,
  1218. unsigned int format,
  1219. struct snd_pcm_substream *substream)
  1220. {
  1221. struct sigmatel_spec *spec = codec->spec;
  1222. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  1223. stream_tag, 0, format);
  1224. return 0;
  1225. }
  1226. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1227. struct hda_codec *codec,
  1228. struct snd_pcm_substream *substream)
  1229. {
  1230. struct sigmatel_spec *spec = codec->spec;
  1231. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  1232. return 0;
  1233. }
  1234. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  1235. .substreams = 1,
  1236. .channels_min = 2,
  1237. .channels_max = 2,
  1238. /* NID is set in stac92xx_build_pcms */
  1239. .ops = {
  1240. .open = stac92xx_dig_playback_pcm_open,
  1241. .close = stac92xx_dig_playback_pcm_close,
  1242. .prepare = stac92xx_dig_playback_pcm_prepare
  1243. },
  1244. };
  1245. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  1246. .substreams = 1,
  1247. .channels_min = 2,
  1248. .channels_max = 2,
  1249. /* NID is set in stac92xx_build_pcms */
  1250. };
  1251. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  1252. .substreams = 1,
  1253. .channels_min = 2,
  1254. .channels_max = 8,
  1255. .nid = 0x02, /* NID to query formats and rates */
  1256. .ops = {
  1257. .open = stac92xx_playback_pcm_open,
  1258. .prepare = stac92xx_playback_pcm_prepare,
  1259. .cleanup = stac92xx_playback_pcm_cleanup
  1260. },
  1261. };
  1262. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  1263. .substreams = 1,
  1264. .channels_min = 2,
  1265. .channels_max = 2,
  1266. .nid = 0x06, /* NID to query formats and rates */
  1267. .ops = {
  1268. .open = stac92xx_playback_pcm_open,
  1269. .prepare = stac92xx_playback_pcm_prepare,
  1270. .cleanup = stac92xx_playback_pcm_cleanup
  1271. },
  1272. };
  1273. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  1274. .channels_min = 2,
  1275. .channels_max = 2,
  1276. /* NID + .substreams is set in stac92xx_build_pcms */
  1277. .ops = {
  1278. .prepare = stac92xx_capture_pcm_prepare,
  1279. .cleanup = stac92xx_capture_pcm_cleanup
  1280. },
  1281. };
  1282. static int stac92xx_build_pcms(struct hda_codec *codec)
  1283. {
  1284. struct sigmatel_spec *spec = codec->spec;
  1285. struct hda_pcm *info = spec->pcm_rec;
  1286. codec->num_pcms = 1;
  1287. codec->pcm_info = info;
  1288. info->name = "STAC92xx Analog";
  1289. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  1290. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  1291. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  1292. info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams = spec->num_adcs;
  1293. if (spec->alt_switch) {
  1294. codec->num_pcms++;
  1295. info++;
  1296. info->name = "STAC92xx Analog Alt";
  1297. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  1298. }
  1299. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  1300. codec->num_pcms++;
  1301. info++;
  1302. info->name = "STAC92xx Digital";
  1303. if (spec->multiout.dig_out_nid) {
  1304. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  1305. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  1306. }
  1307. if (spec->dig_in_nid) {
  1308. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  1309. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  1310. }
  1311. }
  1312. return 0;
  1313. }
  1314. static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
  1315. {
  1316. unsigned int pincap = snd_hda_param_read(codec, nid,
  1317. AC_PAR_PIN_CAP);
  1318. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  1319. if (pincap & AC_PINCAP_VREF_100)
  1320. return AC_PINCTL_VREF_100;
  1321. if (pincap & AC_PINCAP_VREF_80)
  1322. return AC_PINCTL_VREF_80;
  1323. if (pincap & AC_PINCAP_VREF_50)
  1324. return AC_PINCTL_VREF_50;
  1325. if (pincap & AC_PINCAP_VREF_GRD)
  1326. return AC_PINCTL_VREF_GRD;
  1327. return 0;
  1328. }
  1329. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  1330. {
  1331. snd_hda_codec_write_cache(codec, nid, 0,
  1332. AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  1333. }
  1334. #define stac92xx_io_switch_info snd_ctl_boolean_mono_info
  1335. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1336. {
  1337. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1338. struct sigmatel_spec *spec = codec->spec;
  1339. int io_idx = kcontrol-> private_value & 0xff;
  1340. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  1341. return 0;
  1342. }
  1343. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  1344. {
  1345. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1346. struct sigmatel_spec *spec = codec->spec;
  1347. hda_nid_t nid = kcontrol->private_value >> 8;
  1348. int io_idx = kcontrol-> private_value & 0xff;
  1349. unsigned short val = ucontrol->value.integer.value[0];
  1350. spec->io_switch[io_idx] = val;
  1351. if (val)
  1352. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1353. else {
  1354. unsigned int pinctl = AC_PINCTL_IN_EN;
  1355. if (io_idx) /* set VREF for mic */
  1356. pinctl |= stac92xx_get_vref(codec, nid);
  1357. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1358. }
  1359. return 1;
  1360. }
  1361. #define stac92xx_clfe_switch_info snd_ctl_boolean_mono_info
  1362. static int stac92xx_clfe_switch_get(struct snd_kcontrol *kcontrol,
  1363. struct snd_ctl_elem_value *ucontrol)
  1364. {
  1365. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1366. struct sigmatel_spec *spec = codec->spec;
  1367. ucontrol->value.integer.value[0] = spec->clfe_swap;
  1368. return 0;
  1369. }
  1370. static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
  1371. struct snd_ctl_elem_value *ucontrol)
  1372. {
  1373. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1374. struct sigmatel_spec *spec = codec->spec;
  1375. hda_nid_t nid = kcontrol->private_value & 0xff;
  1376. if (spec->clfe_swap == ucontrol->value.integer.value[0])
  1377. return 0;
  1378. spec->clfe_swap = ucontrol->value.integer.value[0];
  1379. snd_hda_codec_write_cache(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
  1380. spec->clfe_swap ? 0x4 : 0x0);
  1381. return 1;
  1382. }
  1383. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  1384. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1385. .name = xname, \
  1386. .index = 0, \
  1387. .info = stac92xx_io_switch_info, \
  1388. .get = stac92xx_io_switch_get, \
  1389. .put = stac92xx_io_switch_put, \
  1390. .private_value = xpval, \
  1391. }
  1392. #define STAC_CODEC_CLFE_SWITCH(xname, xpval) \
  1393. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  1394. .name = xname, \
  1395. .index = 0, \
  1396. .info = stac92xx_clfe_switch_info, \
  1397. .get = stac92xx_clfe_switch_get, \
  1398. .put = stac92xx_clfe_switch_put, \
  1399. .private_value = xpval, \
  1400. }
  1401. enum {
  1402. STAC_CTL_WIDGET_VOL,
  1403. STAC_CTL_WIDGET_MUTE,
  1404. STAC_CTL_WIDGET_IO_SWITCH,
  1405. STAC_CTL_WIDGET_CLFE_SWITCH
  1406. };
  1407. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  1408. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  1409. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  1410. STAC_CODEC_IO_SWITCH(NULL, 0),
  1411. STAC_CODEC_CLFE_SWITCH(NULL, 0),
  1412. };
  1413. /* add dynamic controls */
  1414. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  1415. {
  1416. struct snd_kcontrol_new *knew;
  1417. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  1418. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  1419. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  1420. if (! knew)
  1421. return -ENOMEM;
  1422. if (spec->kctl_alloc) {
  1423. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  1424. kfree(spec->kctl_alloc);
  1425. }
  1426. spec->kctl_alloc = knew;
  1427. spec->num_kctl_alloc = num;
  1428. }
  1429. knew = &spec->kctl_alloc[spec->num_kctl_used];
  1430. *knew = stac92xx_control_templates[type];
  1431. knew->name = kstrdup(name, GFP_KERNEL);
  1432. if (! knew->name)
  1433. return -ENOMEM;
  1434. knew->private_value = val;
  1435. spec->num_kctl_used++;
  1436. return 0;
  1437. }
  1438. /* flag inputs as additional dynamic lineouts */
  1439. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  1440. {
  1441. struct sigmatel_spec *spec = codec->spec;
  1442. unsigned int wcaps, wtype;
  1443. int i, num_dacs = 0;
  1444. /* use the wcaps cache to count all DACs available for line-outs */
  1445. for (i = 0; i < codec->num_nodes; i++) {
  1446. wcaps = codec->wcaps[i];
  1447. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1448. if (wtype == AC_WID_AUD_OUT && !(wcaps & AC_WCAP_DIGITAL))
  1449. num_dacs++;
  1450. }
  1451. snd_printdd("%s: total dac count=%d\n", __func__, num_dacs);
  1452. switch (cfg->line_outs) {
  1453. case 3:
  1454. /* add line-in as side */
  1455. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 3) {
  1456. cfg->line_out_pins[cfg->line_outs] =
  1457. cfg->input_pins[AUTO_PIN_LINE];
  1458. spec->line_switch = 1;
  1459. cfg->line_outs++;
  1460. }
  1461. break;
  1462. case 2:
  1463. /* add line-in as clfe and mic as side */
  1464. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 2) {
  1465. cfg->line_out_pins[cfg->line_outs] =
  1466. cfg->input_pins[AUTO_PIN_LINE];
  1467. spec->line_switch = 1;
  1468. cfg->line_outs++;
  1469. }
  1470. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 3) {
  1471. cfg->line_out_pins[cfg->line_outs] =
  1472. cfg->input_pins[AUTO_PIN_MIC];
  1473. spec->mic_switch = 1;
  1474. cfg->line_outs++;
  1475. }
  1476. break;
  1477. case 1:
  1478. /* add line-in as surr and mic as clfe */
  1479. if (cfg->input_pins[AUTO_PIN_LINE] && num_dacs > 1) {
  1480. cfg->line_out_pins[cfg->line_outs] =
  1481. cfg->input_pins[AUTO_PIN_LINE];
  1482. spec->line_switch = 1;
  1483. cfg->line_outs++;
  1484. }
  1485. if (cfg->input_pins[AUTO_PIN_MIC] && num_dacs > 2) {
  1486. cfg->line_out_pins[cfg->line_outs] =
  1487. cfg->input_pins[AUTO_PIN_MIC];
  1488. spec->mic_switch = 1;
  1489. cfg->line_outs++;
  1490. }
  1491. break;
  1492. }
  1493. return 0;
  1494. }
  1495. static int is_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1496. {
  1497. int i;
  1498. for (i = 0; i < spec->multiout.num_dacs; i++) {
  1499. if (spec->multiout.dac_nids[i] == nid)
  1500. return 1;
  1501. }
  1502. return 0;
  1503. }
  1504. /*
  1505. * Fill in the dac_nids table from the parsed pin configuration
  1506. * This function only works when every pin in line_out_pins[]
  1507. * contains atleast one DAC in its connection list. Some 92xx
  1508. * codecs are not connected directly to a DAC, such as the 9200
  1509. * and 9202/925x. For those, dac_nids[] must be hard-coded.
  1510. */
  1511. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
  1512. struct auto_pin_cfg *cfg)
  1513. {
  1514. struct sigmatel_spec *spec = codec->spec;
  1515. int i, j, conn_len = 0;
  1516. hda_nid_t nid, conn[HDA_MAX_CONNECTIONS];
  1517. unsigned int wcaps, wtype;
  1518. for (i = 0; i < cfg->line_outs; i++) {
  1519. nid = cfg->line_out_pins[i];
  1520. conn_len = snd_hda_get_connections(codec, nid, conn,
  1521. HDA_MAX_CONNECTIONS);
  1522. for (j = 0; j < conn_len; j++) {
  1523. wcaps = snd_hda_param_read(codec, conn[j],
  1524. AC_PAR_AUDIO_WIDGET_CAP);
  1525. wtype = (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
  1526. if (wtype != AC_WID_AUD_OUT ||
  1527. (wcaps & AC_WCAP_DIGITAL))
  1528. continue;
  1529. /* conn[j] is a DAC routed to this line-out */
  1530. if (!is_in_dac_nids(spec, conn[j]))
  1531. break;
  1532. }
  1533. if (j == conn_len) {
  1534. if (spec->multiout.num_dacs > 0) {
  1535. /* we have already working output pins,
  1536. * so let's drop the broken ones again
  1537. */
  1538. cfg->line_outs = spec->multiout.num_dacs;
  1539. break;
  1540. }
  1541. /* error out, no available DAC found */
  1542. snd_printk(KERN_ERR
  1543. "%s: No available DAC for pin 0x%x\n",
  1544. __func__, nid);
  1545. return -ENODEV;
  1546. }
  1547. spec->multiout.dac_nids[i] = conn[j];
  1548. spec->multiout.num_dacs++;
  1549. if (conn_len > 1) {
  1550. /* select this DAC in the pin's input mux */
  1551. snd_hda_codec_write_cache(codec, nid, 0,
  1552. AC_VERB_SET_CONNECT_SEL, j);
  1553. }
  1554. }
  1555. snd_printd("dac_nids=%d (0x%x/0x%x/0x%x/0x%x/0x%x)\n",
  1556. spec->multiout.num_dacs,
  1557. spec->multiout.dac_nids[0],
  1558. spec->multiout.dac_nids[1],
  1559. spec->multiout.dac_nids[2],
  1560. spec->multiout.dac_nids[3],
  1561. spec->multiout.dac_nids[4]);
  1562. return 0;
  1563. }
  1564. /* create volume control/switch for the given prefx type */
  1565. static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
  1566. {
  1567. char name[32];
  1568. int err;
  1569. sprintf(name, "%s Playback Volume", pfx);
  1570. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  1571. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1572. if (err < 0)
  1573. return err;
  1574. sprintf(name, "%s Playback Switch", pfx);
  1575. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  1576. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  1577. if (err < 0)
  1578. return err;
  1579. return 0;
  1580. }
  1581. /* add playback controls from the parsed DAC table */
  1582. static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
  1583. const struct auto_pin_cfg *cfg)
  1584. {
  1585. static const char *chname[4] = {
  1586. "Front", "Surround", NULL /*CLFE*/, "Side"
  1587. };
  1588. hda_nid_t nid;
  1589. int i, err;
  1590. struct sigmatel_spec *spec = codec->spec;
  1591. unsigned int wid_caps;
  1592. for (i = 0; i < cfg->line_outs; i++) {
  1593. if (!spec->multiout.dac_nids[i])
  1594. continue;
  1595. nid = spec->multiout.dac_nids[i];
  1596. if (i == 2) {
  1597. /* Center/LFE */
  1598. err = create_controls(spec, "Center", nid, 1);
  1599. if (err < 0)
  1600. return err;
  1601. err = create_controls(spec, "LFE", nid, 2);
  1602. if (err < 0)
  1603. return err;
  1604. wid_caps = get_wcaps(codec, nid);
  1605. if (wid_caps & AC_WCAP_LR_SWAP) {
  1606. err = stac92xx_add_control(spec,
  1607. STAC_CTL_WIDGET_CLFE_SWITCH,
  1608. "Swap Center/LFE Playback Switch", nid);
  1609. if (err < 0)
  1610. return err;
  1611. }
  1612. } else {
  1613. err = create_controls(spec, chname[i], nid, 3);
  1614. if (err < 0)
  1615. return err;
  1616. }
  1617. }
  1618. if (spec->line_switch)
  1619. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  1620. return err;
  1621. if (spec->mic_switch)
  1622. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  1623. return err;
  1624. return 0;
  1625. }
  1626. static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  1627. {
  1628. if (is_in_dac_nids(spec, nid))
  1629. return 1;
  1630. if (spec->multiout.hp_nid == nid)
  1631. return 1;
  1632. return 0;
  1633. }
  1634. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  1635. {
  1636. if (!spec->multiout.hp_nid)
  1637. spec->multiout.hp_nid = nid;
  1638. else if (spec->multiout.num_dacs > 4) {
  1639. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  1640. return 1;
  1641. } else {
  1642. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  1643. spec->multiout.num_dacs++;
  1644. }
  1645. return 0;
  1646. }
  1647. /* add playback controls for Speaker and HP outputs */
  1648. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  1649. struct auto_pin_cfg *cfg)
  1650. {
  1651. struct sigmatel_spec *spec = codec->spec;
  1652. hda_nid_t nid;
  1653. int i, old_num_dacs, err;
  1654. old_num_dacs = spec->multiout.num_dacs;
  1655. for (i = 0; i < cfg->hp_outs; i++) {
  1656. unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
  1657. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1658. spec->hp_detect = 1;
  1659. nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  1660. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1661. if (check_in_dac_nids(spec, nid))
  1662. nid = 0;
  1663. if (! nid)
  1664. continue;
  1665. add_spec_dacs(spec, nid);
  1666. }
  1667. for (i = 0; i < cfg->speaker_outs; i++) {
  1668. nid = snd_hda_codec_read(codec, cfg->speaker_pins[i], 0,
  1669. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1670. if (check_in_dac_nids(spec, nid))
  1671. nid = 0;
  1672. if (! nid)
  1673. continue;
  1674. add_spec_dacs(spec, nid);
  1675. }
  1676. for (i = 0; i < cfg->line_outs; i++) {
  1677. nid = snd_hda_codec_read(codec, cfg->line_out_pins[i], 0,
  1678. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1679. if (check_in_dac_nids(spec, nid))
  1680. nid = 0;
  1681. if (! nid)
  1682. continue;
  1683. add_spec_dacs(spec, nid);
  1684. }
  1685. for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
  1686. static const char *pfxs[] = {
  1687. "Speaker", "External Speaker", "Speaker2",
  1688. };
  1689. err = create_controls(spec, pfxs[i - old_num_dacs],
  1690. spec->multiout.dac_nids[i], 3);
  1691. if (err < 0)
  1692. return err;
  1693. }
  1694. if (spec->multiout.hp_nid) {
  1695. const char *pfx;
  1696. if (old_num_dacs == spec->multiout.num_dacs &&
  1697. spec->no_vol_knob)
  1698. pfx = "Master";
  1699. else
  1700. pfx = "Headphone";
  1701. err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
  1702. if (err < 0)
  1703. return err;
  1704. }
  1705. return 0;
  1706. }
  1707. /* labels for dmic mux inputs */
  1708. static const char *stac92xx_dmic_labels[5] = {
  1709. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  1710. "Digital Mic 3", "Digital Mic 4"
  1711. };
  1712. /* create playback/capture controls for input pins on dmic capable codecs */
  1713. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  1714. const struct auto_pin_cfg *cfg)
  1715. {
  1716. struct sigmatel_spec *spec = codec->spec;
  1717. struct hda_input_mux *dimux = &spec->private_dimux;
  1718. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1719. int i, j;
  1720. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  1721. dimux->items[dimux->num_items].index = 0;
  1722. dimux->num_items++;
  1723. for (i = 0; i < spec->num_dmics; i++) {
  1724. int index;
  1725. int num_cons;
  1726. unsigned int def_conf;
  1727. def_conf = snd_hda_codec_read(codec,
  1728. spec->dmic_nids[i],
  1729. 0,
  1730. AC_VERB_GET_CONFIG_DEFAULT,
  1731. 0);
  1732. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1733. continue;
  1734. num_cons = snd_hda_get_connections(codec,
  1735. spec->dmux_nid,
  1736. con_lst,
  1737. HDA_MAX_NUM_INPUTS);
  1738. for (j = 0; j < num_cons; j++)
  1739. if (con_lst[j] == spec->dmic_nids[i]) {
  1740. index = j;
  1741. goto found;
  1742. }
  1743. continue;
  1744. found:
  1745. dimux->items[dimux->num_items].label =
  1746. stac92xx_dmic_labels[dimux->num_items];
  1747. dimux->items[dimux->num_items].index = index;
  1748. dimux->num_items++;
  1749. }
  1750. return 0;
  1751. }
  1752. /* create playback/capture controls for input pins */
  1753. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  1754. {
  1755. struct sigmatel_spec *spec = codec->spec;
  1756. struct hda_input_mux *imux = &spec->private_imux;
  1757. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1758. int i, j, k;
  1759. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1760. int index;
  1761. if (!cfg->input_pins[i])
  1762. continue;
  1763. index = -1;
  1764. for (j = 0; j < spec->num_muxes; j++) {
  1765. int num_cons;
  1766. num_cons = snd_hda_get_connections(codec,
  1767. spec->mux_nids[j],
  1768. con_lst,
  1769. HDA_MAX_NUM_INPUTS);
  1770. for (k = 0; k < num_cons; k++)
  1771. if (con_lst[k] == cfg->input_pins[i]) {
  1772. index = k;
  1773. goto found;
  1774. }
  1775. }
  1776. continue;
  1777. found:
  1778. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  1779. imux->items[imux->num_items].index = index;
  1780. imux->num_items++;
  1781. }
  1782. if (imux->num_items) {
  1783. /*
  1784. * Set the current input for the muxes.
  1785. * The STAC9221 has two input muxes with identical source
  1786. * NID lists. Hopefully this won't get confused.
  1787. */
  1788. for (i = 0; i < spec->num_muxes; i++) {
  1789. snd_hda_codec_write_cache(codec, spec->mux_nids[i], 0,
  1790. AC_VERB_SET_CONNECT_SEL,
  1791. imux->items[0].index);
  1792. }
  1793. }
  1794. return 0;
  1795. }
  1796. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  1797. {
  1798. struct sigmatel_spec *spec = codec->spec;
  1799. int i;
  1800. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1801. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1802. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1803. }
  1804. }
  1805. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  1806. {
  1807. struct sigmatel_spec *spec = codec->spec;
  1808. int i;
  1809. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  1810. hda_nid_t pin;
  1811. pin = spec->autocfg.hp_pins[i];
  1812. if (pin) /* connect to front */
  1813. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  1814. }
  1815. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  1816. hda_nid_t pin;
  1817. pin = spec->autocfg.speaker_pins[i];
  1818. if (pin) /* connect to front */
  1819. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  1820. }
  1821. }
  1822. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  1823. {
  1824. struct sigmatel_spec *spec = codec->spec;
  1825. int err;
  1826. if ((err = snd_hda_parse_pin_def_config(codec,
  1827. &spec->autocfg,
  1828. spec->dmic_nids)) < 0)
  1829. return err;
  1830. if (! spec->autocfg.line_outs)
  1831. return 0; /* can't find valid pin config */
  1832. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1833. return err;
  1834. if (spec->multiout.num_dacs == 0)
  1835. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1836. return err;
  1837. err = stac92xx_auto_create_multi_out_ctls(codec, &spec->autocfg);
  1838. if (err < 0)
  1839. return err;
  1840. err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg);
  1841. if (err < 0)
  1842. return err;
  1843. err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg);
  1844. if (err < 0)
  1845. return err;
  1846. if (spec->num_dmics > 0)
  1847. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1848. &spec->autocfg)) < 0)
  1849. return err;
  1850. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1851. if (spec->multiout.max_channels > 2)
  1852. spec->surr_switch = 1;
  1853. if (spec->autocfg.dig_out_pin)
  1854. spec->multiout.dig_out_nid = dig_out;
  1855. if (spec->autocfg.dig_in_pin)
  1856. spec->dig_in_nid = dig_in;
  1857. if (spec->kctl_alloc)
  1858. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1859. spec->input_mux = &spec->private_imux;
  1860. spec->dinput_mux = &spec->private_dimux;
  1861. return 1;
  1862. }
  1863. /* add playback controls for HP output */
  1864. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1865. struct auto_pin_cfg *cfg)
  1866. {
  1867. struct sigmatel_spec *spec = codec->spec;
  1868. hda_nid_t pin = cfg->hp_pins[0];
  1869. unsigned int wid_caps;
  1870. if (! pin)
  1871. return 0;
  1872. wid_caps = get_wcaps(codec, pin);
  1873. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1874. spec->hp_detect = 1;
  1875. return 0;
  1876. }
  1877. /* add playback controls for LFE output */
  1878. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1879. struct auto_pin_cfg *cfg)
  1880. {
  1881. struct sigmatel_spec *spec = codec->spec;
  1882. int err;
  1883. hda_nid_t lfe_pin = 0x0;
  1884. int i;
  1885. /*
  1886. * search speaker outs and line outs for a mono speaker pin
  1887. * with an amp. If one is found, add LFE controls
  1888. * for it.
  1889. */
  1890. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1891. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1892. unsigned long wcaps = get_wcaps(codec, pin);
  1893. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1894. if (wcaps == AC_WCAP_OUT_AMP)
  1895. /* found a mono speaker with an amp, must be lfe */
  1896. lfe_pin = pin;
  1897. }
  1898. /* if speaker_outs is 0, then speakers may be in line_outs */
  1899. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1900. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1901. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1902. unsigned long cfg;
  1903. cfg = snd_hda_codec_read(codec, pin, 0,
  1904. AC_VERB_GET_CONFIG_DEFAULT,
  1905. 0x00);
  1906. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1907. unsigned long wcaps = get_wcaps(codec, pin);
  1908. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1909. if (wcaps == AC_WCAP_OUT_AMP)
  1910. /* found a mono speaker with an amp,
  1911. must be lfe */
  1912. lfe_pin = pin;
  1913. }
  1914. }
  1915. }
  1916. if (lfe_pin) {
  1917. err = create_controls(spec, "LFE", lfe_pin, 1);
  1918. if (err < 0)
  1919. return err;
  1920. }
  1921. return 0;
  1922. }
  1923. static int stac9200_parse_auto_config(struct hda_codec *codec)
  1924. {
  1925. struct sigmatel_spec *spec = codec->spec;
  1926. int err;
  1927. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  1928. return err;
  1929. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1930. return err;
  1931. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  1932. return err;
  1933. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  1934. return err;
  1935. if (spec->autocfg.dig_out_pin)
  1936. spec->multiout.dig_out_nid = 0x05;
  1937. if (spec->autocfg.dig_in_pin)
  1938. spec->dig_in_nid = 0x04;
  1939. if (spec->kctl_alloc)
  1940. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1941. spec->input_mux = &spec->private_imux;
  1942. spec->dinput_mux = &spec->private_dimux;
  1943. return 1;
  1944. }
  1945. /*
  1946. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  1947. * funky external mute control using GPIO pins.
  1948. */
  1949. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  1950. {
  1951. unsigned int gpiostate, gpiomask, gpiodir;
  1952. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  1953. AC_VERB_GET_GPIO_DATA, 0);
  1954. if (!muted)
  1955. gpiostate |= (1 << pin);
  1956. else
  1957. gpiostate &= ~(1 << pin);
  1958. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  1959. AC_VERB_GET_GPIO_MASK, 0);
  1960. gpiomask |= (1 << pin);
  1961. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  1962. AC_VERB_GET_GPIO_DIRECTION, 0);
  1963. gpiodir |= (1 << pin);
  1964. /* AppleHDA seems to do this -- WTF is this verb?? */
  1965. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  1966. snd_hda_codec_write(codec, codec->afg, 0,
  1967. AC_VERB_SET_GPIO_MASK, gpiomask);
  1968. snd_hda_codec_write(codec, codec->afg, 0,
  1969. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  1970. msleep(1);
  1971. snd_hda_codec_write(codec, codec->afg, 0,
  1972. AC_VERB_SET_GPIO_DATA, gpiostate);
  1973. }
  1974. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  1975. unsigned int event)
  1976. {
  1977. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  1978. snd_hda_codec_write_cache(codec, nid, 0,
  1979. AC_VERB_SET_UNSOLICITED_ENABLE,
  1980. (AC_USRSP_EN | event));
  1981. }
  1982. static int stac92xx_init(struct hda_codec *codec)
  1983. {
  1984. struct sigmatel_spec *spec = codec->spec;
  1985. struct auto_pin_cfg *cfg = &spec->autocfg;
  1986. int i;
  1987. snd_hda_sequence_write(codec, spec->init);
  1988. /* set up pins */
  1989. if (spec->hp_detect) {
  1990. /* Enable unsolicited responses on the HP widget */
  1991. for (i = 0; i < cfg->hp_outs; i++)
  1992. enable_pin_detect(codec, cfg->hp_pins[i],
  1993. STAC_HP_EVENT);
  1994. /* force to enable the first line-out; the others are set up
  1995. * in unsol_event
  1996. */
  1997. stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
  1998. AC_PINCTL_OUT_EN);
  1999. stac92xx_auto_init_hp_out(codec);
  2000. /* fake event to set up pins */
  2001. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2002. } else {
  2003. stac92xx_auto_init_multi_out(codec);
  2004. stac92xx_auto_init_hp_out(codec);
  2005. }
  2006. for (i = 0; i < AUTO_PIN_LAST; i++) {
  2007. hda_nid_t nid = cfg->input_pins[i];
  2008. if (nid) {
  2009. unsigned int pinctl = AC_PINCTL_IN_EN;
  2010. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  2011. pinctl |= stac92xx_get_vref(codec, nid);
  2012. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  2013. }
  2014. }
  2015. if (spec->num_dmics > 0)
  2016. for (i = 0; i < spec->num_dmics; i++)
  2017. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  2018. AC_PINCTL_IN_EN);
  2019. if (cfg->dig_out_pin)
  2020. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  2021. AC_PINCTL_OUT_EN);
  2022. if (cfg->dig_in_pin)
  2023. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  2024. AC_PINCTL_IN_EN);
  2025. if (spec->gpio_mute) {
  2026. stac922x_gpio_mute(codec, 0, 0);
  2027. stac922x_gpio_mute(codec, 1, 0);
  2028. }
  2029. return 0;
  2030. }
  2031. static void stac92xx_free(struct hda_codec *codec)
  2032. {
  2033. struct sigmatel_spec *spec = codec->spec;
  2034. int i;
  2035. if (! spec)
  2036. return;
  2037. if (spec->kctl_alloc) {
  2038. for (i = 0; i < spec->num_kctl_used; i++)
  2039. kfree(spec->kctl_alloc[i].name);
  2040. kfree(spec->kctl_alloc);
  2041. }
  2042. if (spec->bios_pin_configs)
  2043. kfree(spec->bios_pin_configs);
  2044. kfree(spec);
  2045. }
  2046. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2047. unsigned int flag)
  2048. {
  2049. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2050. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2051. if (pin_ctl & AC_PINCTL_IN_EN) {
  2052. /*
  2053. * we need to check the current set-up direction of
  2054. * shared input pins since they can be switched via
  2055. * "xxx as Output" mixer switch
  2056. */
  2057. struct sigmatel_spec *spec = codec->spec;
  2058. struct auto_pin_cfg *cfg = &spec->autocfg;
  2059. if ((nid == cfg->input_pins[AUTO_PIN_LINE] &&
  2060. spec->line_switch) ||
  2061. (nid == cfg->input_pins[AUTO_PIN_MIC] &&
  2062. spec->mic_switch))
  2063. return;
  2064. }
  2065. /* if setting pin direction bits, clear the current
  2066. direction bits first */
  2067. if (flag & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN))
  2068. pin_ctl &= ~(AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN);
  2069. snd_hda_codec_write_cache(codec, nid, 0,
  2070. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2071. pin_ctl | flag);
  2072. }
  2073. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  2074. unsigned int flag)
  2075. {
  2076. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  2077. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  2078. snd_hda_codec_write_cache(codec, nid, 0,
  2079. AC_VERB_SET_PIN_WIDGET_CONTROL,
  2080. pin_ctl & ~flag);
  2081. }
  2082. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  2083. {
  2084. if (!nid)
  2085. return 0;
  2086. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  2087. & (1 << 31))
  2088. return 1;
  2089. return 0;
  2090. }
  2091. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  2092. {
  2093. struct sigmatel_spec *spec = codec->spec;
  2094. struct auto_pin_cfg *cfg = &spec->autocfg;
  2095. int i, presence;
  2096. presence = 0;
  2097. for (i = 0; i < cfg->hp_outs; i++) {
  2098. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  2099. if (presence)
  2100. break;
  2101. }
  2102. if (presence) {
  2103. /* disable lineouts, enable hp */
  2104. for (i = 0; i < cfg->line_outs; i++)
  2105. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  2106. AC_PINCTL_OUT_EN);
  2107. for (i = 0; i < cfg->speaker_outs; i++)
  2108. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  2109. AC_PINCTL_OUT_EN);
  2110. } else {
  2111. /* enable lineouts, disable hp */
  2112. for (i = 0; i < cfg->line_outs; i++)
  2113. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  2114. AC_PINCTL_OUT_EN);
  2115. for (i = 0; i < cfg->speaker_outs; i++)
  2116. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  2117. AC_PINCTL_OUT_EN);
  2118. }
  2119. }
  2120. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  2121. {
  2122. switch (res >> 26) {
  2123. case STAC_HP_EVENT:
  2124. stac92xx_hp_detect(codec, res);
  2125. break;
  2126. }
  2127. }
  2128. #ifdef SND_HDA_NEEDS_RESUME
  2129. static int stac92xx_resume(struct hda_codec *codec)
  2130. {
  2131. struct sigmatel_spec *spec = codec->spec;
  2132. stac92xx_set_config_regs(codec);
  2133. snd_hda_sequence_write(codec, spec->init);
  2134. if (spec->gpio_mute) {
  2135. stac922x_gpio_mute(codec, 0, 0);
  2136. stac922x_gpio_mute(codec, 1, 0);
  2137. }
  2138. snd_hda_codec_resume_amp(codec);
  2139. snd_hda_codec_resume_cache(codec);
  2140. /* invoke unsolicited event to reset the HP state */
  2141. if (spec->hp_detect)
  2142. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2143. return 0;
  2144. }
  2145. #endif
  2146. static struct hda_codec_ops stac92xx_patch_ops = {
  2147. .build_controls = stac92xx_build_controls,
  2148. .build_pcms = stac92xx_build_pcms,
  2149. .init = stac92xx_init,
  2150. .free = stac92xx_free,
  2151. .unsol_event = stac92xx_unsol_event,
  2152. #ifdef SND_HDA_NEEDS_RESUME
  2153. .resume = stac92xx_resume,
  2154. #endif
  2155. };
  2156. static int patch_stac9200(struct hda_codec *codec)
  2157. {
  2158. struct sigmatel_spec *spec;
  2159. int err;
  2160. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2161. if (spec == NULL)
  2162. return -ENOMEM;
  2163. codec->spec = spec;
  2164. spec->num_pins = ARRAY_SIZE(stac9200_pin_nids);
  2165. spec->pin_nids = stac9200_pin_nids;
  2166. spec->no_vol_knob = 1;
  2167. spec->board_config = snd_hda_check_board_config(codec, STAC_9200_MODELS,
  2168. stac9200_models,
  2169. stac9200_cfg_tbl);
  2170. if (spec->board_config < 0) {
  2171. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  2172. err = stac92xx_save_bios_config_regs(codec);
  2173. if (err < 0) {
  2174. stac92xx_free(codec);
  2175. return err;
  2176. }
  2177. spec->pin_configs = spec->bios_pin_configs;
  2178. } else {
  2179. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  2180. stac92xx_set_config_regs(codec);
  2181. }
  2182. spec->multiout.max_channels = 2;
  2183. spec->multiout.num_dacs = 1;
  2184. spec->multiout.dac_nids = stac9200_dac_nids;
  2185. spec->adc_nids = stac9200_adc_nids;
  2186. spec->mux_nids = stac9200_mux_nids;
  2187. spec->num_muxes = 1;
  2188. spec->num_dmics = 0;
  2189. spec->num_adcs = 1;
  2190. if (spec->board_config == STAC_9200_GATEWAY)
  2191. spec->init = stac9200_eapd_init;
  2192. else
  2193. spec->init = stac9200_core_init;
  2194. spec->mixer = stac9200_mixer;
  2195. err = stac9200_parse_auto_config(codec);
  2196. if (err < 0) {
  2197. stac92xx_free(codec);
  2198. return err;
  2199. }
  2200. codec->patch_ops = stac92xx_patch_ops;
  2201. return 0;
  2202. }
  2203. static int patch_stac925x(struct hda_codec *codec)
  2204. {
  2205. struct sigmatel_spec *spec;
  2206. int err;
  2207. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2208. if (spec == NULL)
  2209. return -ENOMEM;
  2210. codec->spec = spec;
  2211. spec->num_pins = ARRAY_SIZE(stac925x_pin_nids);
  2212. spec->pin_nids = stac925x_pin_nids;
  2213. spec->no_vol_knob = 1;
  2214. spec->board_config = snd_hda_check_board_config(codec, STAC_925x_MODELS,
  2215. stac925x_models,
  2216. stac925x_cfg_tbl);
  2217. again:
  2218. if (spec->board_config < 0) {
  2219. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC925x,"
  2220. "using BIOS defaults\n");
  2221. err = stac92xx_save_bios_config_regs(codec);
  2222. if (err < 0) {
  2223. stac92xx_free(codec);
  2224. return err;
  2225. }
  2226. spec->pin_configs = spec->bios_pin_configs;
  2227. } else if (stac925x_brd_tbl[spec->board_config] != NULL){
  2228. spec->pin_configs = stac925x_brd_tbl[spec->board_config];
  2229. stac92xx_set_config_regs(codec);
  2230. }
  2231. spec->multiout.max_channels = 2;
  2232. spec->multiout.num_dacs = 1;
  2233. spec->multiout.dac_nids = stac925x_dac_nids;
  2234. spec->adc_nids = stac925x_adc_nids;
  2235. spec->mux_nids = stac925x_mux_nids;
  2236. spec->num_muxes = 1;
  2237. spec->num_adcs = 1;
  2238. switch (codec->vendor_id) {
  2239. case 0x83847632: /* STAC9202 */
  2240. case 0x83847633: /* STAC9202D */
  2241. case 0x83847636: /* STAC9251 */
  2242. case 0x83847637: /* STAC9251D */
  2243. spec->num_dmics = STAC925X_NUM_DMICS;
  2244. spec->dmic_nids = stac925x_dmic_nids;
  2245. break;
  2246. default:
  2247. spec->num_dmics = 0;
  2248. break;
  2249. }
  2250. spec->init = stac925x_core_init;
  2251. spec->mixer = stac925x_mixer;
  2252. err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
  2253. if (!err) {
  2254. if (spec->board_config < 0) {
  2255. printk(KERN_WARNING "hda_codec: No auto-config is "
  2256. "available, default to model=ref\n");
  2257. spec->board_config = STAC_925x_REF;
  2258. goto again;
  2259. }
  2260. err = -EINVAL;
  2261. }
  2262. if (err < 0) {
  2263. stac92xx_free(codec);
  2264. return err;
  2265. }
  2266. codec->patch_ops = stac92xx_patch_ops;
  2267. return 0;
  2268. }
  2269. static int patch_stac922x(struct hda_codec *codec)
  2270. {
  2271. struct sigmatel_spec *spec;
  2272. int err;
  2273. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2274. if (spec == NULL)
  2275. return -ENOMEM;
  2276. codec->spec = spec;
  2277. spec->num_pins = ARRAY_SIZE(stac922x_pin_nids);
  2278. spec->pin_nids = stac922x_pin_nids;
  2279. spec->board_config = snd_hda_check_board_config(codec, STAC_922X_MODELS,
  2280. stac922x_models,
  2281. stac922x_cfg_tbl);
  2282. if (spec->board_config == STAC_INTEL_MAC_V3) {
  2283. spec->gpio_mute = 1;
  2284. /* Intel Macs have all same PCI SSID, so we need to check
  2285. * codec SSID to distinguish the exact models
  2286. */
  2287. printk(KERN_INFO "hda_codec: STAC922x, Apple subsys_id=%x\n", codec->subsystem_id);
  2288. switch (codec->subsystem_id) {
  2289. case 0x106b0800:
  2290. spec->board_config = STAC_INTEL_MAC_V1;
  2291. break;
  2292. case 0x106b0600:
  2293. case 0x106b0700:
  2294. spec->board_config = STAC_INTEL_MAC_V2;
  2295. break;
  2296. case 0x106b0e00:
  2297. case 0x106b0f00:
  2298. case 0x106b1600:
  2299. case 0x106b1700:
  2300. case 0x106b0200:
  2301. case 0x106b1e00:
  2302. spec->board_config = STAC_INTEL_MAC_V3;
  2303. break;
  2304. case 0x106b1a00:
  2305. case 0x00000100:
  2306. spec->board_config = STAC_INTEL_MAC_V4;
  2307. break;
  2308. case 0x106b0a00:
  2309. case 0x106b2200:
  2310. spec->board_config = STAC_INTEL_MAC_V5;
  2311. break;
  2312. }
  2313. }
  2314. again:
  2315. if (spec->board_config < 0) {
  2316. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  2317. "using BIOS defaults\n");
  2318. err = stac92xx_save_bios_config_regs(codec);
  2319. if (err < 0) {
  2320. stac92xx_free(codec);
  2321. return err;
  2322. }
  2323. spec->pin_configs = spec->bios_pin_configs;
  2324. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  2325. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  2326. stac92xx_set_config_regs(codec);
  2327. }
  2328. spec->adc_nids = stac922x_adc_nids;
  2329. spec->mux_nids = stac922x_mux_nids;
  2330. spec->num_muxes = ARRAY_SIZE(stac922x_mux_nids);
  2331. spec->num_adcs = ARRAY_SIZE(stac922x_adc_nids);
  2332. spec->num_dmics = 0;
  2333. spec->init = stac922x_core_init;
  2334. spec->mixer = stac922x_mixer;
  2335. spec->multiout.dac_nids = spec->dac_nids;
  2336. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  2337. if (!err) {
  2338. if (spec->board_config < 0) {
  2339. printk(KERN_WARNING "hda_codec: No auto-config is "
  2340. "available, default to model=ref\n");
  2341. spec->board_config = STAC_D945_REF;
  2342. goto again;
  2343. }
  2344. err = -EINVAL;
  2345. }
  2346. if (err < 0) {
  2347. stac92xx_free(codec);
  2348. return err;
  2349. }
  2350. codec->patch_ops = stac92xx_patch_ops;
  2351. /* Fix Mux capture level; max to 2 */
  2352. snd_hda_override_amp_caps(codec, 0x12, HDA_OUTPUT,
  2353. (0 << AC_AMPCAP_OFFSET_SHIFT) |
  2354. (2 << AC_AMPCAP_NUM_STEPS_SHIFT) |
  2355. (0x27 << AC_AMPCAP_STEP_SIZE_SHIFT) |
  2356. (0 << AC_AMPCAP_MUTE_SHIFT));
  2357. return 0;
  2358. }
  2359. static int patch_stac927x(struct hda_codec *codec)
  2360. {
  2361. struct sigmatel_spec *spec;
  2362. int err;
  2363. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2364. if (spec == NULL)
  2365. return -ENOMEM;
  2366. codec->spec = spec;
  2367. spec->num_pins = ARRAY_SIZE(stac927x_pin_nids);
  2368. spec->pin_nids = stac927x_pin_nids;
  2369. spec->board_config = snd_hda_check_board_config(codec, STAC_927X_MODELS,
  2370. stac927x_models,
  2371. stac927x_cfg_tbl);
  2372. again:
  2373. if (spec->board_config < 0) {
  2374. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  2375. err = stac92xx_save_bios_config_regs(codec);
  2376. if (err < 0) {
  2377. stac92xx_free(codec);
  2378. return err;
  2379. }
  2380. spec->pin_configs = spec->bios_pin_configs;
  2381. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  2382. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  2383. stac92xx_set_config_regs(codec);
  2384. }
  2385. switch (spec->board_config) {
  2386. case STAC_D965_3ST:
  2387. spec->adc_nids = stac927x_adc_nids;
  2388. spec->mux_nids = stac927x_mux_nids;
  2389. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2390. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2391. spec->num_dmics = 0;
  2392. spec->init = d965_core_init;
  2393. spec->mixer = stac927x_mixer;
  2394. break;
  2395. case STAC_D965_5ST:
  2396. spec->adc_nids = stac927x_adc_nids;
  2397. spec->mux_nids = stac927x_mux_nids;
  2398. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2399. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2400. spec->num_dmics = 0;
  2401. spec->init = d965_core_init;
  2402. spec->mixer = stac927x_mixer;
  2403. break;
  2404. default:
  2405. spec->adc_nids = stac927x_adc_nids;
  2406. spec->mux_nids = stac927x_mux_nids;
  2407. spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
  2408. spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
  2409. spec->num_dmics = 0;
  2410. spec->init = stac927x_core_init;
  2411. spec->mixer = stac927x_mixer;
  2412. }
  2413. spec->multiout.dac_nids = spec->dac_nids;
  2414. /* GPIO0 High = Enable EAPD */
  2415. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2416. stac92xx_enable_gpio_mask(codec);
  2417. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  2418. if (!err) {
  2419. if (spec->board_config < 0) {
  2420. printk(KERN_WARNING "hda_codec: No auto-config is "
  2421. "available, default to model=ref\n");
  2422. spec->board_config = STAC_D965_REF;
  2423. goto again;
  2424. }
  2425. err = -EINVAL;
  2426. }
  2427. if (err < 0) {
  2428. stac92xx_free(codec);
  2429. return err;
  2430. }
  2431. codec->patch_ops = stac92xx_patch_ops;
  2432. return 0;
  2433. }
  2434. static int patch_stac9205(struct hda_codec *codec)
  2435. {
  2436. struct sigmatel_spec *spec;
  2437. int err;
  2438. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2439. if (spec == NULL)
  2440. return -ENOMEM;
  2441. codec->spec = spec;
  2442. spec->num_pins = ARRAY_SIZE(stac9205_pin_nids);
  2443. spec->pin_nids = stac9205_pin_nids;
  2444. spec->board_config = snd_hda_check_board_config(codec, STAC_9205_MODELS,
  2445. stac9205_models,
  2446. stac9205_cfg_tbl);
  2447. again:
  2448. if (spec->board_config < 0) {
  2449. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  2450. err = stac92xx_save_bios_config_regs(codec);
  2451. if (err < 0) {
  2452. stac92xx_free(codec);
  2453. return err;
  2454. }
  2455. spec->pin_configs = spec->bios_pin_configs;
  2456. } else {
  2457. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  2458. stac92xx_set_config_regs(codec);
  2459. }
  2460. spec->adc_nids = stac9205_adc_nids;
  2461. spec->num_adcs = ARRAY_SIZE(stac9205_adc_nids);
  2462. spec->mux_nids = stac9205_mux_nids;
  2463. spec->num_muxes = ARRAY_SIZE(stac9205_mux_nids);
  2464. spec->dmic_nids = stac9205_dmic_nids;
  2465. spec->num_dmics = STAC9205_NUM_DMICS;
  2466. spec->dmux_nid = 0x1d;
  2467. spec->init = stac9205_core_init;
  2468. spec->mixer = stac9205_mixer;
  2469. spec->multiout.dac_nids = spec->dac_nids;
  2470. switch (spec->board_config){
  2471. case STAC_9205_DELL_M43:
  2472. /* Enable SPDIF in/out */
  2473. stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
  2474. stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
  2475. spec->gpio_mask = 0x00000007; /* GPIO0-2 */
  2476. /* GPIO0 High = EAPD, GPIO1 Low = DRM,
  2477. * GPIO2 High = Headphone Mute
  2478. */
  2479. spec->gpio_data = 0x00000005;
  2480. break;
  2481. default:
  2482. /* GPIO0 High = EAPD */
  2483. spec->gpio_mask = spec->gpio_data = 0x00000001;
  2484. break;
  2485. }
  2486. stac92xx_enable_gpio_mask(codec);
  2487. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  2488. if (!err) {
  2489. if (spec->board_config < 0) {
  2490. printk(KERN_WARNING "hda_codec: No auto-config is "
  2491. "available, default to model=ref\n");
  2492. spec->board_config = STAC_9205_REF;
  2493. goto again;
  2494. }
  2495. err = -EINVAL;
  2496. }
  2497. if (err < 0) {
  2498. stac92xx_free(codec);
  2499. return err;
  2500. }
  2501. codec->patch_ops = stac92xx_patch_ops;
  2502. return 0;
  2503. }
  2504. /*
  2505. * STAC9872 hack
  2506. */
  2507. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  2508. static hda_nid_t vaio_dacs[] = { 0x2 };
  2509. #define VAIO_HP_DAC 0x5
  2510. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  2511. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  2512. static struct hda_input_mux vaio_mux = {
  2513. .num_items = 3,
  2514. .items = {
  2515. /* { "HP", 0x0 }, */
  2516. { "Mic Jack", 0x1 },
  2517. { "Internal Mic", 0x2 },
  2518. { "PCM", 0x3 },
  2519. }
  2520. };
  2521. static struct hda_verb vaio_init[] = {
  2522. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2523. {0x0a, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | STAC_HP_EVENT},
  2524. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2525. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2526. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2527. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2528. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2529. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2530. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2531. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2532. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2533. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2534. {}
  2535. };
  2536. static struct hda_verb vaio_ar_init[] = {
  2537. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  2538. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  2539. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  2540. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  2541. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  2542. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  2543. {0x15, AC_VERB_SET_CONNECT_SEL, 0x1}, /* mic-sel: 0a,0d,14,02 */
  2544. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  2545. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  2546. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  2547. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  2548. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  2549. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  2550. {}
  2551. };
  2552. /* bind volumes of both NID 0x02 and 0x05 */
  2553. static struct hda_bind_ctls vaio_bind_master_vol = {
  2554. .ops = &snd_hda_bind_vol,
  2555. .values = {
  2556. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2557. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2558. 0
  2559. },
  2560. };
  2561. /* bind volumes of both NID 0x02 and 0x05 */
  2562. static struct hda_bind_ctls vaio_bind_master_sw = {
  2563. .ops = &snd_hda_bind_sw,
  2564. .values = {
  2565. HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  2566. HDA_COMPOSE_AMP_VAL(0x05, 3, 0, HDA_OUTPUT),
  2567. 0,
  2568. },
  2569. };
  2570. static struct snd_kcontrol_new vaio_mixer[] = {
  2571. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2572. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2573. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2574. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2575. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2576. {
  2577. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2578. .name = "Capture Source",
  2579. .count = 1,
  2580. .info = stac92xx_mux_enum_info,
  2581. .get = stac92xx_mux_enum_get,
  2582. .put = stac92xx_mux_enum_put,
  2583. },
  2584. {}
  2585. };
  2586. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  2587. HDA_BIND_VOL("Master Playback Volume", &vaio_bind_master_vol),
  2588. HDA_BIND_SW("Master Playback Switch", &vaio_bind_master_sw),
  2589. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  2590. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  2591. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  2592. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  2593. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  2594. {
  2595. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  2596. .name = "Capture Source",
  2597. .count = 1,
  2598. .info = stac92xx_mux_enum_info,
  2599. .get = stac92xx_mux_enum_get,
  2600. .put = stac92xx_mux_enum_put,
  2601. },
  2602. {}
  2603. };
  2604. static struct hda_codec_ops stac9872_patch_ops = {
  2605. .build_controls = stac92xx_build_controls,
  2606. .build_pcms = stac92xx_build_pcms,
  2607. .init = stac92xx_init,
  2608. .free = stac92xx_free,
  2609. #ifdef SND_HDA_NEEDS_RESUME
  2610. .resume = stac92xx_resume,
  2611. #endif
  2612. };
  2613. static int stac9872_vaio_init(struct hda_codec *codec)
  2614. {
  2615. int err;
  2616. err = stac92xx_init(codec);
  2617. if (err < 0)
  2618. return err;
  2619. if (codec->patch_ops.unsol_event)
  2620. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  2621. return 0;
  2622. }
  2623. static void stac9872_vaio_hp_detect(struct hda_codec *codec, unsigned int res)
  2624. {
  2625. if (get_pin_presence(codec, 0x0a)) {
  2626. stac92xx_reset_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2627. stac92xx_set_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2628. } else {
  2629. stac92xx_reset_pinctl(codec, 0x0a, AC_PINCTL_OUT_EN);
  2630. stac92xx_set_pinctl(codec, 0x0f, AC_PINCTL_OUT_EN);
  2631. }
  2632. }
  2633. static void stac9872_vaio_unsol_event(struct hda_codec *codec, unsigned int res)
  2634. {
  2635. switch (res >> 26) {
  2636. case STAC_HP_EVENT:
  2637. stac9872_vaio_hp_detect(codec, res);
  2638. break;
  2639. }
  2640. }
  2641. static struct hda_codec_ops stac9872_vaio_patch_ops = {
  2642. .build_controls = stac92xx_build_controls,
  2643. .build_pcms = stac92xx_build_pcms,
  2644. .init = stac9872_vaio_init,
  2645. .free = stac92xx_free,
  2646. .unsol_event = stac9872_vaio_unsol_event,
  2647. #ifdef CONFIG_PM
  2648. .resume = stac92xx_resume,
  2649. #endif
  2650. };
  2651. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  2652. CXD9872RD_VAIO,
  2653. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  2654. STAC9872AK_VAIO,
  2655. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  2656. STAC9872K_VAIO,
  2657. /* AR Series. id=0x83847664 and subsys=104D1300 */
  2658. CXD9872AKD_VAIO,
  2659. STAC_9872_MODELS,
  2660. };
  2661. static const char *stac9872_models[STAC_9872_MODELS] = {
  2662. [CXD9872RD_VAIO] = "vaio",
  2663. [CXD9872AKD_VAIO] = "vaio-ar",
  2664. };
  2665. static struct snd_pci_quirk stac9872_cfg_tbl[] = {
  2666. SND_PCI_QUIRK(0x104d, 0x81e6, "Sony VAIO F/S", CXD9872RD_VAIO),
  2667. SND_PCI_QUIRK(0x104d, 0x81ef, "Sony VAIO F/S", CXD9872RD_VAIO),
  2668. SND_PCI_QUIRK(0x104d, 0x81fd, "Sony VAIO AR", CXD9872AKD_VAIO),
  2669. SND_PCI_QUIRK(0x104d, 0x8205, "Sony VAIO AR", CXD9872AKD_VAIO),
  2670. {}
  2671. };
  2672. static int patch_stac9872(struct hda_codec *codec)
  2673. {
  2674. struct sigmatel_spec *spec;
  2675. int board_config;
  2676. board_config = snd_hda_check_board_config(codec, STAC_9872_MODELS,
  2677. stac9872_models,
  2678. stac9872_cfg_tbl);
  2679. if (board_config < 0)
  2680. /* unknown config, let generic-parser do its job... */
  2681. return snd_hda_parse_generic_codec(codec);
  2682. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2683. if (spec == NULL)
  2684. return -ENOMEM;
  2685. codec->spec = spec;
  2686. switch (board_config) {
  2687. case CXD9872RD_VAIO:
  2688. case STAC9872AK_VAIO:
  2689. case STAC9872K_VAIO:
  2690. spec->mixer = vaio_mixer;
  2691. spec->init = vaio_init;
  2692. spec->multiout.max_channels = 2;
  2693. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2694. spec->multiout.dac_nids = vaio_dacs;
  2695. spec->multiout.hp_nid = VAIO_HP_DAC;
  2696. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2697. spec->adc_nids = vaio_adcs;
  2698. spec->input_mux = &vaio_mux;
  2699. spec->mux_nids = vaio_mux_nids;
  2700. codec->patch_ops = stac9872_vaio_patch_ops;
  2701. break;
  2702. case CXD9872AKD_VAIO:
  2703. spec->mixer = vaio_ar_mixer;
  2704. spec->init = vaio_ar_init;
  2705. spec->multiout.max_channels = 2;
  2706. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  2707. spec->multiout.dac_nids = vaio_dacs;
  2708. spec->multiout.hp_nid = VAIO_HP_DAC;
  2709. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  2710. spec->adc_nids = vaio_adcs;
  2711. spec->input_mux = &vaio_mux;
  2712. spec->mux_nids = vaio_mux_nids;
  2713. codec->patch_ops = stac9872_patch_ops;
  2714. break;
  2715. }
  2716. return 0;
  2717. }
  2718. /*
  2719. * patch entries
  2720. */
  2721. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  2722. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  2723. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  2724. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  2725. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  2726. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  2727. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  2728. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  2729. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  2730. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  2731. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  2732. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  2733. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  2734. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  2735. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  2736. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  2737. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  2738. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  2739. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  2740. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  2741. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  2742. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  2743. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  2744. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  2745. { .id = 0x83847632, .name = "STAC9202", .patch = patch_stac925x },
  2746. { .id = 0x83847633, .name = "STAC9202D", .patch = patch_stac925x },
  2747. { .id = 0x83847634, .name = "STAC9250", .patch = patch_stac925x },
  2748. { .id = 0x83847635, .name = "STAC9250D", .patch = patch_stac925x },
  2749. { .id = 0x83847636, .name = "STAC9251", .patch = patch_stac925x },
  2750. { .id = 0x83847637, .name = "STAC9250D", .patch = patch_stac925x },
  2751. /* The following does not take into account .id=0x83847661 when subsys =
  2752. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  2753. * currently not fully supported.
  2754. */
  2755. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  2756. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  2757. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  2758. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  2759. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  2760. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  2761. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  2762. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  2763. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  2764. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  2765. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  2766. {} /* terminator */
  2767. };