patch_sigmatel.c 75 KB

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