patch_sigmatel.c 65 KB

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