patch_sigmatel.c 70 KB

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