patch_sigmatel.c 75 KB

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