patch_sigmatel.c 74 KB

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