patch_sigmatel.c 57 KB

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