patch_sigmatel.c 75 KB

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