patch_sigmatel.c 88 KB

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