patch_sigmatel.c 74 KB

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