patch_sigmatel.c 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194
  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. #define STAC_REF 0
  38. #define STAC_D945GTP3 1
  39. #define STAC_D945GTP5 2
  40. #define STAC_MACMINI 3
  41. #define STAC_922X_MODELS 4 /* number of 922x models */
  42. #define STAC_D965_3ST 4
  43. #define STAC_D965_5ST 5
  44. #define STAC_927X_MODELS 6 /* number of 927x models */
  45. struct sigmatel_spec {
  46. struct snd_kcontrol_new *mixers[4];
  47. unsigned int num_mixers;
  48. int board_config;
  49. unsigned int surr_switch: 1;
  50. unsigned int line_switch: 1;
  51. unsigned int mic_switch: 1;
  52. unsigned int alt_switch: 1;
  53. unsigned int hp_detect: 1;
  54. unsigned int gpio_mute: 1;
  55. /* playback */
  56. struct hda_multi_out multiout;
  57. hda_nid_t dac_nids[5];
  58. /* capture */
  59. hda_nid_t *adc_nids;
  60. unsigned int num_adcs;
  61. hda_nid_t *mux_nids;
  62. unsigned int num_muxes;
  63. hda_nid_t *dmic_nids;
  64. unsigned int num_dmics;
  65. hda_nid_t dmux_nid;
  66. hda_nid_t dig_in_nid;
  67. /* pin widgets */
  68. hda_nid_t *pin_nids;
  69. unsigned int num_pins;
  70. unsigned int *pin_configs;
  71. unsigned int *bios_pin_configs;
  72. /* codec specific stuff */
  73. struct hda_verb *init;
  74. struct snd_kcontrol_new *mixer;
  75. /* capture source */
  76. struct hda_input_mux *dinput_mux;
  77. unsigned int cur_dmux;
  78. struct hda_input_mux *input_mux;
  79. unsigned int cur_mux[3];
  80. /* i/o switches */
  81. unsigned int io_switch[2];
  82. struct hda_pcm pcm_rec[2]; /* PCM information */
  83. /* dynamic controls and input_mux */
  84. struct auto_pin_cfg autocfg;
  85. unsigned int num_kctl_alloc, num_kctl_used;
  86. struct snd_kcontrol_new *kctl_alloc;
  87. struct hda_input_mux private_dimux;
  88. struct hda_input_mux private_imux;
  89. };
  90. static hda_nid_t stac9200_adc_nids[1] = {
  91. 0x03,
  92. };
  93. static hda_nid_t stac9200_mux_nids[1] = {
  94. 0x0c,
  95. };
  96. static hda_nid_t stac9200_dac_nids[1] = {
  97. 0x02,
  98. };
  99. static hda_nid_t stac922x_adc_nids[2] = {
  100. 0x06, 0x07,
  101. };
  102. static hda_nid_t stac922x_mux_nids[2] = {
  103. 0x12, 0x13,
  104. };
  105. static hda_nid_t stac927x_adc_nids[3] = {
  106. 0x07, 0x08, 0x09
  107. };
  108. static hda_nid_t stac927x_mux_nids[3] = {
  109. 0x15, 0x16, 0x17
  110. };
  111. static hda_nid_t stac9205_adc_nids[2] = {
  112. 0x12, 0x13
  113. };
  114. static hda_nid_t stac9205_mux_nids[2] = {
  115. 0x19, 0x1a
  116. };
  117. static hda_nid_t stac9205_dmic_nids[3] = {
  118. 0x17, 0x18, 0
  119. };
  120. static hda_nid_t stac9200_pin_nids[8] = {
  121. 0x08, 0x09, 0x0d, 0x0e,
  122. 0x0f, 0x10, 0x11, 0x12,
  123. };
  124. static hda_nid_t stac922x_pin_nids[10] = {
  125. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  126. 0x0f, 0x10, 0x11, 0x15, 0x1b,
  127. };
  128. static hda_nid_t stac927x_pin_nids[14] = {
  129. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  130. 0x0f, 0x10, 0x11, 0x12, 0x13,
  131. 0x14, 0x21, 0x22, 0x23,
  132. };
  133. static hda_nid_t stac9205_pin_nids[12] = {
  134. 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
  135. 0x0f, 0x14, 0x16, 0x17, 0x18,
  136. 0x21, 0x22,
  137. };
  138. static int stac92xx_dmux_enum_info(struct snd_kcontrol *kcontrol,
  139. struct snd_ctl_elem_info *uinfo)
  140. {
  141. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  142. struct sigmatel_spec *spec = codec->spec;
  143. return snd_hda_input_mux_info(spec->dinput_mux, uinfo);
  144. }
  145. static int stac92xx_dmux_enum_get(struct snd_kcontrol *kcontrol,
  146. struct snd_ctl_elem_value *ucontrol)
  147. {
  148. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  149. struct sigmatel_spec *spec = codec->spec;
  150. ucontrol->value.enumerated.item[0] = spec->cur_dmux;
  151. return 0;
  152. }
  153. static int stac92xx_dmux_enum_put(struct snd_kcontrol *kcontrol,
  154. struct snd_ctl_elem_value *ucontrol)
  155. {
  156. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  157. struct sigmatel_spec *spec = codec->spec;
  158. return snd_hda_input_mux_put(codec, spec->dinput_mux, ucontrol,
  159. spec->dmux_nid, &spec->cur_dmux);
  160. }
  161. static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  162. {
  163. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  164. struct sigmatel_spec *spec = codec->spec;
  165. return snd_hda_input_mux_info(spec->input_mux, uinfo);
  166. }
  167. static int stac92xx_mux_enum_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  168. {
  169. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  170. struct sigmatel_spec *spec = codec->spec;
  171. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  172. ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
  173. return 0;
  174. }
  175. static int stac92xx_mux_enum_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  176. {
  177. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  178. struct sigmatel_spec *spec = codec->spec;
  179. unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  180. return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
  181. spec->mux_nids[adc_idx], &spec->cur_mux[adc_idx]);
  182. }
  183. static struct hda_verb stac9200_core_init[] = {
  184. /* set dac0mux for dac converter */
  185. { 0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
  186. {}
  187. };
  188. static struct hda_verb stac922x_core_init[] = {
  189. /* set master volume and direct control */
  190. { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  191. {}
  192. };
  193. static struct hda_verb d965_core_init[] = {
  194. /* set master volume and direct control */
  195. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  196. /* unmute node 0x1b */
  197. { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
  198. /* select node 0x03 as DAC */
  199. { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
  200. {}
  201. };
  202. static struct hda_verb stac927x_core_init[] = {
  203. /* set master volume and direct control */
  204. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  205. {}
  206. };
  207. static struct hda_verb stac9205_core_init[] = {
  208. /* set master volume and direct control */
  209. { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
  210. {}
  211. };
  212. static struct snd_kcontrol_new stac9200_mixer[] = {
  213. HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
  214. HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
  215. {
  216. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  217. .name = "Input Source",
  218. .count = 1,
  219. .info = stac92xx_mux_enum_info,
  220. .get = stac92xx_mux_enum_get,
  221. .put = stac92xx_mux_enum_put,
  222. },
  223. HDA_CODEC_VOLUME("Capture Volume", 0x0a, 0, HDA_OUTPUT),
  224. HDA_CODEC_MUTE("Capture Switch", 0x0a, 0, HDA_OUTPUT),
  225. HDA_CODEC_VOLUME("Capture Mux Volume", 0x0c, 0, HDA_OUTPUT),
  226. { } /* end */
  227. };
  228. /* This needs to be generated dynamically based on sequence */
  229. static struct snd_kcontrol_new stac922x_mixer[] = {
  230. {
  231. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  232. .name = "Input Source",
  233. .count = 1,
  234. .info = stac92xx_mux_enum_info,
  235. .get = stac92xx_mux_enum_get,
  236. .put = stac92xx_mux_enum_put,
  237. },
  238. HDA_CODEC_VOLUME("Capture Volume", 0x17, 0x0, HDA_INPUT),
  239. HDA_CODEC_MUTE("Capture Switch", 0x17, 0x0, HDA_INPUT),
  240. HDA_CODEC_VOLUME("Mux Capture Volume", 0x12, 0x0, HDA_OUTPUT),
  241. { } /* end */
  242. };
  243. /* This needs to be generated dynamically based on sequence */
  244. static struct snd_kcontrol_new stac9227_mixer[] = {
  245. {
  246. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  247. .name = "Input Source",
  248. .count = 1,
  249. .info = stac92xx_mux_enum_info,
  250. .get = stac92xx_mux_enum_get,
  251. .put = stac92xx_mux_enum_put,
  252. },
  253. HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  254. HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  255. { } /* end */
  256. };
  257. static snd_kcontrol_new_t stac927x_mixer[] = {
  258. {
  259. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  260. .name = "Input Source",
  261. .count = 1,
  262. .info = stac92xx_mux_enum_info,
  263. .get = stac92xx_mux_enum_get,
  264. .put = stac92xx_mux_enum_put,
  265. },
  266. HDA_CODEC_VOLUME("InMux Capture Volume", 0x15, 0x0, HDA_OUTPUT),
  267. HDA_CODEC_VOLUME("InVol Capture Volume", 0x18, 0x0, HDA_INPUT),
  268. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
  269. { } /* end */
  270. };
  271. static snd_kcontrol_new_t stac9205_mixer[] = {
  272. {
  273. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  274. .name = "Digital Input Source",
  275. .count = 1,
  276. .info = stac92xx_dmux_enum_info,
  277. .get = stac92xx_dmux_enum_get,
  278. .put = stac92xx_dmux_enum_put,
  279. },
  280. {
  281. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  282. .name = "Input Source",
  283. .count = 1,
  284. .info = stac92xx_mux_enum_info,
  285. .get = stac92xx_mux_enum_get,
  286. .put = stac92xx_mux_enum_put,
  287. },
  288. HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
  289. HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
  290. HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
  291. { } /* end */
  292. };
  293. static int stac92xx_build_controls(struct hda_codec *codec)
  294. {
  295. struct sigmatel_spec *spec = codec->spec;
  296. int err;
  297. int i;
  298. err = snd_hda_add_new_ctls(codec, spec->mixer);
  299. if (err < 0)
  300. return err;
  301. for (i = 0; i < spec->num_mixers; i++) {
  302. err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
  303. if (err < 0)
  304. return err;
  305. }
  306. if (spec->multiout.dig_out_nid) {
  307. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  308. if (err < 0)
  309. return err;
  310. }
  311. if (spec->dig_in_nid) {
  312. err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
  313. if (err < 0)
  314. return err;
  315. }
  316. return 0;
  317. }
  318. static unsigned int ref9200_pin_configs[8] = {
  319. 0x01c47010, 0x01447010, 0x0221401f, 0x01114010,
  320. 0x02a19020, 0x01a19021, 0x90100140, 0x01813122,
  321. };
  322. static unsigned int *stac9200_brd_tbl[] = {
  323. ref9200_pin_configs,
  324. };
  325. static struct hda_board_config stac9200_cfg_tbl[] = {
  326. { .modelname = "ref",
  327. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  328. .pci_subdevice = 0x2668, /* DFI LanParty */
  329. .config = STAC_REF },
  330. /* Dell laptops have BIOS problem */
  331. { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01b5,
  332. .config = STAC_REF }, /* Dell Inspiron 630m */
  333. { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01c2,
  334. .config = STAC_REF }, /* Dell Latitude D620 */
  335. { .pci_subvendor = PCI_VENDOR_ID_DELL, .pci_subdevice = 0x01cb,
  336. .config = STAC_REF }, /* Dell Latitude 120L */
  337. {} /* terminator */
  338. };
  339. static unsigned int ref922x_pin_configs[10] = {
  340. 0x01014010, 0x01016011, 0x01012012, 0x0221401f,
  341. 0x01813122, 0x01011014, 0x01441030, 0x01c41030,
  342. 0x40000100, 0x40000100,
  343. };
  344. static unsigned int d945gtp3_pin_configs[10] = {
  345. 0x0221401f, 0x01a19022, 0x01813021, 0x01014010,
  346. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  347. 0x02a19120, 0x40000100,
  348. };
  349. static unsigned int d945gtp5_pin_configs[10] = {
  350. 0x0221401f, 0x01011012, 0x01813024, 0x01014010,
  351. 0x01a19021, 0x01016011, 0x01452130, 0x40000100,
  352. 0x02a19320, 0x40000100,
  353. };
  354. static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
  355. [STAC_REF] = ref922x_pin_configs,
  356. [STAC_D945GTP3] = d945gtp3_pin_configs,
  357. [STAC_D945GTP5] = d945gtp5_pin_configs,
  358. [STAC_MACMINI] = d945gtp5_pin_configs,
  359. };
  360. static struct hda_board_config stac922x_cfg_tbl[] = {
  361. { .modelname = "5stack", .config = STAC_D945GTP5 },
  362. { .modelname = "3stack", .config = STAC_D945GTP3 },
  363. { .modelname = "ref",
  364. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  365. .pci_subdevice = 0x2668, /* DFI LanParty */
  366. .config = STAC_REF }, /* SigmaTel reference board */
  367. /* Intel 945G based systems */
  368. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  369. .pci_subdevice = 0x0101,
  370. .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
  371. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  372. .pci_subdevice = 0x0202,
  373. .config = STAC_D945GTP3 }, /* Intel D945GNT - 3 Stack */
  374. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  375. .pci_subdevice = 0x0606,
  376. .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
  377. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  378. .pci_subdevice = 0x0601,
  379. .config = STAC_D945GTP3 }, /* Intel D945GTP - 3 Stack */
  380. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  381. .pci_subdevice = 0x0111,
  382. .config = STAC_D945GTP3 }, /* Intel D945GZP - 3 Stack */
  383. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  384. .pci_subdevice = 0x1115,
  385. .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
  386. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  387. .pci_subdevice = 0x1116,
  388. .config = STAC_D945GTP3 }, /* Intel D945GBO - 3 Stack */
  389. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  390. .pci_subdevice = 0x1117,
  391. .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
  392. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  393. .pci_subdevice = 0x1118,
  394. .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
  395. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  396. .pci_subdevice = 0x1119,
  397. .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
  398. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  399. .pci_subdevice = 0x8826,
  400. .config = STAC_D945GTP3 }, /* Intel D945GPM - 3 Stack */
  401. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  402. .pci_subdevice = 0x5049,
  403. .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
  404. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  405. .pci_subdevice = 0x5055,
  406. .config = STAC_D945GTP3 }, /* Intel D945GCZ - 3 Stack */
  407. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  408. .pci_subdevice = 0x5048,
  409. .config = STAC_D945GTP3 }, /* Intel D945GPB - 3 Stack */
  410. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  411. .pci_subdevice = 0x0110,
  412. .config = STAC_D945GTP3 }, /* Intel D945GLR - 3 Stack */
  413. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  414. .pci_subdevice = 0x0404,
  415. .config = STAC_D945GTP5 }, /* Intel D945GTP - 5 Stack */
  416. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  417. .pci_subdevice = 0x0303,
  418. .config = STAC_D945GTP5 }, /* Intel D945GNT - 5 Stack */
  419. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  420. .pci_subdevice = 0x0013,
  421. .config = STAC_D945GTP5 }, /* Intel D955XBK - 5 Stack */
  422. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  423. .pci_subdevice = 0x0417,
  424. .config = STAC_D945GTP5 }, /* Intel D975XBK - 5 Stack */
  425. /* Intel 945P based systems */
  426. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  427. .pci_subdevice = 0x0b0b,
  428. .config = STAC_D945GTP3 }, /* Intel D945PSN - 3 Stack */
  429. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  430. .pci_subdevice = 0x0112,
  431. .config = STAC_D945GTP3 }, /* Intel D945PLN - 3 Stack */
  432. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  433. .pci_subdevice = 0x0d0d,
  434. .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
  435. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  436. .pci_subdevice = 0x0909,
  437. .config = STAC_D945GTP3 }, /* Intel D945PAW - 3 Stack */
  438. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  439. .pci_subdevice = 0x0505,
  440. .config = STAC_D945GTP3 }, /* Intel D945PLM - 3 Stack */
  441. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  442. .pci_subdevice = 0x0707,
  443. .config = STAC_D945GTP5 }, /* Intel D945PSV - 5 Stack */
  444. /* other systems */
  445. { .pci_subvendor = 0x8384,
  446. .pci_subdevice = 0x7680,
  447. .config = STAC_MACMINI }, /* Apple Mac Mini (early 2006) */
  448. {} /* terminator */
  449. };
  450. static unsigned int ref927x_pin_configs[14] = {
  451. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  452. 0x01a19040, 0x01011012, 0x01016011, 0x0101201f,
  453. 0x183301f0, 0x18a001f0, 0x18a001f0, 0x01442070,
  454. 0x01c42190, 0x40000100,
  455. };
  456. static unsigned int d965_3st_pin_configs[14] = {
  457. 0x0221401f, 0x02a19120, 0x40000100, 0x01014011,
  458. 0x01a19021, 0x01813024, 0x40000100, 0x40000100,
  459. 0x40000100, 0x40000100, 0x40000100, 0x40000100,
  460. 0x40000100, 0x40000100
  461. };
  462. static unsigned int d965_5st_pin_configs[14] = {
  463. 0x02214020, 0x02a19080, 0x0181304e, 0x01014010,
  464. 0x01a19040, 0x01011012, 0x01016011, 0x40000100,
  465. 0x40000100, 0x40000100, 0x40000100, 0x01442070,
  466. 0x40000100, 0x40000100
  467. };
  468. static unsigned int *stac927x_brd_tbl[STAC_927X_MODELS] = {
  469. [STAC_REF] = ref927x_pin_configs,
  470. [STAC_D965_3ST] = d965_3st_pin_configs,
  471. [STAC_D965_5ST] = d965_5st_pin_configs,
  472. };
  473. static struct hda_board_config stac927x_cfg_tbl[] = {
  474. { .modelname = "5stack", .config = STAC_D965_5ST },
  475. { .modelname = "3stack", .config = STAC_D965_3ST },
  476. { .modelname = "ref",
  477. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  478. .pci_subdevice = 0x2668, /* DFI LanParty */
  479. .config = STAC_REF }, /* SigmaTel reference board */
  480. /* Intel 946 based systems */
  481. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  482. .pci_subdevice = 0x3d01,
  483. .config = STAC_D965_3ST }, /* D946 configuration */
  484. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  485. .pci_subdevice = 0xa301,
  486. .config = STAC_D965_3ST }, /* Intel D946GZT - 3 stack */
  487. /* 965 based 3 stack systems */
  488. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  489. .pci_subdevice = 0x2116,
  490. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  491. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  492. .pci_subdevice = 0x2115,
  493. .config = STAC_D965_3ST }, /* Intel DQ965WC - 3 Stack */
  494. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  495. .pci_subdevice = 0x2114,
  496. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  497. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  498. .pci_subdevice = 0x2113,
  499. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  500. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  501. .pci_subdevice = 0x2112,
  502. .config = STAC_D965_3ST }, /* Intel DG965MS - 3 Stack */
  503. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  504. .pci_subdevice = 0x2111,
  505. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  506. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  507. .pci_subdevice = 0x2110,
  508. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  509. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  510. .pci_subdevice = 0x2009,
  511. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  512. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  513. .pci_subdevice = 0x2008,
  514. .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
  515. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  516. .pci_subdevice = 0x2007,
  517. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  518. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  519. .pci_subdevice = 0x2006,
  520. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  521. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  522. .pci_subdevice = 0x2005,
  523. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  524. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  525. .pci_subdevice = 0x2004,
  526. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  527. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  528. .pci_subdevice = 0x2003,
  529. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  530. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  531. .pci_subdevice = 0x2002,
  532. .config = STAC_D965_3ST }, /* Intel D965 3Stack config */
  533. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  534. .pci_subdevice = 0x2001,
  535. .config = STAC_D965_3ST }, /* Intel DQ965GF - 3 Stack */
  536. /* 965 based 5 stack systems */
  537. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  538. .pci_subdevice = 0x2301,
  539. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  540. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  541. .pci_subdevice = 0x2302,
  542. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  543. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  544. .pci_subdevice = 0x2303,
  545. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  546. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  547. .pci_subdevice = 0x2304,
  548. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  549. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  550. .pci_subdevice = 0x2305,
  551. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  552. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  553. .pci_subdevice = 0x2501,
  554. .config = STAC_D965_5ST }, /* Intel DG965MQ - 5 Stack */
  555. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  556. .pci_subdevice = 0x2502,
  557. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  558. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  559. .pci_subdevice = 0x2503,
  560. .config = STAC_D965_5ST }, /* Intel DG965 - 5 Stack */
  561. { .pci_subvendor = PCI_VENDOR_ID_INTEL,
  562. .pci_subdevice = 0x2504,
  563. .config = STAC_D965_5ST }, /* Intel DQ965GF - 5 Stack */
  564. {} /* terminator */
  565. };
  566. static unsigned int ref9205_pin_configs[12] = {
  567. 0x40000100, 0x40000100, 0x01016011, 0x01014010,
  568. 0x01813122, 0x01a19021, 0x40000100, 0x40000100,
  569. 0x90a000f0, 0x90a000f0, 0x01441030, 0x01c41030
  570. };
  571. static unsigned int *stac9205_brd_tbl[] = {
  572. ref9205_pin_configs,
  573. };
  574. static struct hda_board_config stac9205_cfg_tbl[] = {
  575. { .modelname = "ref",
  576. .pci_subvendor = PCI_VENDOR_ID_INTEL,
  577. .pci_subdevice = 0x2668, /* DFI LanParty */
  578. .config = STAC_REF }, /* SigmaTel reference board */
  579. {} /* terminator */
  580. };
  581. static int stac92xx_save_bios_config_regs(struct hda_codec *codec)
  582. {
  583. int i;
  584. struct sigmatel_spec *spec = codec->spec;
  585. if (! spec->bios_pin_configs) {
  586. spec->bios_pin_configs = kcalloc(spec->num_pins,
  587. sizeof(*spec->bios_pin_configs), GFP_KERNEL);
  588. if (! spec->bios_pin_configs)
  589. return -ENOMEM;
  590. }
  591. for (i = 0; i < spec->num_pins; i++) {
  592. hda_nid_t nid = spec->pin_nids[i];
  593. unsigned int pin_cfg;
  594. pin_cfg = snd_hda_codec_read(codec, nid, 0,
  595. AC_VERB_GET_CONFIG_DEFAULT, 0x00);
  596. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x bios pin config %8.8x\n",
  597. nid, pin_cfg);
  598. spec->bios_pin_configs[i] = pin_cfg;
  599. }
  600. return 0;
  601. }
  602. static void stac92xx_set_config_regs(struct hda_codec *codec)
  603. {
  604. int i;
  605. struct sigmatel_spec *spec = codec->spec;
  606. unsigned int pin_cfg;
  607. if (! spec->pin_nids || ! spec->pin_configs)
  608. return;
  609. for (i = 0; i < spec->num_pins; i++) {
  610. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  611. AC_VERB_SET_CONFIG_DEFAULT_BYTES_0,
  612. spec->pin_configs[i] & 0x000000ff);
  613. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  614. AC_VERB_SET_CONFIG_DEFAULT_BYTES_1,
  615. (spec->pin_configs[i] & 0x0000ff00) >> 8);
  616. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  617. AC_VERB_SET_CONFIG_DEFAULT_BYTES_2,
  618. (spec->pin_configs[i] & 0x00ff0000) >> 16);
  619. snd_hda_codec_write(codec, spec->pin_nids[i], 0,
  620. AC_VERB_SET_CONFIG_DEFAULT_BYTES_3,
  621. spec->pin_configs[i] >> 24);
  622. pin_cfg = snd_hda_codec_read(codec, spec->pin_nids[i], 0,
  623. AC_VERB_GET_CONFIG_DEFAULT,
  624. 0x00);
  625. snd_printdd(KERN_INFO "hda_codec: pin nid %2.2x pin config %8.8x\n", spec->pin_nids[i], pin_cfg);
  626. }
  627. }
  628. /*
  629. * Analog playback callbacks
  630. */
  631. static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
  632. struct hda_codec *codec,
  633. struct snd_pcm_substream *substream)
  634. {
  635. struct sigmatel_spec *spec = codec->spec;
  636. return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
  637. }
  638. static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  639. struct hda_codec *codec,
  640. unsigned int stream_tag,
  641. unsigned int format,
  642. struct snd_pcm_substream *substream)
  643. {
  644. struct sigmatel_spec *spec = codec->spec;
  645. return snd_hda_multi_out_analog_prepare(codec, &spec->multiout, stream_tag, format, substream);
  646. }
  647. static int stac92xx_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  648. struct hda_codec *codec,
  649. struct snd_pcm_substream *substream)
  650. {
  651. struct sigmatel_spec *spec = codec->spec;
  652. return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
  653. }
  654. /*
  655. * Digital playback callbacks
  656. */
  657. static int stac92xx_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
  658. struct hda_codec *codec,
  659. struct snd_pcm_substream *substream)
  660. {
  661. struct sigmatel_spec *spec = codec->spec;
  662. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  663. }
  664. static int stac92xx_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
  665. struct hda_codec *codec,
  666. struct snd_pcm_substream *substream)
  667. {
  668. struct sigmatel_spec *spec = codec->spec;
  669. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  670. }
  671. /*
  672. * Analog capture callbacks
  673. */
  674. static int stac92xx_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
  675. struct hda_codec *codec,
  676. unsigned int stream_tag,
  677. unsigned int format,
  678. struct snd_pcm_substream *substream)
  679. {
  680. struct sigmatel_spec *spec = codec->spec;
  681. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number],
  682. stream_tag, 0, format);
  683. return 0;
  684. }
  685. static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
  686. struct hda_codec *codec,
  687. struct snd_pcm_substream *substream)
  688. {
  689. struct sigmatel_spec *spec = codec->spec;
  690. snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0);
  691. return 0;
  692. }
  693. static struct hda_pcm_stream stac92xx_pcm_digital_playback = {
  694. .substreams = 1,
  695. .channels_min = 2,
  696. .channels_max = 2,
  697. /* NID is set in stac92xx_build_pcms */
  698. .ops = {
  699. .open = stac92xx_dig_playback_pcm_open,
  700. .close = stac92xx_dig_playback_pcm_close
  701. },
  702. };
  703. static struct hda_pcm_stream stac92xx_pcm_digital_capture = {
  704. .substreams = 1,
  705. .channels_min = 2,
  706. .channels_max = 2,
  707. /* NID is set in stac92xx_build_pcms */
  708. };
  709. static struct hda_pcm_stream stac92xx_pcm_analog_playback = {
  710. .substreams = 1,
  711. .channels_min = 2,
  712. .channels_max = 8,
  713. .nid = 0x02, /* NID to query formats and rates */
  714. .ops = {
  715. .open = stac92xx_playback_pcm_open,
  716. .prepare = stac92xx_playback_pcm_prepare,
  717. .cleanup = stac92xx_playback_pcm_cleanup
  718. },
  719. };
  720. static struct hda_pcm_stream stac92xx_pcm_analog_alt_playback = {
  721. .substreams = 1,
  722. .channels_min = 2,
  723. .channels_max = 2,
  724. .nid = 0x06, /* NID to query formats and rates */
  725. .ops = {
  726. .open = stac92xx_playback_pcm_open,
  727. .prepare = stac92xx_playback_pcm_prepare,
  728. .cleanup = stac92xx_playback_pcm_cleanup
  729. },
  730. };
  731. static struct hda_pcm_stream stac92xx_pcm_analog_capture = {
  732. .substreams = 2,
  733. .channels_min = 2,
  734. .channels_max = 2,
  735. /* NID is set in stac92xx_build_pcms */
  736. .ops = {
  737. .prepare = stac92xx_capture_pcm_prepare,
  738. .cleanup = stac92xx_capture_pcm_cleanup
  739. },
  740. };
  741. static int stac92xx_build_pcms(struct hda_codec *codec)
  742. {
  743. struct sigmatel_spec *spec = codec->spec;
  744. struct hda_pcm *info = spec->pcm_rec;
  745. codec->num_pcms = 1;
  746. codec->pcm_info = info;
  747. info->name = "STAC92xx Analog";
  748. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_playback;
  749. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_analog_capture;
  750. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
  751. if (spec->alt_switch) {
  752. codec->num_pcms++;
  753. info++;
  754. info->name = "STAC92xx Analog Alt";
  755. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_analog_alt_playback;
  756. }
  757. if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
  758. codec->num_pcms++;
  759. info++;
  760. info->name = "STAC92xx Digital";
  761. if (spec->multiout.dig_out_nid) {
  762. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
  763. info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
  764. }
  765. if (spec->dig_in_nid) {
  766. info->stream[SNDRV_PCM_STREAM_CAPTURE] = stac92xx_pcm_digital_capture;
  767. info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
  768. }
  769. }
  770. return 0;
  771. }
  772. static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
  773. {
  774. unsigned int pincap = snd_hda_param_read(codec, nid,
  775. AC_PAR_PIN_CAP);
  776. pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
  777. if (pincap & AC_PINCAP_VREF_100)
  778. return AC_PINCTL_VREF_100;
  779. if (pincap & AC_PINCAP_VREF_80)
  780. return AC_PINCTL_VREF_80;
  781. if (pincap & AC_PINCAP_VREF_50)
  782. return AC_PINCTL_VREF_50;
  783. if (pincap & AC_PINCAP_VREF_GRD)
  784. return AC_PINCTL_VREF_GRD;
  785. return 0;
  786. }
  787. static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
  788. {
  789. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
  790. }
  791. static int stac92xx_io_switch_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
  792. {
  793. uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  794. uinfo->count = 1;
  795. uinfo->value.integer.min = 0;
  796. uinfo->value.integer.max = 1;
  797. return 0;
  798. }
  799. static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  800. {
  801. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  802. struct sigmatel_spec *spec = codec->spec;
  803. int io_idx = kcontrol-> private_value & 0xff;
  804. ucontrol->value.integer.value[0] = spec->io_switch[io_idx];
  805. return 0;
  806. }
  807. static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
  808. {
  809. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  810. struct sigmatel_spec *spec = codec->spec;
  811. hda_nid_t nid = kcontrol->private_value >> 8;
  812. int io_idx = kcontrol-> private_value & 0xff;
  813. unsigned short val = ucontrol->value.integer.value[0];
  814. spec->io_switch[io_idx] = val;
  815. if (val)
  816. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  817. else {
  818. unsigned int pinctl = AC_PINCTL_IN_EN;
  819. if (io_idx) /* set VREF for mic */
  820. pinctl |= stac92xx_get_vref(codec, nid);
  821. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  822. }
  823. return 1;
  824. }
  825. #define STAC_CODEC_IO_SWITCH(xname, xpval) \
  826. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
  827. .name = xname, \
  828. .index = 0, \
  829. .info = stac92xx_io_switch_info, \
  830. .get = stac92xx_io_switch_get, \
  831. .put = stac92xx_io_switch_put, \
  832. .private_value = xpval, \
  833. }
  834. enum {
  835. STAC_CTL_WIDGET_VOL,
  836. STAC_CTL_WIDGET_MUTE,
  837. STAC_CTL_WIDGET_IO_SWITCH,
  838. };
  839. static struct snd_kcontrol_new stac92xx_control_templates[] = {
  840. HDA_CODEC_VOLUME(NULL, 0, 0, 0),
  841. HDA_CODEC_MUTE(NULL, 0, 0, 0),
  842. STAC_CODEC_IO_SWITCH(NULL, 0),
  843. };
  844. /* add dynamic controls */
  845. static int stac92xx_add_control(struct sigmatel_spec *spec, int type, const char *name, unsigned long val)
  846. {
  847. struct snd_kcontrol_new *knew;
  848. if (spec->num_kctl_used >= spec->num_kctl_alloc) {
  849. int num = spec->num_kctl_alloc + NUM_CONTROL_ALLOC;
  850. knew = kcalloc(num + 1, sizeof(*knew), GFP_KERNEL); /* array + terminator */
  851. if (! knew)
  852. return -ENOMEM;
  853. if (spec->kctl_alloc) {
  854. memcpy(knew, spec->kctl_alloc, sizeof(*knew) * spec->num_kctl_alloc);
  855. kfree(spec->kctl_alloc);
  856. }
  857. spec->kctl_alloc = knew;
  858. spec->num_kctl_alloc = num;
  859. }
  860. knew = &spec->kctl_alloc[spec->num_kctl_used];
  861. *knew = stac92xx_control_templates[type];
  862. knew->name = kstrdup(name, GFP_KERNEL);
  863. if (! knew->name)
  864. return -ENOMEM;
  865. knew->private_value = val;
  866. spec->num_kctl_used++;
  867. return 0;
  868. }
  869. /* flag inputs as additional dynamic lineouts */
  870. static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cfg *cfg)
  871. {
  872. struct sigmatel_spec *spec = codec->spec;
  873. switch (cfg->line_outs) {
  874. case 3:
  875. /* add line-in as side */
  876. if (cfg->input_pins[AUTO_PIN_LINE]) {
  877. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_LINE];
  878. spec->line_switch = 1;
  879. cfg->line_outs++;
  880. }
  881. break;
  882. case 2:
  883. /* add line-in as clfe and mic as side */
  884. if (cfg->input_pins[AUTO_PIN_LINE]) {
  885. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_LINE];
  886. spec->line_switch = 1;
  887. cfg->line_outs++;
  888. }
  889. if (cfg->input_pins[AUTO_PIN_MIC]) {
  890. cfg->line_out_pins[3] = cfg->input_pins[AUTO_PIN_MIC];
  891. spec->mic_switch = 1;
  892. cfg->line_outs++;
  893. }
  894. break;
  895. case 1:
  896. /* add line-in as surr and mic as clfe */
  897. if (cfg->input_pins[AUTO_PIN_LINE]) {
  898. cfg->line_out_pins[1] = cfg->input_pins[AUTO_PIN_LINE];
  899. spec->line_switch = 1;
  900. cfg->line_outs++;
  901. }
  902. if (cfg->input_pins[AUTO_PIN_MIC]) {
  903. cfg->line_out_pins[2] = cfg->input_pins[AUTO_PIN_MIC];
  904. spec->mic_switch = 1;
  905. cfg->line_outs++;
  906. }
  907. break;
  908. }
  909. return 0;
  910. }
  911. /*
  912. * XXX The line_out pin widget connection list may not be set to the
  913. * desired DAC nid. This is the case on 927x where ports A and B can
  914. * be routed to several DACs.
  915. *
  916. * This requires an analysis of the line-out/hp pin configuration
  917. * to provide a best fit for pin/DAC configurations that are routable.
  918. * For now, 927x DAC4 is not supported and 927x DAC1 output to ports
  919. * A and B is not supported.
  920. */
  921. /* fill in the dac_nids table from the parsed pin configuration */
  922. static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
  923. const struct auto_pin_cfg *cfg)
  924. {
  925. struct sigmatel_spec *spec = codec->spec;
  926. hda_nid_t nid;
  927. int i;
  928. /* check the pins hardwired to audio widget */
  929. for (i = 0; i < cfg->line_outs; i++) {
  930. nid = cfg->line_out_pins[i];
  931. spec->multiout.dac_nids[i] = snd_hda_codec_read(codec, nid, 0,
  932. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  933. }
  934. spec->multiout.num_dacs = cfg->line_outs;
  935. return 0;
  936. }
  937. /* create volume control/switch for the given prefx type */
  938. static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_t nid, int chs)
  939. {
  940. char name[32];
  941. int err;
  942. sprintf(name, "%s Playback Volume", pfx);
  943. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_VOL, name,
  944. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  945. if (err < 0)
  946. return err;
  947. sprintf(name, "%s Playback Switch", pfx);
  948. err = stac92xx_add_control(spec, STAC_CTL_WIDGET_MUTE, name,
  949. HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
  950. if (err < 0)
  951. return err;
  952. return 0;
  953. }
  954. /* add playback controls from the parsed DAC table */
  955. static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
  956. const struct auto_pin_cfg *cfg)
  957. {
  958. static const char *chname[4] = {
  959. "Front", "Surround", NULL /*CLFE*/, "Side"
  960. };
  961. hda_nid_t nid;
  962. int i, err;
  963. for (i = 0; i < cfg->line_outs; i++) {
  964. if (!spec->multiout.dac_nids[i])
  965. continue;
  966. nid = spec->multiout.dac_nids[i];
  967. if (i == 2) {
  968. /* Center/LFE */
  969. err = create_controls(spec, "Center", nid, 1);
  970. if (err < 0)
  971. return err;
  972. err = create_controls(spec, "LFE", nid, 2);
  973. if (err < 0)
  974. return err;
  975. } else {
  976. err = create_controls(spec, chname[i], nid, 3);
  977. if (err < 0)
  978. return err;
  979. }
  980. }
  981. if (spec->line_switch)
  982. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
  983. return err;
  984. if (spec->mic_switch)
  985. if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
  986. return err;
  987. return 0;
  988. }
  989. static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
  990. {
  991. int i;
  992. for (i = 0; i < spec->multiout.num_dacs; i++) {
  993. if (spec->multiout.dac_nids[i] == nid)
  994. return 1;
  995. }
  996. if (spec->multiout.hp_nid == nid)
  997. return 1;
  998. return 0;
  999. }
  1000. static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
  1001. {
  1002. if (!spec->multiout.hp_nid)
  1003. spec->multiout.hp_nid = nid;
  1004. else if (spec->multiout.num_dacs > 4) {
  1005. printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
  1006. return 1;
  1007. } else {
  1008. spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
  1009. spec->multiout.num_dacs++;
  1010. }
  1011. return 0;
  1012. }
  1013. /* add playback controls for Speaker and HP outputs */
  1014. static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
  1015. struct auto_pin_cfg *cfg)
  1016. {
  1017. struct sigmatel_spec *spec = codec->spec;
  1018. hda_nid_t nid;
  1019. int i, old_num_dacs, err;
  1020. old_num_dacs = spec->multiout.num_dacs;
  1021. for (i = 0; i < cfg->hp_outs; i++) {
  1022. unsigned int wid_caps = get_wcaps(codec, cfg->hp_pins[i]);
  1023. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1024. spec->hp_detect = 1;
  1025. nid = snd_hda_codec_read(codec, cfg->hp_pins[i], 0,
  1026. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1027. if (check_in_dac_nids(spec, nid))
  1028. nid = 0;
  1029. if (! nid)
  1030. continue;
  1031. add_spec_dacs(spec, nid);
  1032. }
  1033. for (i = 0; i < cfg->speaker_outs; i++) {
  1034. nid = snd_hda_codec_read(codec, cfg->speaker_pins[0], 0,
  1035. AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
  1036. if (check_in_dac_nids(spec, nid))
  1037. nid = 0;
  1038. if (check_in_dac_nids(spec, nid))
  1039. nid = 0;
  1040. if (! nid)
  1041. continue;
  1042. add_spec_dacs(spec, nid);
  1043. }
  1044. for (i = old_num_dacs; i < spec->multiout.num_dacs; i++) {
  1045. static const char *pfxs[] = {
  1046. "Speaker", "External Speaker", "Speaker2",
  1047. };
  1048. err = create_controls(spec, pfxs[i - old_num_dacs],
  1049. spec->multiout.dac_nids[i], 3);
  1050. if (err < 0)
  1051. return err;
  1052. }
  1053. if (spec->multiout.hp_nid) {
  1054. const char *pfx;
  1055. if (old_num_dacs == spec->multiout.num_dacs)
  1056. pfx = "Master";
  1057. else
  1058. pfx = "Headphone";
  1059. err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
  1060. if (err < 0)
  1061. return err;
  1062. }
  1063. return 0;
  1064. }
  1065. /* labels for dmic mux inputs */
  1066. const char *stac92xx_dmic_labels[5] = {
  1067. "Analog Inputs", "Digital Mic 1", "Digital Mic 2",
  1068. "Digital Mic 3", "Digital Mic 4"
  1069. };
  1070. /* create playback/capture controls for input pins on dmic capable codecs */
  1071. static int stac92xx_auto_create_dmic_input_ctls(struct hda_codec *codec,
  1072. const struct auto_pin_cfg *cfg)
  1073. {
  1074. struct sigmatel_spec *spec = codec->spec;
  1075. struct hda_input_mux *dimux = &spec->private_dimux;
  1076. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1077. int i, j;
  1078. dimux->items[dimux->num_items].label = stac92xx_dmic_labels[0];
  1079. dimux->items[dimux->num_items].index = 0;
  1080. dimux->num_items++;
  1081. for (i = 0; i < spec->num_dmics; i++) {
  1082. int index;
  1083. int num_cons;
  1084. unsigned int def_conf;
  1085. def_conf = snd_hda_codec_read(codec,
  1086. spec->dmic_nids[i],
  1087. 0,
  1088. AC_VERB_GET_CONFIG_DEFAULT,
  1089. 0);
  1090. if (get_defcfg_connect(def_conf) == AC_JACK_PORT_NONE)
  1091. continue;
  1092. num_cons = snd_hda_get_connections(codec,
  1093. spec->dmux_nid,
  1094. con_lst,
  1095. HDA_MAX_NUM_INPUTS);
  1096. for (j = 0; j < num_cons; j++)
  1097. if (con_lst[j] == spec->dmic_nids[i]) {
  1098. index = j;
  1099. goto found;
  1100. }
  1101. continue;
  1102. found:
  1103. dimux->items[dimux->num_items].label =
  1104. stac92xx_dmic_labels[dimux->num_items];
  1105. dimux->items[dimux->num_items].index = index;
  1106. dimux->num_items++;
  1107. }
  1108. return 0;
  1109. }
  1110. /* create playback/capture controls for input pins */
  1111. static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
  1112. {
  1113. struct sigmatel_spec *spec = codec->spec;
  1114. struct hda_input_mux *imux = &spec->private_imux;
  1115. hda_nid_t con_lst[HDA_MAX_NUM_INPUTS];
  1116. int i, j, k;
  1117. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1118. int index;
  1119. if (!cfg->input_pins[i])
  1120. continue;
  1121. index = -1;
  1122. for (j = 0; j < spec->num_muxes; j++) {
  1123. int num_cons;
  1124. num_cons = snd_hda_get_connections(codec,
  1125. spec->mux_nids[j],
  1126. con_lst,
  1127. HDA_MAX_NUM_INPUTS);
  1128. for (k = 0; k < num_cons; k++)
  1129. if (con_lst[k] == cfg->input_pins[i]) {
  1130. index = k;
  1131. goto found;
  1132. }
  1133. }
  1134. continue;
  1135. found:
  1136. imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
  1137. imux->items[imux->num_items].index = index;
  1138. imux->num_items++;
  1139. }
  1140. if (imux->num_items == 1) {
  1141. /*
  1142. * Set the current input for the muxes.
  1143. * The STAC9221 has two input muxes with identical source
  1144. * NID lists. Hopefully this won't get confused.
  1145. */
  1146. for (i = 0; i < spec->num_muxes; i++) {
  1147. snd_hda_codec_write(codec, spec->mux_nids[i], 0,
  1148. AC_VERB_SET_CONNECT_SEL,
  1149. imux->items[0].index);
  1150. }
  1151. }
  1152. return 0;
  1153. }
  1154. static void stac92xx_auto_init_multi_out(struct hda_codec *codec)
  1155. {
  1156. struct sigmatel_spec *spec = codec->spec;
  1157. int i;
  1158. for (i = 0; i < spec->autocfg.line_outs; i++) {
  1159. hda_nid_t nid = spec->autocfg.line_out_pins[i];
  1160. stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
  1161. }
  1162. }
  1163. static void stac92xx_auto_init_hp_out(struct hda_codec *codec)
  1164. {
  1165. struct sigmatel_spec *spec = codec->spec;
  1166. int i;
  1167. for (i = 0; i < spec->autocfg.hp_outs; i++) {
  1168. hda_nid_t pin;
  1169. pin = spec->autocfg.hp_pins[i];
  1170. if (pin) /* connect to front */
  1171. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN);
  1172. }
  1173. for (i = 0; i < spec->autocfg.speaker_outs; i++) {
  1174. hda_nid_t pin;
  1175. pin = spec->autocfg.speaker_pins[i];
  1176. if (pin) /* connect to front */
  1177. stac92xx_auto_set_pinctl(codec, pin, AC_PINCTL_OUT_EN);
  1178. }
  1179. }
  1180. static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
  1181. {
  1182. struct sigmatel_spec *spec = codec->spec;
  1183. int err;
  1184. if ((err = snd_hda_parse_pin_def_config(codec,
  1185. &spec->autocfg,
  1186. spec->dmic_nids)) < 0)
  1187. return err;
  1188. if (! spec->autocfg.line_outs)
  1189. return 0; /* can't find valid pin config */
  1190. if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
  1191. return err;
  1192. if (spec->multiout.num_dacs == 0)
  1193. if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
  1194. return err;
  1195. if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
  1196. (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
  1197. (err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1198. return err;
  1199. if (spec->num_dmics > 0)
  1200. if ((err = stac92xx_auto_create_dmic_input_ctls(codec,
  1201. &spec->autocfg)) < 0)
  1202. return err;
  1203. spec->multiout.max_channels = spec->multiout.num_dacs * 2;
  1204. if (spec->multiout.max_channels > 2)
  1205. spec->surr_switch = 1;
  1206. if (spec->autocfg.dig_out_pin)
  1207. spec->multiout.dig_out_nid = dig_out;
  1208. if (spec->autocfg.dig_in_pin)
  1209. spec->dig_in_nid = dig_in;
  1210. if (spec->kctl_alloc)
  1211. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1212. spec->input_mux = &spec->private_imux;
  1213. spec->dinput_mux = &spec->private_dimux;
  1214. return 1;
  1215. }
  1216. /* add playback controls for HP output */
  1217. static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
  1218. struct auto_pin_cfg *cfg)
  1219. {
  1220. struct sigmatel_spec *spec = codec->spec;
  1221. hda_nid_t pin = cfg->hp_pins[0];
  1222. unsigned int wid_caps;
  1223. if (! pin)
  1224. return 0;
  1225. wid_caps = get_wcaps(codec, pin);
  1226. if (wid_caps & AC_WCAP_UNSOL_CAP)
  1227. spec->hp_detect = 1;
  1228. return 0;
  1229. }
  1230. /* add playback controls for LFE output */
  1231. static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
  1232. struct auto_pin_cfg *cfg)
  1233. {
  1234. struct sigmatel_spec *spec = codec->spec;
  1235. int err;
  1236. hda_nid_t lfe_pin = 0x0;
  1237. int i;
  1238. /*
  1239. * search speaker outs and line outs for a mono speaker pin
  1240. * with an amp. If one is found, add LFE controls
  1241. * for it.
  1242. */
  1243. for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
  1244. hda_nid_t pin = spec->autocfg.speaker_pins[i];
  1245. unsigned long wcaps = get_wcaps(codec, pin);
  1246. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1247. if (wcaps == AC_WCAP_OUT_AMP)
  1248. /* found a mono speaker with an amp, must be lfe */
  1249. lfe_pin = pin;
  1250. }
  1251. /* if speaker_outs is 0, then speakers may be in line_outs */
  1252. if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
  1253. for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
  1254. hda_nid_t pin = spec->autocfg.line_out_pins[i];
  1255. unsigned long cfg;
  1256. cfg = snd_hda_codec_read(codec, pin, 0,
  1257. AC_VERB_GET_CONFIG_DEFAULT,
  1258. 0x00);
  1259. if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) {
  1260. unsigned long wcaps = get_wcaps(codec, pin);
  1261. wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
  1262. if (wcaps == AC_WCAP_OUT_AMP)
  1263. /* found a mono speaker with an amp,
  1264. must be lfe */
  1265. lfe_pin = pin;
  1266. }
  1267. }
  1268. }
  1269. if (lfe_pin) {
  1270. err = create_controls(spec, "LFE", lfe_pin, 1);
  1271. if (err < 0)
  1272. return err;
  1273. }
  1274. return 0;
  1275. }
  1276. static int stac9200_parse_auto_config(struct hda_codec *codec)
  1277. {
  1278. struct sigmatel_spec *spec = codec->spec;
  1279. int err;
  1280. if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
  1281. return err;
  1282. if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
  1283. return err;
  1284. if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
  1285. return err;
  1286. if ((err = stac9200_auto_create_lfe_ctls(codec, &spec->autocfg)) < 0)
  1287. return err;
  1288. if (spec->autocfg.dig_out_pin)
  1289. spec->multiout.dig_out_nid = 0x05;
  1290. if (spec->autocfg.dig_in_pin)
  1291. spec->dig_in_nid = 0x04;
  1292. if (spec->kctl_alloc)
  1293. spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
  1294. spec->input_mux = &spec->private_imux;
  1295. spec->dinput_mux = &spec->private_dimux;
  1296. return 1;
  1297. }
  1298. /*
  1299. * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
  1300. * funky external mute control using GPIO pins.
  1301. */
  1302. static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
  1303. {
  1304. unsigned int gpiostate, gpiomask, gpiodir;
  1305. gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
  1306. AC_VERB_GET_GPIO_DATA, 0);
  1307. if (!muted)
  1308. gpiostate |= (1 << pin);
  1309. else
  1310. gpiostate &= ~(1 << pin);
  1311. gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
  1312. AC_VERB_GET_GPIO_MASK, 0);
  1313. gpiomask |= (1 << pin);
  1314. gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
  1315. AC_VERB_GET_GPIO_DIRECTION, 0);
  1316. gpiodir |= (1 << pin);
  1317. /* AppleHDA seems to do this -- WTF is this verb?? */
  1318. snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
  1319. snd_hda_codec_write(codec, codec->afg, 0,
  1320. AC_VERB_SET_GPIO_MASK, gpiomask);
  1321. snd_hda_codec_write(codec, codec->afg, 0,
  1322. AC_VERB_SET_GPIO_DIRECTION, gpiodir);
  1323. msleep(1);
  1324. snd_hda_codec_write(codec, codec->afg, 0,
  1325. AC_VERB_SET_GPIO_DATA, gpiostate);
  1326. }
  1327. static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
  1328. unsigned int event)
  1329. {
  1330. if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP)
  1331. snd_hda_codec_write(codec, nid, 0,
  1332. AC_VERB_SET_UNSOLICITED_ENABLE,
  1333. (AC_USRSP_EN | event));
  1334. }
  1335. static int stac92xx_init(struct hda_codec *codec)
  1336. {
  1337. struct sigmatel_spec *spec = codec->spec;
  1338. struct auto_pin_cfg *cfg = &spec->autocfg;
  1339. int i;
  1340. snd_hda_sequence_write(codec, spec->init);
  1341. /* set up pins */
  1342. if (spec->hp_detect) {
  1343. /* Enable unsolicited responses on the HP widget */
  1344. for (i = 0; i < cfg->hp_outs; i++)
  1345. enable_pin_detect(codec, cfg->hp_pins[i],
  1346. STAC_HP_EVENT);
  1347. stac92xx_auto_init_hp_out(codec);
  1348. /* fake event to set up pins */
  1349. codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
  1350. } else {
  1351. stac92xx_auto_init_multi_out(codec);
  1352. stac92xx_auto_init_hp_out(codec);
  1353. }
  1354. for (i = 0; i < AUTO_PIN_LAST; i++) {
  1355. hda_nid_t nid = cfg->input_pins[i];
  1356. if (nid) {
  1357. unsigned int pinctl = AC_PINCTL_IN_EN;
  1358. if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
  1359. pinctl |= stac92xx_get_vref(codec, nid);
  1360. stac92xx_auto_set_pinctl(codec, nid, pinctl);
  1361. }
  1362. }
  1363. if (spec->num_dmics > 0)
  1364. for (i = 0; i < spec->num_dmics; i++)
  1365. stac92xx_auto_set_pinctl(codec, spec->dmic_nids[i],
  1366. AC_PINCTL_IN_EN);
  1367. if (cfg->dig_out_pin)
  1368. stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
  1369. AC_PINCTL_OUT_EN);
  1370. if (cfg->dig_in_pin)
  1371. stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
  1372. AC_PINCTL_IN_EN);
  1373. if (spec->gpio_mute) {
  1374. stac922x_gpio_mute(codec, 0, 0);
  1375. stac922x_gpio_mute(codec, 1, 0);
  1376. }
  1377. return 0;
  1378. }
  1379. static void stac92xx_free(struct hda_codec *codec)
  1380. {
  1381. struct sigmatel_spec *spec = codec->spec;
  1382. int i;
  1383. if (! spec)
  1384. return;
  1385. if (spec->kctl_alloc) {
  1386. for (i = 0; i < spec->num_kctl_used; i++)
  1387. kfree(spec->kctl_alloc[i].name);
  1388. kfree(spec->kctl_alloc);
  1389. }
  1390. if (spec->bios_pin_configs)
  1391. kfree(spec->bios_pin_configs);
  1392. kfree(spec);
  1393. }
  1394. static void stac92xx_set_pinctl(struct hda_codec *codec, hda_nid_t nid,
  1395. unsigned int flag)
  1396. {
  1397. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  1398. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  1399. if (flag == AC_PINCTL_OUT_EN && (pin_ctl & AC_PINCTL_IN_EN))
  1400. return;
  1401. snd_hda_codec_write(codec, nid, 0,
  1402. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1403. pin_ctl | flag);
  1404. }
  1405. static void stac92xx_reset_pinctl(struct hda_codec *codec, hda_nid_t nid,
  1406. unsigned int flag)
  1407. {
  1408. unsigned int pin_ctl = snd_hda_codec_read(codec, nid,
  1409. 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0x00);
  1410. snd_hda_codec_write(codec, nid, 0,
  1411. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1412. pin_ctl & ~flag);
  1413. }
  1414. static int get_pin_presence(struct hda_codec *codec, hda_nid_t nid)
  1415. {
  1416. if (!nid)
  1417. return 0;
  1418. if (snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_PIN_SENSE, 0x00)
  1419. & (1 << 31))
  1420. return 1;
  1421. return 0;
  1422. }
  1423. static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
  1424. {
  1425. struct sigmatel_spec *spec = codec->spec;
  1426. struct auto_pin_cfg *cfg = &spec->autocfg;
  1427. int i, presence;
  1428. presence = 0;
  1429. for (i = 0; i < cfg->hp_outs; i++) {
  1430. presence = get_pin_presence(codec, cfg->hp_pins[i]);
  1431. if (presence)
  1432. break;
  1433. }
  1434. if (presence) {
  1435. /* disable lineouts, enable hp */
  1436. for (i = 0; i < cfg->line_outs; i++)
  1437. stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
  1438. AC_PINCTL_OUT_EN);
  1439. for (i = 0; i < cfg->speaker_outs; i++)
  1440. stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
  1441. AC_PINCTL_OUT_EN);
  1442. } else {
  1443. /* enable lineouts, disable hp */
  1444. for (i = 0; i < cfg->line_outs; i++)
  1445. stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
  1446. AC_PINCTL_OUT_EN);
  1447. for (i = 0; i < cfg->speaker_outs; i++)
  1448. stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
  1449. AC_PINCTL_OUT_EN);
  1450. }
  1451. }
  1452. static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
  1453. {
  1454. switch (res >> 26) {
  1455. case STAC_HP_EVENT:
  1456. stac92xx_hp_detect(codec, res);
  1457. break;
  1458. }
  1459. }
  1460. #ifdef CONFIG_PM
  1461. static int stac92xx_resume(struct hda_codec *codec)
  1462. {
  1463. struct sigmatel_spec *spec = codec->spec;
  1464. int i;
  1465. stac92xx_init(codec);
  1466. stac92xx_set_config_regs(codec);
  1467. for (i = 0; i < spec->num_mixers; i++)
  1468. snd_hda_resume_ctls(codec, spec->mixers[i]);
  1469. if (spec->multiout.dig_out_nid)
  1470. snd_hda_resume_spdif_out(codec);
  1471. if (spec->dig_in_nid)
  1472. snd_hda_resume_spdif_in(codec);
  1473. return 0;
  1474. }
  1475. #endif
  1476. static struct hda_codec_ops stac92xx_patch_ops = {
  1477. .build_controls = stac92xx_build_controls,
  1478. .build_pcms = stac92xx_build_pcms,
  1479. .init = stac92xx_init,
  1480. .free = stac92xx_free,
  1481. .unsol_event = stac92xx_unsol_event,
  1482. #ifdef CONFIG_PM
  1483. .resume = stac92xx_resume,
  1484. #endif
  1485. };
  1486. static int patch_stac9200(struct hda_codec *codec)
  1487. {
  1488. struct sigmatel_spec *spec;
  1489. int err;
  1490. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1491. if (spec == NULL)
  1492. return -ENOMEM;
  1493. codec->spec = spec;
  1494. spec->num_pins = 8;
  1495. spec->pin_nids = stac9200_pin_nids;
  1496. spec->board_config = snd_hda_check_board_config(codec, stac9200_cfg_tbl);
  1497. if (spec->board_config < 0) {
  1498. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9200, using BIOS defaults\n");
  1499. err = stac92xx_save_bios_config_regs(codec);
  1500. if (err < 0) {
  1501. stac92xx_free(codec);
  1502. return err;
  1503. }
  1504. spec->pin_configs = spec->bios_pin_configs;
  1505. } else {
  1506. spec->pin_configs = stac9200_brd_tbl[spec->board_config];
  1507. stac92xx_set_config_regs(codec);
  1508. }
  1509. spec->multiout.max_channels = 2;
  1510. spec->multiout.num_dacs = 1;
  1511. spec->multiout.dac_nids = stac9200_dac_nids;
  1512. spec->adc_nids = stac9200_adc_nids;
  1513. spec->mux_nids = stac9200_mux_nids;
  1514. spec->num_muxes = 1;
  1515. spec->num_dmics = 0;
  1516. spec->init = stac9200_core_init;
  1517. spec->mixer = stac9200_mixer;
  1518. err = stac9200_parse_auto_config(codec);
  1519. if (err < 0) {
  1520. stac92xx_free(codec);
  1521. return err;
  1522. }
  1523. codec->patch_ops = stac92xx_patch_ops;
  1524. return 0;
  1525. }
  1526. static int patch_stac922x(struct hda_codec *codec)
  1527. {
  1528. struct sigmatel_spec *spec;
  1529. int err;
  1530. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1531. if (spec == NULL)
  1532. return -ENOMEM;
  1533. codec->spec = spec;
  1534. spec->num_pins = 10;
  1535. spec->pin_nids = stac922x_pin_nids;
  1536. spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
  1537. if (spec->board_config < 0) {
  1538. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
  1539. "using BIOS defaults\n");
  1540. err = stac92xx_save_bios_config_regs(codec);
  1541. if (err < 0) {
  1542. stac92xx_free(codec);
  1543. return err;
  1544. }
  1545. spec->pin_configs = spec->bios_pin_configs;
  1546. } else if (stac922x_brd_tbl[spec->board_config] != NULL) {
  1547. spec->pin_configs = stac922x_brd_tbl[spec->board_config];
  1548. stac92xx_set_config_regs(codec);
  1549. }
  1550. spec->adc_nids = stac922x_adc_nids;
  1551. spec->mux_nids = stac922x_mux_nids;
  1552. spec->num_muxes = 2;
  1553. spec->num_dmics = 0;
  1554. spec->init = stac922x_core_init;
  1555. spec->mixer = stac922x_mixer;
  1556. spec->multiout.dac_nids = spec->dac_nids;
  1557. err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
  1558. if (err < 0) {
  1559. stac92xx_free(codec);
  1560. return err;
  1561. }
  1562. if (spec->board_config == STAC_MACMINI)
  1563. spec->gpio_mute = 1;
  1564. codec->patch_ops = stac92xx_patch_ops;
  1565. return 0;
  1566. }
  1567. static int patch_stac927x(struct hda_codec *codec)
  1568. {
  1569. struct sigmatel_spec *spec;
  1570. int err;
  1571. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1572. if (spec == NULL)
  1573. return -ENOMEM;
  1574. codec->spec = spec;
  1575. spec->num_pins = 14;
  1576. spec->pin_nids = stac927x_pin_nids;
  1577. spec->board_config = snd_hda_check_board_config(codec, stac927x_cfg_tbl);
  1578. if (spec->board_config < 0) {
  1579. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC927x, using BIOS defaults\n");
  1580. err = stac92xx_save_bios_config_regs(codec);
  1581. if (err < 0) {
  1582. stac92xx_free(codec);
  1583. return err;
  1584. }
  1585. spec->pin_configs = spec->bios_pin_configs;
  1586. } else if (stac927x_brd_tbl[spec->board_config] != NULL) {
  1587. spec->pin_configs = stac927x_brd_tbl[spec->board_config];
  1588. stac92xx_set_config_regs(codec);
  1589. }
  1590. switch (spec->board_config) {
  1591. case STAC_D965_3ST:
  1592. spec->adc_nids = stac927x_adc_nids;
  1593. spec->mux_nids = stac927x_mux_nids;
  1594. spec->num_muxes = 3;
  1595. spec->num_dmics = 0;
  1596. spec->init = d965_core_init;
  1597. spec->mixer = stac9227_mixer;
  1598. break;
  1599. case STAC_D965_5ST:
  1600. spec->adc_nids = stac927x_adc_nids;
  1601. spec->mux_nids = stac927x_mux_nids;
  1602. spec->num_muxes = 3;
  1603. spec->num_dmics = 0;
  1604. spec->init = d965_core_init;
  1605. spec->mixer = stac9227_mixer;
  1606. break;
  1607. default:
  1608. spec->adc_nids = stac927x_adc_nids;
  1609. spec->mux_nids = stac927x_mux_nids;
  1610. spec->num_muxes = 3;
  1611. spec->num_dmics = 0;
  1612. spec->init = stac927x_core_init;
  1613. spec->mixer = stac927x_mixer;
  1614. }
  1615. spec->multiout.dac_nids = spec->dac_nids;
  1616. err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
  1617. if (err < 0) {
  1618. stac92xx_free(codec);
  1619. return err;
  1620. }
  1621. codec->patch_ops = stac92xx_patch_ops;
  1622. return 0;
  1623. }
  1624. static int patch_stac9205(struct hda_codec *codec)
  1625. {
  1626. struct sigmatel_spec *spec;
  1627. int err;
  1628. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1629. if (spec == NULL)
  1630. return -ENOMEM;
  1631. codec->spec = spec;
  1632. spec->num_pins = 14;
  1633. spec->pin_nids = stac9205_pin_nids;
  1634. spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
  1635. if (spec->board_config < 0) {
  1636. snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
  1637. err = stac92xx_save_bios_config_regs(codec);
  1638. if (err < 0) {
  1639. stac92xx_free(codec);
  1640. return err;
  1641. }
  1642. spec->pin_configs = spec->bios_pin_configs;
  1643. } else {
  1644. spec->pin_configs = stac9205_brd_tbl[spec->board_config];
  1645. stac92xx_set_config_regs(codec);
  1646. }
  1647. spec->adc_nids = stac9205_adc_nids;
  1648. spec->mux_nids = stac9205_mux_nids;
  1649. spec->num_muxes = 2;
  1650. spec->dmic_nids = stac9205_dmic_nids;
  1651. spec->num_dmics = 2;
  1652. spec->dmux_nid = 0x1d;
  1653. spec->init = stac9205_core_init;
  1654. spec->mixer = stac9205_mixer;
  1655. spec->multiout.dac_nids = spec->dac_nids;
  1656. err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
  1657. if (err < 0) {
  1658. stac92xx_free(codec);
  1659. return err;
  1660. }
  1661. codec->patch_ops = stac92xx_patch_ops;
  1662. return 0;
  1663. }
  1664. /*
  1665. * STAC9872 hack
  1666. */
  1667. /* static config for Sony VAIO FE550G and Sony VAIO AR */
  1668. static hda_nid_t vaio_dacs[] = { 0x2 };
  1669. #define VAIO_HP_DAC 0x5
  1670. static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
  1671. static hda_nid_t vaio_mux_nids[] = { 0x15 };
  1672. static struct hda_input_mux vaio_mux = {
  1673. .num_items = 2,
  1674. .items = {
  1675. /* { "HP", 0x0 }, */
  1676. { "Line", 0x1 },
  1677. { "Mic", 0x2 },
  1678. { "PCM", 0x3 },
  1679. }
  1680. };
  1681. static struct hda_verb vaio_init[] = {
  1682. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  1683. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  1684. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  1685. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  1686. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  1687. {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
  1688. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  1689. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  1690. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  1691. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  1692. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  1693. {}
  1694. };
  1695. static struct hda_verb vaio_ar_init[] = {
  1696. {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
  1697. {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
  1698. {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
  1699. {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
  1700. /* {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },*/ /* Optical Out */
  1701. {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
  1702. {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
  1703. {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
  1704. {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
  1705. /* {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},*/ /* Optical Out */
  1706. {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
  1707. {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
  1708. {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
  1709. {}
  1710. };
  1711. /* bind volumes of both NID 0x02 and 0x05 */
  1712. static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
  1713. struct snd_ctl_elem_value *ucontrol)
  1714. {
  1715. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1716. long *valp = ucontrol->value.integer.value;
  1717. int change;
  1718. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  1719. 0x7f, valp[0] & 0x7f);
  1720. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  1721. 0x7f, valp[1] & 0x7f);
  1722. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1723. 0x7f, valp[0] & 0x7f);
  1724. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1725. 0x7f, valp[1] & 0x7f);
  1726. return change;
  1727. }
  1728. /* bind volumes of both NID 0x02 and 0x05 */
  1729. static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
  1730. struct snd_ctl_elem_value *ucontrol)
  1731. {
  1732. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  1733. long *valp = ucontrol->value.integer.value;
  1734. int change;
  1735. change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
  1736. 0x80, (valp[0] ? 0 : 0x80));
  1737. change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
  1738. 0x80, (valp[1] ? 0 : 0x80));
  1739. snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
  1740. 0x80, (valp[0] ? 0 : 0x80));
  1741. snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
  1742. 0x80, (valp[1] ? 0 : 0x80));
  1743. return change;
  1744. }
  1745. static struct snd_kcontrol_new vaio_mixer[] = {
  1746. {
  1747. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1748. .name = "Master Playback Volume",
  1749. .info = snd_hda_mixer_amp_volume_info,
  1750. .get = snd_hda_mixer_amp_volume_get,
  1751. .put = vaio_master_vol_put,
  1752. .tlv = { .c = snd_hda_mixer_amp_tlv },
  1753. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1754. },
  1755. {
  1756. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1757. .name = "Master Playback Switch",
  1758. .info = snd_hda_mixer_amp_switch_info,
  1759. .get = snd_hda_mixer_amp_switch_get,
  1760. .put = vaio_master_sw_put,
  1761. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1762. },
  1763. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  1764. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  1765. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  1766. {
  1767. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1768. .name = "Capture Source",
  1769. .count = 1,
  1770. .info = stac92xx_mux_enum_info,
  1771. .get = stac92xx_mux_enum_get,
  1772. .put = stac92xx_mux_enum_put,
  1773. },
  1774. {}
  1775. };
  1776. static struct snd_kcontrol_new vaio_ar_mixer[] = {
  1777. {
  1778. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1779. .name = "Master Playback Volume",
  1780. .info = snd_hda_mixer_amp_volume_info,
  1781. .get = snd_hda_mixer_amp_volume_get,
  1782. .put = vaio_master_vol_put,
  1783. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1784. },
  1785. {
  1786. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1787. .name = "Master Playback Switch",
  1788. .info = snd_hda_mixer_amp_switch_info,
  1789. .get = snd_hda_mixer_amp_switch_get,
  1790. .put = vaio_master_sw_put,
  1791. .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
  1792. },
  1793. /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
  1794. HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
  1795. HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
  1796. /*HDA_CODEC_MUTE("Optical Out Switch", 0x10, 0, HDA_OUTPUT),
  1797. HDA_CODEC_VOLUME("Optical Out Volume", 0x10, 0, HDA_OUTPUT),*/
  1798. {
  1799. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  1800. .name = "Capture Source",
  1801. .count = 1,
  1802. .info = stac92xx_mux_enum_info,
  1803. .get = stac92xx_mux_enum_get,
  1804. .put = stac92xx_mux_enum_put,
  1805. },
  1806. {}
  1807. };
  1808. static struct hda_codec_ops stac9872_patch_ops = {
  1809. .build_controls = stac92xx_build_controls,
  1810. .build_pcms = stac92xx_build_pcms,
  1811. .init = stac92xx_init,
  1812. .free = stac92xx_free,
  1813. #ifdef CONFIG_PM
  1814. .resume = stac92xx_resume,
  1815. #endif
  1816. };
  1817. enum { /* FE and SZ series. id=0x83847661 and subsys=0x104D0700 or 104D1000. */
  1818. CXD9872RD_VAIO,
  1819. /* Unknown. id=0x83847662 and subsys=0x104D1200 or 104D1000. */
  1820. STAC9872AK_VAIO,
  1821. /* Unknown. id=0x83847661 and subsys=0x104D1200. */
  1822. STAC9872K_VAIO,
  1823. /* AR Series. id=0x83847664 and subsys=104D1300 */
  1824. CXD9872AKD_VAIO
  1825. };
  1826. static struct hda_board_config stac9872_cfg_tbl[] = {
  1827. { .modelname = "vaio", .config = CXD9872RD_VAIO },
  1828. { .modelname = "vaio-ar", .config = CXD9872AKD_VAIO },
  1829. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
  1830. .config = CXD9872RD_VAIO },
  1831. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
  1832. .config = CXD9872RD_VAIO },
  1833. { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
  1834. .config = CXD9872AKD_VAIO },
  1835. {}
  1836. };
  1837. static int patch_stac9872(struct hda_codec *codec)
  1838. {
  1839. struct sigmatel_spec *spec;
  1840. int board_config;
  1841. board_config = snd_hda_check_board_config(codec, stac9872_cfg_tbl);
  1842. if (board_config < 0)
  1843. /* unknown config, let generic-parser do its job... */
  1844. return snd_hda_parse_generic_codec(codec);
  1845. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1846. if (spec == NULL)
  1847. return -ENOMEM;
  1848. codec->spec = spec;
  1849. switch (board_config) {
  1850. case CXD9872RD_VAIO:
  1851. case STAC9872AK_VAIO:
  1852. case STAC9872K_VAIO:
  1853. spec->mixer = vaio_mixer;
  1854. spec->init = vaio_init;
  1855. spec->multiout.max_channels = 2;
  1856. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  1857. spec->multiout.dac_nids = vaio_dacs;
  1858. spec->multiout.hp_nid = VAIO_HP_DAC;
  1859. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  1860. spec->adc_nids = vaio_adcs;
  1861. spec->input_mux = &vaio_mux;
  1862. spec->mux_nids = vaio_mux_nids;
  1863. break;
  1864. case CXD9872AKD_VAIO:
  1865. spec->mixer = vaio_ar_mixer;
  1866. spec->init = vaio_ar_init;
  1867. spec->multiout.max_channels = 2;
  1868. spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
  1869. spec->multiout.dac_nids = vaio_dacs;
  1870. spec->multiout.hp_nid = VAIO_HP_DAC;
  1871. spec->num_adcs = ARRAY_SIZE(vaio_adcs);
  1872. spec->adc_nids = vaio_adcs;
  1873. spec->input_mux = &vaio_mux;
  1874. spec->mux_nids = vaio_mux_nids;
  1875. break;
  1876. }
  1877. codec->patch_ops = stac9872_patch_ops;
  1878. return 0;
  1879. }
  1880. /*
  1881. * patch entries
  1882. */
  1883. struct hda_codec_preset snd_hda_preset_sigmatel[] = {
  1884. { .id = 0x83847690, .name = "STAC9200", .patch = patch_stac9200 },
  1885. { .id = 0x83847882, .name = "STAC9220 A1", .patch = patch_stac922x },
  1886. { .id = 0x83847680, .name = "STAC9221 A1", .patch = patch_stac922x },
  1887. { .id = 0x83847880, .name = "STAC9220 A2", .patch = patch_stac922x },
  1888. { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
  1889. { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
  1890. { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
  1891. { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
  1892. { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
  1893. { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
  1894. { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
  1895. { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
  1896. { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
  1897. { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
  1898. { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
  1899. { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
  1900. { .id = 0x83847623, .name = "STAC9273D", .patch = patch_stac927x },
  1901. { .id = 0x83847624, .name = "STAC9272X", .patch = patch_stac927x },
  1902. { .id = 0x83847625, .name = "STAC9272D", .patch = patch_stac927x },
  1903. { .id = 0x83847626, .name = "STAC9271X", .patch = patch_stac927x },
  1904. { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
  1905. { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
  1906. { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
  1907. /* The following does not take into account .id=0x83847661 when subsys =
  1908. * 104D0C00 which is STAC9225s. Because of this, some SZ Notebooks are
  1909. * currently not fully supported.
  1910. */
  1911. { .id = 0x83847661, .name = "CXD9872RD/K", .patch = patch_stac9872 },
  1912. { .id = 0x83847662, .name = "STAC9872AK", .patch = patch_stac9872 },
  1913. { .id = 0x83847664, .name = "CXD9872AKD", .patch = patch_stac9872 },
  1914. { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
  1915. { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
  1916. { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
  1917. { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
  1918. { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
  1919. { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
  1920. { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
  1921. { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
  1922. {} /* terminator */
  1923. };