patch_sigmatel.c 67 KB

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