patch_sigmatel.c 96 KB

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